From f0b72b9104696172b0116b3ff4e586ff42d34e28 Mon Sep 17 00:00:00 2001 From: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:54:14 +0200 Subject: [PATCH] Add `subxt` feature in `subxt-signer` crate to default features (#1193) * add subxt to subxt-signer default features * distinguish between native and web in signer * fix formatting and clippy * rustfmt --- examples/parachain-example/Cargo.toml | 2 +- signer/Cargo.toml | 7 ++++--- signer/README.md | 4 +++- signer/src/lib.rs | 3 +++ subxt/Cargo.toml | 2 +- testing/integration-tests/Cargo.toml | 2 +- .../src/full_client/client/unstable_rpcs.rs | 5 +---- testing/ui-tests/Cargo.toml | 5 +---- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/parachain-example/Cargo.toml b/examples/parachain-example/Cargo.toml index 929acf6578..bb959d4092 100644 --- a/examples/parachain-example/Cargo.toml +++ b/examples/parachain-example/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] subxt = { path = "../../subxt" } -subxt-signer = { path = "../../signer", features = ["subxt"] } +subxt-signer = { path = "../../signer" } futures = { version = "0.3.27", default-features = false, features = ["std"] } tokio = { version = "1.28", features = ["macros", "time", "rt-multi-thread"] } sp-core = "21.0.0" diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 3b4398c303..d8e0398203 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -15,7 +15,7 @@ description = "Sign extrinsics to be submitted by Subxt" keywords = ["parity", "subxt", "extrinsic", "signer"] [features] -default = ["sr25519", "ecdsa"] +default = ["sr25519", "ecdsa", "subxt", "native"] # Pick the signer implementation(s) you need by enabling the # corresponding features. Note: I had more difficulties getting @@ -30,11 +30,12 @@ subxt = ["dep:subxt"] # The getrandom package is used via schnorrkel. We need to enable the JS # feature on it if compiling for the web. -web = ["getrandom/js"] +web = ["getrandom/js", "subxt?/web"] +native = ["subxt?/native"] [dependencies] +subxt = { workspace = true, optional = true, default-features = false } regex = { workspace = true } -subxt = { workspace = true, optional = true } hex = { workspace = true } codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } sp-core-hashing = { workspace = true } diff --git a/signer/README.md b/signer/README.md index 01d8a21bdd..1bd77b4770 100644 --- a/signer/README.md +++ b/signer/README.md @@ -1,3 +1,5 @@ # Subxt-signer -This library exposes a small, WASM compatible signer implementation which can be used in conjunction with Subxt to sign transactions. \ No newline at end of file +This library exposes a small, WASM compatible signer implementation which can be used in conjunction with Subxt to sign transactions. + +This library can be used without Subxt by disabling the `subxt` feature flag, which is enabled by default. diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 846d95d36b..5287b2b6ce 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -38,3 +38,6 @@ pub use secrecy::{ExposeSecret, SecretString}; // SecretUri's can be parsed from strings and used to generate key pairs. // DeriveJunctions are the "path" part of these SecretUris. pub use crypto::{DeriveJunction, SecretUri, SecretUriError, DEV_PHRASE}; + +#[cfg(all(feature = "subxt", not(any(feature = "web", feature = "native"))))] +compile_error!("subxt-signer: When using the 'subxt' feature, exactly one of the 'web' and 'native' features should be used."); diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 35fd8e634c..c1968746e1 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -103,7 +103,7 @@ sp-core = { workspace = true } sp-keyring = { workspace = true } sp-runtime = { workspace = true } assert_matches = { workspace = true } -subxt-signer = { path = "../signer", features = ["subxt"] } +subxt-signer = { path = "../signer" } # Tracing subscriber is useful for light-client examples to ensure that # the `bootNodes` and chain spec are configured correctly. If all is fine, then # the light-client wlll emit INFO logs with diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index 48685bbc60..27a2c83d9f 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -34,7 +34,7 @@ scale-info = { workspace = true, features = ["bit-vec"] } sp-core = { workspace = true } syn = { workspace = true } subxt = { workspace = true, features = ["unstable-metadata", "native", "jsonrpsee", "substrate-compat"] } -subxt-signer = { workspace = true, features = ["subxt"] } +subxt-signer = { workspace = true } subxt-codegen = { workspace = true } subxt-metadata = { workspace = true } test-runtime = { workspace = true } diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index 2252abc3e4..7704e0d002 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -210,10 +210,7 @@ async fn chainhead_unstable_unpin() { }; let sub_id = blocks.subscription_id().unwrap(); - assert!(rpc - .chainhead_unstable_unpin(sub_id.clone(), hash) - .await - .is_ok()); + assert!(rpc.chainhead_unstable_unpin(sub_id, hash).await.is_ok()); // The block was already unpinned. assert!(rpc.chainhead_unstable_unpin(sub_id, hash).await.is_err()); } diff --git a/testing/ui-tests/Cargo.toml b/testing/ui-tests/Cargo.toml index 2e3cba2efb..3ae0f25e92 100644 --- a/testing/ui-tests/Cargo.toml +++ b/testing/ui-tests/Cargo.toml @@ -13,10 +13,7 @@ trybuild = { workspace = true } hex = { workspace = true } scale-info = { workspace = true, features = ["bit-vec"] } frame-metadata = { workspace = true } -codec = { package = "parity-scale-codec", workspace = true, features = [ - "derive", - "bit-vec", -] } +codec = { package = "parity-scale-codec", workspace = true, features = ["derive", "bit-vec"] } subxt = { workspace = true, features = ["native", "jsonrpsee"] } subxt-metadata = { workspace = true } generate-custom-metadata = { path = "../generate-custom-metadata" }