From d2e25a5a636c06795bc6505c33362ea54ac120bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bigna=20H=C3=A4rdi?= <73821294+haerdib@users.noreply.github.com> Date: Mon, 17 Apr 2023 09:33:19 +0200 Subject: [PATCH] Clean up dependencies and fix primitives no_std build (#535) * 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 --- .github/workflows/ci.yml | 3 ++- Cargo.lock | 29 +++++++----------------- Cargo.toml | 9 ++++++-- README.md | 4 ++-- compose-macros/Cargo.toml | 22 ++++++++---------- compose-macros/README.md | 3 +++ compose-macros/src/lib.rs | 3 --- examples/examples/event_error_details.rs | 3 +-- node-api/Cargo.toml | 10 +++++--- node-api/README.md | 7 ++++++ primitives/Cargo.toml | 18 ++++++++++++--- primitives/README.md | 3 +++ test-no-std/Cargo.toml | 4 +++- test-no-std/src/main.rs | 10 +++++++- 14 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 compose-macros/README.md create mode 100644 node-api/README.md create mode 100644 primitives/README.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 729424c44..2ce0e3871 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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, diff --git a/Cargo.lock b/Cargo.lock index 9b4c562db..adb674009 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,10 +18,6 @@ version = "0.3.0" dependencies = [ "ac-primitives", "log", - "parity-scale-codec", - "sp-application-crypto", - "sp-core", - "sp-runtime", ] [[package]] @@ -55,7 +51,7 @@ dependencies = [ "bitvec", "derive_more", "either", - "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", + "frame-metadata", "hex", "log", "parity-scale-codec", @@ -73,7 +69,6 @@ name = "ac-primitives" version = "0.6.0" dependencies = [ "frame-system", - "hex", "impl-serde", "node-template-runtime", "pallet-assets", @@ -85,9 +80,11 @@ dependencies = [ "scale-info", "serde", "serde_json", + "sp-application-crypto", "sp-core", "sp-keyring", "sp-runtime", + "sp-runtime-interface", "sp-staking", "sp-version", "sp-weights", @@ -1191,20 +1188,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df6bb8542ef006ef0de09a5c4420787d79823c0ed7924225822362fd2bf2ff2d" -dependencies = [ - "cfg-if 1.0.0", - "parity-scale-codec", - "scale-info", - "serde", -] - -[[package]] -name = "frame-metadata" -version = "15.0.0" -source = "git+https://github.com/paritytech/frame-metadata#02a063bc5e6170f6e7e1d9295da4dec887e86bc4" +checksum = "878babb0b136e731cc77ec2fd883ff02745ff21e6fb662729953d44923df009c" dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", @@ -1219,7 +1205,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=master#7363dce0 dependencies = [ "bitflags", "environmental", - "frame-metadata 15.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata", "frame-support-procedural", "impl-trait-for-tuples", "k256", @@ -5315,7 +5301,7 @@ dependencies = [ "ac-node-api", "ac-primitives", "derive_more", - "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", + "frame-metadata", "frame-support", "futures", "hex", @@ -5460,6 +5446,7 @@ version = "0.7.0" dependencies = [ "ac-compose-macros", "ac-node-api", + "ac-primitives", "libc", "sp-io", "substrate-api-client", diff --git a/Cargo.toml b/Cargo.toml index 34278c8e7..b8d6f432b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,11 @@ version = "0.11.0" authors = ["Supercomputing Systems AG "] 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] @@ -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"] } @@ -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" } @@ -63,6 +68,7 @@ disable_target_static_assertions = [ std = [ # crates.io no_std "codec/std", + "frame-metadata/std", "hex/std", "log/std", "serde/std", @@ -70,7 +76,6 @@ std = [ # crates.io std only "url", # substrate no_std - "frame-metadata/std", "sp-core/std", "sp-runtime/std", "sp-runtime-interface/std", diff --git a/README.md b/README.md index 1a61223e6..2860062ae 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

-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. @@ -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. diff --git a/compose-macros/Cargo.toml b/compose-macros/Cargo.toml index 93475efde..9e2a7e2bd 100644 --- a/compose-macros/Cargo.toml +++ b/compose-macros/Cargo.toml @@ -4,30 +4,26 @@ version = "0.3.0" authors = ["Supercomputing Systems AG "] 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", ] diff --git a/compose-macros/README.md b/compose-macros/README.md new file mode 100644 index 000000000..0b5fb6319 --- /dev/null +++ b/compose-macros/README.md @@ -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. diff --git a/compose-macros/src/lib.rs b/compose-macros/src/lib.rs index 5ca7890fa..575134a70 100644 --- a/compose-macros/src/lib.rs +++ b/compose-macros/src/lib.rs @@ -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; diff --git a/examples/examples/event_error_details.rs b/examples/examples/event_error_details.rs index e3545eaa3..e32181c14 100644 --- a/examples/examples/event_error_details.rs +++ b/examples/examples/event_error_details.rs @@ -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 }, }; diff --git a/node-api/Cargo.toml b/node-api/Cargo.toml index eafaf63d4..46dba6bda 100644 --- a/node-api/Cargo.toml +++ b/node-api/Cargo.toml @@ -1,14 +1,20 @@ [package] name = "ac-node-api" version = "0.3.0" +authors = ["Supercomputing Systems AG "] 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 } @@ -16,7 +22,6 @@ 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" } @@ -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. @@ -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 diff --git a/node-api/README.md b/node-api/README.md new file mode 100644 index 000000000..389f68a4f --- /dev/null +++ b/node-api/README.md @@ -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 diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index fa939a050..586278cdc 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -4,10 +4,14 @@ version = "0.6.0" authors = ["Supercomputing Systems AG "] 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"] } @@ -15,11 +19,14 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo 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" } @@ -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", @@ -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", diff --git a/primitives/README.md b/primitives/README.md new file mode 100644 index 000000000..7a2ccfab7 --- /dev/null +++ b/primitives/README.md @@ -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. diff --git a/test-no-std/Cargo.toml b/test-no-std/Cargo.toml index a7d97c05e..f8acdc5ee 100644 --- a/test-no-std/Cargo.toml +++ b/test-no-std/Cargo.toml @@ -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 @@ -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"] diff --git a/test-no-std/src/main.rs b/test-no-std/src/main.rs index 4afbe0d79..e20bc919f 100644 --- a/test-no-std/src/main.rs +++ b/test-no-std/src/main.rs @@ -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" ); @@ -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::{