Skip to content

Commit

Permalink
Support embedded full/light node clients. (#91)
Browse files Browse the repository at this point in the history
* Add support for light clients.

* Add wasm toolchain to ci.

* Fix ci tests.

* Address review comments.

* Use expect instead of unwrap.

* Purge light client chain too.

* Add README section.
  • Loading branch information
dvc94ch authored Jun 15, 2020
1 parent 91203b9 commit 21d07c6
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 58 deletions.
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" }
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"

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

0 comments on commit 21d07c6

Please sign in to comment.