Skip to content

Commit

Permalink
Clean up dependencies and fix primitives no_std build (#535)
Browse files Browse the repository at this point in the history
* fix readme

* udpate .toml

* add reamdes and update tomls

* remove unused deps

* fix spacing indent

* move frame-metadata to crates.io

* fix positioning

* remove unused substrate deps

* fix primitvies

* taplo fmt

* update expected error

* remove error check
  • Loading branch information
haerdib committed Apr 17, 2023
1 parent 6d09a9d commit d2e25a5
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ jobs:
cargo build --release -p test-no-std --features api-client,
cargo build --release -p test-no-std --features compose-macros,
cargo build --release -p test-no-std --features node-api,
cargo build --release -p test-no-std --features primitives,

# Test for 32 bit and wasm32-unknown-unknown compatibility
cargo build --target wasm32-unknown-unknown --no-default-features,

# Clippy
cargo clippy --workspace --exclude test-no-std -- -D warnings,
cargo clippy --all-features --examples -- -D warnings,
Expand Down
29 changes: 8 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ version = "0.11.0"
authors = ["Supercomputing Systems AG <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
repository = "https://github.com/scs/substrate-api-client"
description = "Json-rpc client with helper functions compatible with any Substrate node"
readme = "README.md"
keywords = ["json", "rpc"]
categories = ["no-std", "wasm"]


[workspace]
Expand All @@ -21,6 +26,7 @@ members = [
# crates.io no_std
codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ['derive'] }
derive_more = { version = "0.99.5" }
frame-metadata = { version = "15.1", default-features = false, features = ["v14", "serde_full", "decode"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
Expand All @@ -36,7 +42,6 @@ tungstenite = { version = "0.18.0", optional = true, features = ["native-tls"] }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }

# Substrate no_std dependencies
frame-metadata = { default-features = false, git = "https://github.com/paritytech/frame-metadata", features = ["v14", "serde_full", "decode"] }
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand All @@ -63,14 +68,14 @@ disable_target_static_assertions = [
std = [
# crates.io no_std
"codec/std",
"frame-metadata/std",
"hex/std",
"log/std",
"serde/std",
"serde_json/std",
# crates.io std only
"url",
# substrate no_std
"frame-metadata/std",
"sp-core/std",
"sp-runtime/std",
"sp-runtime-interface/std",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src=./web3_foundation_grants_badge_black.svg width = 400>
</p>

substrate-api-client a library written in Rust for connecting to the substrate's RPC interface via WebSockets allowing to
substrate-api-client is a library written in Rust for connecting to the substrate's RPC interface via WebSockets allowing to

* Compose extrinsics, send them and subscribe to updates (synchronously).
* supports `no_std` builds. Only the rpc-client is std only. For `no_std` builds, a custom rpc client needs to be implemented.
Expand Down Expand Up @@ -53,7 +53,7 @@ Set the output verbosity by prepending `RUST_LOG=info` or `RUST_LOG=debug`.

The following examples can be found in the [examples](/examples/examples) folder:

* [benchmark_bulk_xt](/examples/examples/benchmark_bulk_xt.rs): Float the node with a series of transactions.
* [benchmark_bulk_xt](/examples/examples/benchmark_bulk_xt.rs): Float the node with a series of transactions.
* [compose_extrinsic_offline](/examples/examples/compose_extrinsic_offline.rs): Compose an extrinsic without interacting with the node.
* [custom_nonce](/examples/examples/custom_nonce.rs): Compose an with a custom nonce.
* [contract_instantiate_with_code](/examples/examples/contract_instantiate_with_code.rs): Instantiate a contract on the chain.
Expand Down
22 changes: 9 additions & 13 deletions compose-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@ version = "0.3.0"
authors = ["Supercomputing Systems AG <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
repository = "https://github.com/scs/substrate-api-client"
description = "Macros for creating Substrate extrsinics and rpc calls"
readme = "README.md"
categories = ["no-std"]


[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ['derive'] }
log = { version = "0.4.14", default-features = false }

# substrate
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

# need to add this for the app_crypto macro
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate.git", features = ["full_crypto"], branch = "master" }

# local
ac-primitives = { path = "../primitives", default-features = false }

[features]
default = ["std"]
# To support `no_std` builds in non-32 bit environments.
disable_target_static_assertions = [
"ac-primitives/disable_target_static_assertions",
]
std = [
"codec/std",
"log/std",
# substrate
"sp-core/std",
"sp-runtime/std",
"sp-application-crypto/std",
# local
"ac-primitives/std",
]
3 changes: 3 additions & 0 deletions compose-macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ac_primitives

This crate is a submodule of the [substrate-api-client](https://github.com/scs/substrate-api-client). It contains macro definition for creating Substrate extrinsic and rpc calls for the api-client.
3 changes: 0 additions & 3 deletions compose-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

// re-export for macro resolution
pub use ac_primitives as primitives;
pub use codec;
pub use log;
pub use sp_core;
pub use sp_runtime;

mod rpc;

Expand Down
3 changes: 1 addition & 2 deletions examples/examples/event_error_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ async fn main() {
let string_error = format!("{:?}", e);
// We expect a TokenError::FundsUnavailable error. See :
//https://github.com/paritytech/substrate/blob/b42a687c9050cbe04849c45b0c5ccadb82c84948/frame/support/src/traits/tokens/fungible/mod.rs#L177
assert!(string_error.contains("Other"));
assert!(string_error.contains("[7, 0, 194, 110, 3, 65, 37, 56, 0, 0]")); //Fixme This is for now not decoded. See issue: #488
assert!(string_error.contains("Other")); //Fixme This is for now not decoded. See issue: #488
},
};

Expand Down
10 changes: 7 additions & 3 deletions node-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
[package]
name = "ac-node-api"
version = "0.3.0"
authors = ["Supercomputing Systems AG <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
repository = "https://github.com/scs/substrate-api-client"
description = "Substrate node type definitions and helpers for the substrate-api-client"
readme = "README.md"
categories = ["no-std"]

[dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "3.2.1", features = ["derive", "bit-vec"], default-features = false }
derive_more = { version = "0.99.17" }
either = { version = "1.6.1", default-features = false }
frame-metadata = { version = "15.1", default-features = false, features = ["v14", "serde_full", "decode"] }
hex = { version = "0.4.3", default-features = false }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.0.1", features = ["derive", "decode", "bitvec"], default-features = false }
serde = { version = "1.0.136", features = ["derive"], default-features = false }
serde_json = { version = "1.0.79", default-features = false, features = ["alloc"] }

# substrate
frame-metadata = { default-features = false, git = "https://github.com/paritytech/frame-metadata", features = ["v14", "serde_full", "decode"] }
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

Expand All @@ -27,7 +32,6 @@ sp-runtime-interface = { default-features = false, git = "https://github.com/par
# local
ac-primitives = { path = "../primitives", default-features = false }


[features]
default = ["std"]
# To support `no_std` builds in non-32 bit environments.
Expand All @@ -38,13 +42,13 @@ std = [
"bitvec/std",
"codec/std",
"either/default",
"frame-metadata/std",
"hex/std",
"log/std",
"scale-info/std",
"serde/std",
"serde_json/std",
# substrate
"frame-metadata/std",
"sp-core/std",
"sp-runtime/std",
# no_std support
Expand Down
7 changes: 7 additions & 0 deletions node-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ac_node_api

This crate is a submodule of the [substrate-api-client](https://github.com/scs/substrate-api-client). It contains Substrate node specific types and helpers such as:
- Strorage keys (key hash, double map, ..)
- Metadata
- Runtime Events
- Runtime Errors
18 changes: 15 additions & 3 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ version = "0.6.0"
authors = ["Supercomputing Systems AG <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
repository = "https://github.com/scs/substrate-api-client"
description = "Substrate-api-client primitive types"
readme = "README.md"
categories = ["no-std"]


[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ['derive'] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
impl-serde = { version = "0.4", default-features = false }
primitive-types = { version = "0.12.1", default-features = false, features = ["serde_no_std", "scale-info"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# substrate no_std
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
# need to add this for the app_crypto macro
sp-application-crypto = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }

# substrate std / wasm only
frame-system = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand All @@ -34,9 +41,12 @@ sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "ma

[features]
default = ["std"]
# To support `no_std` builds in non-32 bit environments.
disable_target_static_assertions = [
"sp-runtime-interface/disable_target_static_assertions",
]
std = [
"codec/std",
"hex/std",
"primitive-types/std",
"scale-info/std",
"serde/std",
Expand All @@ -46,6 +56,8 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"sp-version/std",
# app_crypto macro
"sp-application-crypto/std",
# substrate std
"frame-system",
"pallet-assets",
Expand Down
3 changes: 3 additions & 0 deletions primitives/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ac_primitives

This crate is a submodule of the [substrate-api-client](https://github.com/scs/substrate-api-client). It contains primitives types and helpers used by the api-client and its submodules.
4 changes: 3 additions & 1 deletion test-no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ edition = "2021"
libc = { version = "0.2.119", default-features = false }

# local dependencies
ac-compose-macros = { path = "../compose-macros", default-features = false, optional = true }
ac-compose-macros = { path = "../compose-macros", default-features = false, optional = true, features = ["disable_target_static_assertions"] }
ac-node-api = { path = "../node-api", default-features = false, optional = true, features = ["disable_target_static_assertions"] }
ac-primitives = { path = "../primitives", default-features = false, optional = true, features = ["disable_target_static_assertions"] }
substrate-api-client = { path = "..", default-features = false, optional = true, features = ["disable_target_static_assertions"] }

# substrate dependencies
Expand All @@ -22,3 +23,4 @@ sp-io = { default-features = false, features = ["disable_oom", "disable_panic_ha
api-client = ["substrate-api-client"]
compose-macros = ["ac-compose-macros"]
node-api = ["ac-node-api"]
primitives = ["ac-primitives"]
10 changes: 9 additions & 1 deletion test-no-std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#![no_std]
#![no_main]

#[cfg(not(any(feature = "api-client", feature = "node-api", feature = "compose-macros")))]
#[cfg(not(any(
feature = "api-client",
feature = "node-api",
feature = "compose-macros",
feature = "primitives"
)))]
compile_error!(
"either feature \"api-client\", \"compose-macro\", or feature \"node-api\" must be enabled"
);
Expand All @@ -19,6 +24,9 @@ extern crate ac_compose_macros;
#[cfg(feature = "node-api")]
extern crate ac_node_api;

#[cfg(feature = "primitives")]
extern crate ac_primitives;

// The libc crate allows importing functions from C.
extern crate libc;
use core::{
Expand Down

0 comments on commit d2e25a5

Please sign in to comment.