Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support embedded full/light node clients. #91

Merged
merged 7 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:

- name: setup
run: |
rustup install nightly --profile default
rustup install nightly --profile default
rustup +nightly target add wasm32-unknown-unknown

- name: fmt
run: cargo +nightly fmt --all -- --check

- name: build
run: cargo build --verbose
run: cargo build --workspace --verbose

- name: test
run: cargo test --verbose
run: cargo test --workspace --verbose
59 changes: 35 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "proc-macro"]
members = [".", "client", "proc-macro"]

[package]
name = "substrate-subxt"
Expand All @@ -16,33 +16,44 @@ description = "Submit extrinsics (transactions) to a substrate node via RPC"
keywords = ["parity", "substrate", "blockchain"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[features]
client = ["substrate-subxt-client"]

[dependencies]
log = "0.4"
thiserror = "1.0"
log = "0.4.8"
thiserror = "1.0.19"
futures = "0.3.5"
jsonrpsee = { version = "0.1", features = ["ws"] }
num-traits = { version = "0.2", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
url = "2.1"
jsonrpsee = { version = "0.1.0", features = ["ws"] }
num-traits = { version = "0.2.11", default-features = false }
serde = { version = "1.0.111", features = ["derive"] }
serde_json = "1.0.53"
url = "2.1.1"
codec = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] }

frame-metadata = { version = "11.0.0-rc2", package = "frame-metadata" }
frame-support = { version = "2.0.0-rc2", package = "frame-support" }
sp-runtime = { version = "2.0.0-rc2", package = "sp-runtime" }
sp-version = { version = "2.0.0-rc2", package = "sp-version" }
pallet-indices = { version = "2.0.0-rc2", package = "pallet-indices" }
hex = "0.4.0"
sp-rpc = { version = "2.0.0-rc2", package = "sp-rpc" }
sp-core = { version = "2.0.0-rc2", package = "sp-core" }
sc-rpc-api = { version = "0.8.0-rc2", package = "sc-rpc-api" }
sp-transaction-pool = { version = "2.0.0-rc2", package = "sp-transaction-pool" }
frame-metadata = { version = "11.0.0-rc3", package = "frame-metadata" }
frame-support = { version = "2.0.0-rc3", package = "frame-support" }
sp-runtime = { version = "2.0.0-rc3", package = "sp-runtime" }
sp-version = { version = "2.0.0-rc3", package = "sp-version" }
pallet-indices = { version = "2.0.0-rc3", package = "pallet-indices" }
hex = "0.4.2"
sp-rpc = { version = "2.0.0-rc3", package = "sp-rpc" }
sp-core = { version = "2.0.0-rc3", package = "sp-core" }
sc-rpc-api = { version = "0.8.0-rc3", package = "sc-rpc-api" }
sp-transaction-pool = { version = "2.0.0-rc3", package = "sp-transaction-pool" }
substrate-subxt-client = { path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.8.0", path = "proc-macro" }

[dev-dependencies]
async-std = { version = "1.5.0", features = ["attributes"] }
env_logger = "0.7"
wabt = "0.9"
frame-system = { version = "2.0.0-rc2", package = "frame-system" }
pallet-balances = { version = "2.0.0-rc2", package = "pallet-balances" }
sp-keyring = { version = "2.0.0-rc2", package = "sp-keyring" }
async-std = { version = "=1.5.0", features = ["attributes"] }
env_logger = "0.7.1"
wabt = "0.9.2"
frame-system = { version = "2.0.0-rc3", package = "frame-system" }
node-template = { git = "https://github.com/paritytech/substrate" }
pallet-balances = { version = "2.0.0-rc3", package = "pallet-balances" }
sp-keyring = { version = "2.0.0-rc3", package = "sp-keyring" }
substrate-subxt-client = { path = "client" }
tempdir = "0.3.7"

[patch.crates-io]
sc-network = { git = "https://github.com/paritytech/substrate" }
sc-service = { git = "https://github.com/paritytech/substrate" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these patches for? Something not yet included in rc3? It might prevent publishing the main crate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that node template isn't published, but it's required for the tests. So this makes sure that when it's checked out locally it uses the same versions as the template. I was hoping this trick would allow publish to crates.io

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ See [examples](./examples).

[substrate-api-client](https://github.com/scs/substrate-api-client) provides similar functionality.

## Subxt Client
By default the client builder will connect to a full node via rpc. The `subxt-client` helps
embedding a light client directly. It can also be used to embed a full node. This is especially
useful for testing and ci.

#### License

<sup>
Expand Down
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev-chain.json
30 changes: 30 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "substrate-subxt-client"
version = "0.1.0"
authors = ["David Craven <david@craven.ch>", "Parity Technologies <admin@parity.io>"]
edition = "2018"
dvc94ch marked this conversation as resolved.
Show resolved Hide resolved

license = "GPL-3.0"
repository = "https://github.com/paritytech/substrate-subxt"
documentation = "https://docs.rs/substrate-subxt-client"
homepage = "https://www.parity.io/"
description = "Embed a substrate node into your subxt application."
keywords = ["parity", "substrate", "blockchain"]

[dependencies]
async-std = "=1.5.0"
futures = { version = "0.3.5", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee = "0.1.0"
log = "0.4.8"
sc-network = { version = "0.8.0-rc3", default-features = false }
sc-service = { version = "0.8.0-rc3", default-features = false }
serde_json = "1.0.53"
sp-keyring = "2.0.0-rc3"
thiserror = "1.0.19"

[dev-dependencies]
async-std = { version = "=1.5.0", features = ["attributes"] }
env_logger = "0.7.1"
node-template = { git = "https://github.com/paritytech/substrate" }
substrate-subxt = { path = ".." }
5 changes: 5 additions & 0 deletions client/gen-chain-spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
NODE_TEMPLATE=../../substrate/target/release/node-template
$NODE_TEMPLATE purge-chain --dev
$NODE_TEMPLATE build-spec --dev > dev-chain.json
rm -rf /tmp/subxt-light-client
4 changes: 4 additions & 0 deletions client/purge-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
NODE_TEMPLATE=../../substrate/target/release/node-template
$NODE_TEMPLATE purge-chain --chain=dev-chain.json
rm -rf /tmp/subxt-light-client
3 changes: 3 additions & 0 deletions client/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
NODE_TEMPLATE=../../substrate/target/release/node-template
$NODE_TEMPLATE --chain=dev-chain.json --alice
Loading