From 9aa32ef63d935820bf86ab7f42b96ab92fe1f406 Mon Sep 17 00:00:00 2001 From: David Craven Date: Thu, 13 Aug 2020 17:04:30 +0200 Subject: [PATCH 1/7] Fix port number. (#151) --- client/src/lib.rs | 18 ++++++++++-------- src/lib.rs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index a335b11c48..2dabb6aee2 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -218,8 +218,8 @@ pub struct SubxtClientConfig { pub chain_spec: C, /// Role of the node. pub role: Role, - /// Enable telemetry. - pub enable_telemetry: bool, + /// Enable telemetry on the given port. + pub telemetry: Option, } impl SubxtClientConfig { @@ -238,10 +238,12 @@ impl SubxtClientConfig { wasm_external_transport: None, use_yamux_flow_control: true, }; - let telemetry_endpoints = if self.enable_telemetry { - let endpoints = - TelemetryEndpoints::new(vec![("/ip4/127.0.0.1/tcp/99000/ws".into(), 0)]) - .expect("valid config; qed"); + let telemetry_endpoints = if let Some(port) = self.telemetry { + let endpoints = TelemetryEndpoints::new(vec![( + format!("/ip4/127.0.0.1/tcp/{}/ws", port), + 0, + )]) + .expect("valid config; qed"); Some(endpoints) } else { None @@ -356,7 +358,7 @@ mod tests { keystore: KeystoreConfig::InMemory, chain_spec, role: Role::Light, - enable_telemetry: false, + telemetry: None, }; let client = ClientBuilder::::new() .set_client( @@ -389,7 +391,7 @@ mod tests { keystore: KeystoreConfig::InMemory, chain_spec: test_node::chain_spec::development_config().unwrap(), role: Role::Authority(AccountKeyring::Alice), - enable_telemetry: false, + telemetry: None, }; let client = ClientBuilder::::new() .set_client( diff --git a/src/lib.rs b/src/lib.rs index b790083cd8..b98755625f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -588,7 +588,7 @@ mod tests { }, chain_spec: test_node::chain_spec::development_config().unwrap(), role: Role::Authority(key), - enable_telemetry: false, + telemetry: None, }; let client = ClientBuilder::new() .set_client( From 59b9c117b76f68ec480729f03ef644954b8b555c Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Fri, 14 Aug 2020 04:06:30 +0800 Subject: [PATCH 2/7] Add a method to fetch an unhashed key, close #100 (#152) * Add a method to fetch an unhashed key, close #100 * Return decoded value * Refactoring --- src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b98755625f..e1a75a4011 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,13 +258,12 @@ impl Client { &self.metadata } - /// Fetch a StorageKey with an optional block hash. - pub async fn fetch>( + /// Fetch the value under an unhashed storage key + pub async fn fetch_unhashed( &self, - store: &F, + key: StorageKey, hash: Option, - ) -> Result, Error> { - let key = store.key(&self.metadata)?; + ) -> Result, Error> { if let Some(data) = self.rpc.storage(&key, hash).await? { Ok(Some(Decode::decode(&mut &data.0[..])?)) } else { @@ -272,6 +271,16 @@ impl Client { } } + /// Fetch a StorageKey with an optional block hash. + pub async fn fetch>( + &self, + store: &F, + hash: Option, + ) -> Result, Error> { + let key = store.key(&self.metadata)?; + self.fetch_unhashed::(key, hash).await + } + /// Fetch a StorageKey that has a default value with an optional block hash. pub async fn fetch_or_default>( &self, From eac2ce3b2a9d8a3a0e248229e77b00846e50647b Mon Sep 17 00:00:00 2001 From: David Craven Date: Mon, 17 Aug 2020 10:14:26 +0200 Subject: [PATCH 3/7] Different assert. (#153) --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e1a75a4011..260fff9e2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,7 +241,7 @@ impl> KeyIter { } } } - debug_assert_eq!(self.buffer.len(), self.count as usize); + debug_assert_eq!(self.buffer.len(), keys.len()); } } } @@ -604,7 +604,7 @@ mod tests { SubxtClient::from_config(config, test_node::service::new_full) .expect("Error creating subxt client"), ) - .set_page_size(2) + .set_page_size(3) .build() .await .expect("Error creating client"); From 3ea9d3b8bbeb8c7ab9c2f7b382c39a54ba2bcb6a Mon Sep 17 00:00:00 2001 From: David Craven Date: Tue, 25 Aug 2020 10:50:14 +0200 Subject: [PATCH 4/7] Update to rc6. (#155) * Update to rc6. * Fix clippy warnings. --- Cargo.toml | 30 ++--- client/Cargo.toml | 12 +- client/src/lib.rs | 14 +- proc-macro/Cargo.toml | 10 +- test-node/Cargo.toml | 42 +++--- test-node/runtime/Cargo.toml | 66 ++++----- test-node/runtime/build.rs | 2 +- test-node/runtime/src/lib.rs | 57 ++++---- test-node/src/chain_spec.rs | 10 +- test-node/src/command.rs | 20 ++- test-node/src/service.rs | 250 ++++++++++++++++++----------------- 11 files changed, 260 insertions(+), 253 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea222904f8..f86ab4e8ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,30 +25,30 @@ thiserror = "1.0.20" futures = "0.3.5" jsonrpsee = { version = "0.1.0", features = ["ws"] } num-traits = { version = "0.2.12", default-features = false } -serde = { version = "1.0.114", features = ["derive"] } -serde_json = "1.0.56" +serde = { version = "1.0.115", features = ["derive"] } +serde_json = "1.0.57" url = "2.1.1" codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] } -frame-metadata = { version = "11.0.0-rc5", package = "frame-metadata" } -frame-support = { version = "2.0.0-rc5", package = "frame-support" } -sp-runtime = { version = "2.0.0-rc5", package = "sp-runtime" } -sp-version = { version = "2.0.0-rc5", package = "sp-version" } -pallet-indices = { version = "2.0.0-rc5", package = "pallet-indices" } +frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" } +frame-support = { version = "2.0.0-rc6", package = "frame-support" } +sp-runtime = { version = "2.0.0-rc6", package = "sp-runtime" } +sp-version = { version = "2.0.0-rc6", package = "sp-version" } +pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" } hex = "0.4.2" -sp-rpc = { version = "2.0.0-rc5", package = "sp-rpc" } -sp-core = { version = "2.0.0-rc5", package = "sp-core" } -sc-rpc-api = { version = "0.8.0-rc5", package = "sc-rpc-api" } -sp-transaction-pool = { version = "2.0.0-rc5", package = "sp-transaction-pool" } +sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" } +sp-core = { version = "2.0.0-rc6", package = "sp-core" } +sc-rpc-api = { version = "0.8.0-rc6", package = "sc-rpc-api" } +sp-transaction-pool = { version = "2.0.0-rc6", package = "sp-transaction-pool" } substrate-subxt-client = { version = "0.3.0", path = "client", optional = true } substrate-subxt-proc-macro = { version = "0.11.0", path = "proc-macro" } [dev-dependencies] -async-std = { version = "1.6.2", features = ["attributes"] } +async-std = { version = "1.6.3", features = ["attributes"] } env_logger = "0.7.1" -frame-system = { version = "2.0.0-rc5", package = "frame-system" } -pallet-balances = { version = "2.0.0-rc5", package = "pallet-balances" } -sp-keyring = { version = "2.0.0-rc5", package = "sp-keyring" } +frame-system = { version = "2.0.0-rc6", package = "frame-system" } +pallet-balances = { version = "2.0.0-rc6", package = "pallet-balances" } +sp-keyring = { version = "2.0.0-rc6", package = "sp-keyring" } substrate-subxt-client = { version = "0.3.0", path = "client" } tempdir = "0.3.7" test-node = { path = "test-node" } diff --git a/client/Cargo.toml b/client/Cargo.toml index a9a31bab3d..8bd0a919f5 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -12,19 +12,19 @@ description = "Embed a substrate node into your subxt application." keywords = ["parity", "substrate", "blockchain"] [dependencies] -async-std = "1.6.2" +async-std = "1.6.3" futures = { version = "0.3.5", features = ["compat"] } futures01 = { package = "futures", version = "0.1.29" } jsonrpsee = "0.1.0" log = "0.4.11" -sc-network = { version = "0.8.0-rc5", default-features = false } -sc-service = { version = "0.8.0-rc5", default-features = false } -serde_json = "1.0.56" -sp-keyring = "2.0.0-rc5" +sc-network = { version = "0.8.0-rc6", default-features = false } +sc-service = { version = "0.8.0-rc6", default-features = false } +serde_json = "1.0.57" +sp-keyring = "2.0.0-rc6" thiserror = "1.0.20" [dev-dependencies] -async-std = { version = "1.6.2", features = ["attributes"] } +async-std = { version = "1.6.3", features = ["attributes"] } env_logger = "0.7.1" substrate-subxt = { path = ".." } tempdir = "0.3.7" diff --git a/client/src/lib.rs b/client/src/lib.rs index 2dabb6aee2..e6c02ad05e 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -64,7 +64,6 @@ use sc_service::{ use std::{ future::Future, pin::Pin, - sync::Arc, }; use thiserror::Error; @@ -87,17 +86,16 @@ pub struct SubxtClient { impl SubxtClient { /// Create a new client. - pub fn new(mut task_manager: TaskManager, rpc: Arc) -> Self { + pub fn new(mut task_manager: TaskManager, rpc: RpcHandlers) -> Self { let (to_back, from_front) = mpsc::channel(4); let (to_front, from_back) = mpsc01::channel(4); let session = RpcSession::new(to_front.clone()); - let session2 = session.clone(); task::spawn( select( Box::pin(from_front.for_each(move |message: String| { let rpc = rpc.clone(); - let session = session2.clone(); + let session = session.clone(); let mut to_front = to_front.clone().sink_compat(); async move { let response = rpc.rpc_query(&session, &message).await; @@ -122,11 +120,9 @@ impl SubxtClient { /// Creates a new client from a config. pub fn from_config( config: SubxtClientConfig, - builder: impl Fn( - Configuration, - ) -> Result<(TaskManager, Arc), ServiceError>, + builder: impl Fn(Configuration) -> Result<(TaskManager, RpcHandlers), ServiceError>, ) -> Result { - let config = config.to_service_config(); + let config = config.into_service_config(); let (task_manager, rpc_handlers) = (builder)(config)?; Ok(Self::new(task_manager, rpc_handlers)) } @@ -224,7 +220,7 @@ pub struct SubxtClientConfig { impl SubxtClientConfig { /// Creates a service configuration. - pub fn to_service_config(self) -> Configuration { + pub fn into_service_config(self) -> Configuration { let mut network = NetworkConfiguration::new( format!("{} (subxt client)", self.chain_spec.name()), "unknown", diff --git a/proc-macro/Cargo.toml b/proc-macro/Cargo.toml index 844920f0cf..0a112230f2 100644 --- a/proc-macro/Cargo.toml +++ b/proc-macro/Cargo.toml @@ -18,19 +18,19 @@ proc-macro = true heck = "0.3.1" proc-macro2 = "1.0.19" proc-macro-crate = "0.1.5" -proc-macro-error = "1.0.3" +proc-macro-error = "1.0.4" quote = "1.0.7" -syn = "1.0.35" +syn = "1.0.38" synstructure = "0.12.4" [dev-dependencies] -async-std = { version = "1.6.2", features = ["attributes"] } +async-std = { version = "1.6.3", features = ["attributes"] } codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive"] } env_logger = "0.7.1" pretty_assertions = "0.6.1" -sp-keyring = "2.0.0-rc5" +sp-keyring = "2.0.0-rc6" substrate-subxt = { path = ".." } -trybuild = "1.0.30" +trybuild = "1.0.32" [[test]] name = "balances" diff --git a/test-node/Cargo.toml b/test-node/Cargo.toml index 82a9c9a20f..5b25fd25a4 100644 --- a/test-node/Cargo.toml +++ b/test-node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-node" -version = "2.0.0-rc5" +version = "2.0.0" authors = ["Anonymous"] description = "Substrate Node template" edition = "2018" @@ -15,28 +15,28 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] futures = "0.3.5" log = "0.4.11" -structopt = "0.3.15" +structopt = "0.3.16" parking_lot = "0.11.0" -sc-cli = { version = "0.8.0-rc5", features = ["wasmtime"] } -sp-core = "2.0.0-rc5" -sc-executor = { version = "0.8.0-rc5", features = ["wasmtime"] } -sc-service = { version = "0.8.0-rc5", features = ["wasmtime"] } -sp-inherents = "2.0.0-rc5" -sc-transaction-pool = "2.0.0-rc5" -sp-transaction-pool = "2.0.0-rc5" -sc-network = "0.8.0-rc5" -sc-consensus-aura = "0.8.0-rc5" -sp-consensus-aura = "0.8.0-rc5" -sp-consensus = "0.8.0-rc5" -sc-consensus = "0.8.0-rc5" -sc-finality-grandpa = "0.8.0-rc5" -sp-finality-grandpa = "2.0.0-rc5" -sc-client-api = "2.0.0-rc5" -sp-runtime = "2.0.0-rc5" -sc-basic-authorship = "0.8.0-rc5" +sc-cli = { version = "0.8.0-rc6", features = ["wasmtime"] } +sp-core = "2.0.0-rc6" +sc-executor = { version = "0.8.0-rc6", features = ["wasmtime"] } +sc-service = { version = "0.8.0-rc6", features = ["wasmtime"] } +sp-inherents = "2.0.0-rc6" +sc-transaction-pool = "2.0.0-rc6" +sp-transaction-pool = "2.0.0-rc6" +sc-network = "0.8.0-rc6" +sc-consensus-aura = "0.8.0-rc6" +sp-consensus-aura = "0.8.0-rc6" +sp-consensus = "0.8.0-rc6" +sc-consensus = "0.8.0-rc6" +sc-finality-grandpa = "0.8.0-rc6" +sp-finality-grandpa = "2.0.0-rc6" +sc-client-api = "2.0.0-rc6" +sp-runtime = "2.0.0-rc6" +sc-basic-authorship = "0.8.0-rc6" -test-node-runtime = { version = "2.0.0-rc5", path = "runtime" } +test-node-runtime = { path = "runtime" } [build-dependencies] -substrate-build-script-utils = "2.0.0-rc5" +substrate-build-script-utils = "2.0.0-rc6" diff --git a/test-node/runtime/Cargo.toml b/test-node/runtime/Cargo.toml index 2a27d3ea3a..85463292cc 100644 --- a/test-node/runtime/Cargo.toml +++ b/test-node/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-node-runtime" -version = "2.0.0-rc5" +version = "2.0.0" authors = ["Anonymous"] edition = "2018" license = "Unlicense" @@ -13,43 +13,47 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] } -aura = { version = "2.0.0-rc5", default-features = false, package = "pallet-aura" } -balances = { version = "2.0.0-rc5", default-features = false, package = "pallet-balances" } -frame-support = { version = "2.0.0-rc5", default-features = false } -grandpa = { version = "2.0.0-rc5", default-features = false, package = "pallet-grandpa" } -randomness-collective-flip = { version = "2.0.0-rc5", default-features = false, package = "pallet-randomness-collective-flip" } -sudo = { version = "2.0.0-rc5", default-features = false, package = "pallet-sudo" } -system = { version = "2.0.0-rc5", default-features = false, package = "frame-system" } -timestamp = { version = "2.0.0-rc5", default-features = false, package = "pallet-timestamp" } -transaction-payment = { version = "2.0.0-rc5", default-features = false, package = "pallet-transaction-payment" } -frame-executive = { version = "2.0.0-rc5", default-features = false } -serde = { version = "1.0.114", optional = true, features = ["derive"] } -sp-api = { version = "2.0.0-rc5", default-features = false } -sp-block-builder = { version = "2.0.0-rc5", default-features = false } -sp-consensus-aura = { version = "0.8.0-rc5", default-features = false } -sp-core = { version = "2.0.0-rc5", default-features = false } -sp-inherents = { version = "2.0.0-rc5", default-features = false } -sp-io = { version = "2.0.0-rc5", default-features = false } -sp-offchain = { version = "2.0.0-rc5", default-features = false } -sp-runtime = { version = "2.0.0-rc5", default-features = false } -sp-session = { version = "2.0.0-rc5", default-features = false } -sp-std = { version = "2.0.0-rc5", default-features = false } -sp-transaction-pool = { version = "2.0.0-rc5", default-features = false } -sp-version = { version = "2.0.0-rc5", default-features = false } +frame-executive = { version = "2.0.0-rc6", default-features = false } +frame-support = { version = "2.0.0-rc6", default-features = false } +frame-system = { version = "2.0.0-rc6", default-features = false } +pallet-aura = { version = "2.0.0-rc6", default-features = false } +pallet-balances = { version = "2.0.0-rc6", default-features = false } +pallet-grandpa = { version = "2.0.0-rc6", default-features = false } +pallet-randomness-collective-flip = { version = "2.0.0-rc6", default-features = false } +pallet-sudo = { version = "2.0.0-rc6", default-features = false } +pallet-timestamp = { version = "2.0.0-rc6", default-features = false } +pallet-transaction-payment = { version = "2.0.0-rc6", default-features = false } +serde = { version = "1.0.115", optional = true, features = ["derive"] } +sp-api = { version = "2.0.0-rc6", default-features = false } +sp-block-builder = { version = "2.0.0-rc6", default-features = false } +sp-consensus-aura = { version = "0.8.0-rc6", default-features = false } +sp-core = { version = "2.0.0-rc6", default-features = false } +sp-inherents = { version = "2.0.0-rc6", default-features = false } +sp-io = { version = "2.0.0-rc6", default-features = false } +sp-offchain = { version = "2.0.0-rc6", default-features = false } +sp-runtime = { version = "2.0.0-rc6", default-features = false } +sp-session = { version = "2.0.0-rc6", default-features = false } +sp-std = { version = "2.0.0-rc6", default-features = false } +sp-transaction-pool = { version = "2.0.0-rc6", default-features = false } +sp-version = { version = "2.0.0-rc6", default-features = false } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner" } +substrate-wasm-builder-runner = "1.0.6" [features] default = ["std"] std = [ - "aura/std", - "balances/std", "codec/std", "frame-executive/std", "frame-support/std", - "grandpa/std", - "randomness-collective-flip/std", + "frame-system/std", + "pallet-aura/std", + "pallet-balances/std", + "pallet-grandpa/std", + "pallet-randomness-collective-flip/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment/std", "serde", "sp-api/std", "sp-block-builder/std", @@ -63,8 +67,4 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", - "sudo/std", - "system/std", - "timestamp/std", - "transaction-payment/std", ] diff --git a/test-node/runtime/build.rs b/test-node/runtime/build.rs index 8dfb883c04..2ab31cf6cd 100644 --- a/test-node/runtime/build.rs +++ b/test-node/runtime/build.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with substrate-subxt. If not, see . -use wasm_builder_runner::WasmBuilder; +use substrate_wasm_builder_runner::WasmBuilder; fn main() { WasmBuilder::new() diff --git a/test-node/runtime/src/lib.rs b/test-node/runtime/src/lib.rs index 66f9c1bd52..85abd73d32 100644 --- a/test-node/runtime/src/lib.rs +++ b/test-node/runtime/src/lib.rs @@ -19,12 +19,13 @@ #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +#![allow(clippy::large_enum_variant)] // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use grandpa::{ +use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, @@ -61,7 +62,6 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. -pub use balances::Call as BalancesCall; pub use frame_support::{ construct_runtime, parameter_types, @@ -81,13 +81,14 @@ pub use frame_support::{ }, StorageValue, }; +pub use pallet_balances::Call as BalancesCall; +pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{ Perbill, Permill, }; -pub use timestamp::Call as TimestampCall; /// An index to a block. pub type BlockNumber = u32; @@ -180,7 +181,7 @@ parameter_types! { pub const Version: RuntimeVersion = VERSION; } -impl system::Trait for Runtime { +impl frame_system::Trait for Runtime { /// The basic call filter to use in dispatchable. type BaseCallFilter = (); /// The identifier used to distinguish between accounts. @@ -234,16 +235,16 @@ impl system::Trait for Runtime { /// What to do if an account is fully reaped from the system. type OnKilledAccount = (); /// The data to be stored in an account. - type AccountData = balances::AccountData; + type AccountData = pallet_balances::AccountData; /// Weight information for the extrinsics of this pallet. type SystemWeightInfo = (); } -impl aura::Trait for Runtime { +impl pallet_aura::Trait for Runtime { type AuthorityId = AuraId; } -impl grandpa::Trait for Runtime { +impl pallet_grandpa::Trait for Runtime { type Event = Event; type Call = Call; @@ -264,7 +265,7 @@ parameter_types! { pub const MinimumPeriod: u64 = SLOT_DURATION / 2; } -impl timestamp::Trait for Runtime { +impl pallet_timestamp::Trait for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; type OnTimestampSet = Aura; @@ -276,7 +277,7 @@ parameter_types! { pub const ExistentialDeposit: u128 = 500; } -impl balances::Trait for Runtime { +impl pallet_balances::Trait for Runtime { /// The type for recording an account's balance. type Balance = Balance; /// The ubiquitous event type. @@ -291,15 +292,15 @@ parameter_types! { pub const TransactionByteFee: Balance = 1; } -impl transaction_payment::Trait for Runtime { - type Currency = balances::Module; +impl pallet_transaction_payment::Trait for Runtime { + type Currency = pallet_balances::Module; type OnTransactionPayment = (); type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); } -impl sudo::Trait for Runtime { +impl pallet_sudo::Trait for Runtime { type Event = Event; type Call = Call; } @@ -310,14 +311,14 @@ construct_runtime!( NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Module, Call, Config, Storage, Event}, - RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage}, - Timestamp: timestamp::{Module, Call, Storage, Inherent}, - Aura: aura::{Module, Config, Inherent}, - Grandpa: grandpa::{Module, Call, Storage, Config, Event}, - Balances: balances::{Module, Call, Storage, Config, Event}, - TransactionPayment: transaction_payment::{Module, Storage}, - Sudo: sudo::{Module, Call, Config, Storage, Event}, + System: frame_system::{Module, Call, Config, Storage, Event}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, + Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, + Aura: pallet_aura::{Module, Config, Inherent}, + Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + TransactionPayment: pallet_transaction_payment::{Module, Storage}, + Sudo: pallet_sudo::{Module, Call, Config, Storage, Event}, } ); @@ -333,13 +334,13 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The SignedExtension to the basic transaction logic. pub type SignedExtra = ( - system::CheckSpecVersion, - system::CheckTxVersion, - system::CheckGenesis, - system::CheckEra, - system::CheckNonce, - system::CheckWeight, - transaction_payment::ChargeTransactionPayment, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -350,7 +351,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic, + frame_system::ChainContext, Runtime, AllModules, >; diff --git a/test-node/src/chain_spec.rs b/test-node/src/chain_spec.rs index c1e028f39b..a9cc64e42d 100644 --- a/test-node/src/chain_spec.rs +++ b/test-node/src/chain_spec.rs @@ -164,12 +164,12 @@ fn testnet_genesis( _enable_println: bool, ) -> GenesisConfig { GenesisConfig { - system: Some(SystemConfig { + frame_system: Some(SystemConfig { // Add Wasm runtime to storage. code: wasm_binary.to_vec(), changes_trie_config: Default::default(), }), - balances: Some(BalancesConfig { + pallet_balances: Some(BalancesConfig { // Configure endowed accounts with initial balance of 1 << 60. balances: endowed_accounts .iter() @@ -177,16 +177,16 @@ fn testnet_genesis( .map(|k| (k, 1 << 60)) .collect(), }), - aura: Some(AuraConfig { + pallet_aura: Some(AuraConfig { authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), }), - grandpa: Some(GrandpaConfig { + pallet_grandpa: Some(GrandpaConfig { authorities: initial_authorities .iter() .map(|x| (x.1.clone(), 1)) .collect(), }), - sudo: Some(SudoConfig { + pallet_sudo: Some(SudoConfig { // Assign network admin rights. key: root_key, }), diff --git a/test-node/src/command.rs b/test-node/src/command.rs index c8196d2291..f4d7e82fd9 100644 --- a/test-node/src/command.rs +++ b/test-node/src/command.rs @@ -18,7 +18,6 @@ use crate::{ chain_spec, cli::Cli, service, - service::new_full_params, }; use sc_cli::{ ChainSpec, @@ -26,7 +25,7 @@ use sc_cli::{ RuntimeVersion, SubstrateCli, }; -use sc_service::ServiceParams; +use sc_service::PartialComponents; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -78,16 +77,13 @@ pub fn run() -> sc_cli::Result<()> { Some(subcommand) => { let runner = cli.create_runner(subcommand)?; runner.run_subcommand(subcommand, |config| { - let ( - ServiceParams { - client, - backend, - task_manager, - import_queue, - .. - }, - .., - ) = new_full_params(config)?; + let PartialComponents { + client, + backend, + task_manager, + import_queue, + .. + } = service::new_partial(&config)?; Ok((client, backend, import_queue, task_manager)) }) } diff --git a/test-node/src/service.rs b/test-node/src/service.rs index 601d19fdc1..454f7f41a9 100644 --- a/test-node/src/service.rs +++ b/test-node/src/service.rs @@ -15,6 +15,7 @@ // along with substrate-subxt. If not, see . //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. +#![allow(clippy::type_complexity)] use sc_client_api::{ ExecutorProvider, @@ -25,13 +26,12 @@ pub use sc_executor::NativeExecutor; use sc_finality_grandpa::{ FinalityProofProvider as GrandpaFinalityProofProvider, SharedVoterState, - StorageAndProofProvider, }; use sc_service::{ error::Error as ServiceError, Configuration, + PartialComponents, RpcHandlers, - ServiceComponents, TaskManager, }; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; @@ -57,28 +57,25 @@ type FullClient = sc_service::TFullClient; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; -pub fn new_full_params( - config: Configuration, +pub fn new_partial( + config: &Configuration, ) -> Result< - ( - sc_service::ServiceParams< - Block, - FullClient, - sc_consensus_aura::AuraImportQueue, - sc_transaction_pool::FullPool, - (), - FullBackend, - >, + sc_service::PartialComponents< + FullClient, + FullBackend, FullSelectChain, - sp_inherents::InherentDataProviders, - sc_finality_grandpa::GrandpaBlockImport< - FullBackend, - Block, - FullClient, - FullSelectChain, - >, - sc_finality_grandpa::LinkHalf, - ), + sp_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + ( + sc_finality_grandpa::GrandpaBlockImport< + FullBackend, + Block, + FullClient, + FullSelectChain, + >, + sc_finality_grandpa::LinkHalf, + ), + >, ServiceError, > { let inherent_data_providers = sp_inherents::InherentDataProviders::new(); @@ -89,13 +86,8 @@ pub fn new_full_params( let select_chain = sc_consensus::LongestChain::new(backend.clone()); - let pool_api = sc_transaction_pool::FullChainApi::new( - client.clone(), - config.prometheus_registry(), - ); let transaction_pool = sc_transaction_pool::BasicPool::new_full( config.transaction_pool.clone(), - std::sync::Arc::new(pool_api), config.prometheus_registry(), task_manager.spawn_handle(), client.clone(), @@ -112,7 +104,7 @@ pub fn new_full_params( client.clone(), ); - let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>( + let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>( sc_consensus_aura::slot_duration(&*client)?, aura_block_import, Some(Box::new(grandpa_block_import.clone())), @@ -121,81 +113,86 @@ pub fn new_full_params( inherent_data_providers.clone(), &task_manager.spawn_handle(), config.prometheus_registry(), + sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()), )?; - let provider = client.clone() as Arc>; - let finality_proof_provider = - Arc::new(GrandpaFinalityProofProvider::new(backend.clone(), provider)); - - let params = sc_service::ServiceParams { - backend, + Ok(sc_service::PartialComponents { client, + backend, + task_manager, import_queue, keystore, - task_manager, - transaction_pool, - config, - block_announce_validator_builder: None, - finality_proof_request_builder: None, - finality_proof_provider: Some(finality_proof_provider), - on_demand: None, - remote_blockchain: None, - rpc_extensions_builder: Box::new(|_| ()), - }; - - Ok(( - params, select_chain, + transaction_pool, inherent_data_providers, - grandpa_block_import, - grandpa_link, - )) + other: (grandpa_block_import, grandpa_link), + }) } /// Builds a new service for a full client. pub fn new_full( config: Configuration, -) -> Result<(TaskManager, Arc), ServiceError> { - let (params, select_chain, inherent_data_providers, block_import, grandpa_link) = - new_full_params(config)?; - - let ( - role, - force_authoring, - name, - enable_grandpa, - prometheus_registry, +) -> Result<(TaskManager, RpcHandlers), ServiceError> { + let PartialComponents { client, - transaction_pool, + backend, + mut task_manager, + import_queue, keystore, - ) = { - let sc_service::ServiceParams { - config, - client, - transaction_pool, - keystore, - .. - } = ¶ms; + select_chain, + transaction_pool, + inherent_data_providers, + other: (block_import, grandpa_link), + } = new_partial(&config)?; - ( - config.role.clone(), - config.force_authoring, - config.network.node_name.clone(), - !config.disable_grandpa, - config.prometheus_registry().cloned(), + let finality_proof_provider = + GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone()); + + let (network, network_status_sinks, system_rpc_tx, network_starter) = + sc_service::build_network(sc_service::BuildNetworkParams { + config: &config, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + spawn_handle: task_manager.spawn_handle(), + import_queue, + on_demand: None, + block_announce_validator_builder: None, + finality_proof_request_builder: None, + finality_proof_provider: Some(finality_proof_provider), + })?; + + if config.offchain_worker.enabled { + sc_service::build_offchain_workers( + &config, + backend.clone(), + task_manager.spawn_handle(), client.clone(), - transaction_pool.clone(), - keystore.clone(), - ) - }; + network.clone(), + ); + } - let ServiceComponents { - task_manager, - rpc_handlers, - network, - telemetry_on_connect_sinks, - .. - } = sc_service::build(params)?; + let role = config.role.clone(); + let force_authoring = config.force_authoring; + let name = config.network.node_name.clone(); + let enable_grandpa = !config.disable_grandpa; + let prometheus_registry = config.prometheus_registry().cloned(); + let telemetry_connection_sinks = sc_service::TelemetryConnectionSinks::default(); + + let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { + network: network.clone(), + client: client.clone(), + keystore: keystore.clone(), + task_manager: &mut task_manager, + transaction_pool: transaction_pool.clone(), + telemetry_connection_sinks: telemetry_connection_sinks.clone(), + rpc_extensions_builder: Box::new(|_, _| ()), + on_demand: None, + remote_blockchain: None, + backend, + network_status_sinks, + system_rpc_tx, + config, + })?; if role.is_authority() { let proposer = sc_basic_authorship::ProposerFactory::new( @@ -256,7 +253,7 @@ pub fn new_full( link: grandpa_link, network, inherent_data_providers, - telemetry_on_connect: Some(telemetry_on_connect_sinks.on_connect_stream()), + telemetry_on_connect: Some(telemetry_connection_sinks.on_connect_stream()), voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(), prometheus_registry, shared_voter_state: SharedVoterState::empty(), @@ -276,26 +273,24 @@ pub fn new_full( )?; } + network_starter.start_network(); Ok((task_manager, rpc_handlers)) } /// Builds a new service for a light client. pub fn new_light( config: Configuration, -) -> Result<(TaskManager, Arc), ServiceError> { - let (client, backend, keystore, task_manager, on_demand) = +) -> Result<(TaskManager, RpcHandlers), ServiceError> { + let (client, backend, keystore, mut task_manager, on_demand) = sc_service::new_light_parts::(&config)?; - let transaction_pool_api = Arc::new(sc_transaction_pool::LightChainApi::new( - client.clone(), - on_demand.clone(), - )); - let transaction_pool = sc_transaction_pool::BasicPool::new_light( + let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light( config.transaction_pool.clone(), - transaction_pool_api, config.prometheus_registry(), task_manager.spawn_handle(), - ); + client.clone(), + on_demand.clone(), + )); let grandpa_block_import = sc_finality_grandpa::light_block_import( client.clone(), @@ -307,7 +302,7 @@ pub fn new_light( let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder(); - let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>( + let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>( sc_consensus_aura::slot_duration(&*client)?, grandpa_block_import, None, @@ -316,33 +311,52 @@ pub fn new_light( InherentDataProviders::new(), &task_manager.spawn_handle(), config.prometheus_registry(), + sp_consensus::NeverCanAuthor, )?; - let finality_proof_provider = Arc::new(GrandpaFinalityProofProvider::new( - backend.clone(), - client.clone() as Arc<_>, - )); + let finality_proof_provider = + GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone()); + + let (network, network_status_sinks, system_rpc_tx, network_starter) = + sc_service::build_network(sc_service::BuildNetworkParams { + config: &config, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + spawn_handle: task_manager.spawn_handle(), + import_queue, + on_demand: Some(on_demand.clone()), + block_announce_validator_builder: None, + finality_proof_request_builder: Some(finality_proof_request_builder), + finality_proof_provider: Some(finality_proof_provider), + })?; + + if config.offchain_worker.enabled { + sc_service::build_offchain_workers( + &config, + backend.clone(), + task_manager.spawn_handle(), + client.clone(), + network.clone(), + ); + } - sc_service::build(sc_service::ServiceParams { - block_announce_validator_builder: None, - finality_proof_request_builder: Some(finality_proof_request_builder), - finality_proof_provider: Some(finality_proof_provider), - on_demand: Some(on_demand), + let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { remote_blockchain: Some(backend.remote_blockchain()), - rpc_extensions_builder: Box::new(|_| ()), - transaction_pool: Arc::new(transaction_pool), + transaction_pool, + task_manager: &mut task_manager, + on_demand: Some(on_demand), + rpc_extensions_builder: Box::new(|_, _| ()), + telemetry_connection_sinks: sc_service::TelemetryConnectionSinks::default(), config, client, - import_queue, keystore, backend, - task_manager, - }) - .map( - |ServiceComponents { - task_manager, - rpc_handlers, - .. - }| (task_manager, rpc_handlers), - ) + network, + network_status_sinks, + system_rpc_tx, + })?; + + network_starter.start_network(); + + Ok((task_manager, rpc_handlers)) } From e9c50e21d04e3b6ed1afaac1daa8cadc62fb9ad3 Mon Sep 17 00:00:00 2001 From: David Craven Date: Tue, 1 Sep 2020 10:15:04 +0000 Subject: [PATCH 5/7] Only return an error if the extrinsic failed. (#156) --- src/error.rs | 44 ++++++++++++++++++++++++------------- src/events.rs | 50 +++++++++++++++++++++++++++++-------------- src/frame/balances.rs | 5 +++-- src/frame/sudo.rs | 7 ++++-- src/subscription.rs | 7 +++++- 5 files changed, 77 insertions(+), 36 deletions(-) diff --git a/src/error.rs b/src/error.rs index cbadeb35f5..195a2d22da 100644 --- a/src/error.rs +++ b/src/error.rs @@ -62,13 +62,7 @@ pub enum Error { TypeSizeUnavailable(String), /// Runtime error. #[error("Runtime error: {0}")] - Runtime(RuntimeError), - /// Bad origin. - #[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")] - BadOrigin, - /// Cannot lookup. - #[error("Cannot lookup some information required to validate the transaction.")] - CannotLookup, + Runtime(#[from] RuntimeError), /// Other error. #[error("Other error: {0}")] Other(String), @@ -98,9 +92,29 @@ impl From for Error { } } -impl Error { +/// Runtime error. +#[derive(Clone, Debug, Eq, Error, PartialEq)] +pub enum RuntimeError { + /// Module error. + #[error("Runtime module error: {0}")] + Module(ModuleError), + /// Bad origin. + #[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")] + BadOrigin, + /// Cannot lookup. + #[error("Cannot lookup some information required to validate the transaction.")] + CannotLookup, + /// Other error. + #[error("Other error: {0}")] + Other(String), +} + +impl RuntimeError { /// Converts a `DispatchError` into a subxt error. - pub fn from_dispatch(metadata: &Metadata, error: DispatchError) -> Result<(), Self> { + pub fn from_dispatch( + metadata: &Metadata, + error: DispatchError, + ) -> Result { match error { DispatchError::Module { index, @@ -109,22 +123,22 @@ impl Error { } => { let module = metadata.module_with_errors(index)?; let error = module.error(error)?; - Err(Error::Runtime(RuntimeError { + Ok(Self::Module(ModuleError { module: module.name().to_string(), error: error.to_string(), })) } - DispatchError::BadOrigin => Err(Error::BadOrigin), - DispatchError::CannotLookup => Err(Error::CannotLookup), - DispatchError::Other(msg) => Err(Error::Other(msg.into())), + DispatchError::BadOrigin => Ok(Self::BadOrigin), + DispatchError::CannotLookup => Ok(Self::CannotLookup), + DispatchError::Other(msg) => Ok(Self::Other(msg.into())), } } } -/// Runtime errors. +/// Module error. #[derive(Clone, Debug, Eq, Error, PartialEq)] #[error("{error} from {module}")] -pub struct RuntimeError { +pub struct ModuleError { pub module: String, pub error: String, } diff --git a/src/events.rs b/src/events.rs index d5f75c9b8c..9a05de14cc 100644 --- a/src/events.rs +++ b/src/events.rs @@ -39,7 +39,10 @@ use std::{ }; use crate::{ - error::Error, + error::{ + Error, + RuntimeError, + }, metadata::{ EventArg, Metadata, @@ -168,7 +171,9 @@ impl EventsDecoder { } }; if let Err(error) = result { - Error::from_dispatch(&self.metadata, error)?; + return Err( + RuntimeError::from_dispatch(&self.metadata, error)?.into() + ) } } } @@ -177,10 +182,7 @@ impl EventsDecoder { } /// Decode events. - pub fn decode_events( - &self, - input: &mut &[u8], - ) -> Result, Error> { + pub fn decode_events(&self, input: &mut &[u8]) -> Result, Error> { let compact_len = >::decode(input)?; let len = compact_len.0 as usize; @@ -201,20 +203,36 @@ impl EventsDecoder { ); let mut event_data = Vec::::new(); - self.decode_raw_bytes(&event_metadata.arguments(), input, &mut event_data)?; - - log::debug!("raw bytes: {}", hex::encode(&event_data),); + let result = self.decode_raw_bytes( + &event_metadata.arguments(), + input, + &mut event_data, + ); + let raw = match result { + Ok(()) => { + log::debug!("raw bytes: {}", hex::encode(&event_data),); + + let event = RawEvent { + module: module.name().to_string(), + variant: event_metadata.name.clone(), + data: event_data, + }; - let event = RawEvent { - module: module.name().to_string(), - variant: event_metadata.name.clone(), - data: event_data, + // topics come after the event data in EventRecord + let _topics = Vec::::decode(input)?; + Raw::Event(event) + } + Err(Error::Runtime(err)) => Raw::Error(err), + Err(err) => return Err(err), }; - // topics come after the event data in EventRecord - let _topics = Vec::::decode(input)?; - r.push((phase, event)); + r.push((phase, raw)); } Ok(r) } } + +pub enum Raw { + Event(RawEvent), + Error(RuntimeError), +} diff --git a/src/frame/balances.rs b/src/frame/balances.rs index edf146dc26..9ebf6d6388 100644 --- a/src/frame/balances.rs +++ b/src/frame/balances.rs @@ -112,6 +112,7 @@ mod tests { use crate::{ error::{ Error, + ModuleError, RuntimeError, }, events::EventsDecoder, @@ -193,8 +194,8 @@ mod tests { let res = client .transfer_and_watch(&hans, alice.account_id(), 100_000_000_000) .await; - if let Err(Error::Runtime(error)) = res { - let error2 = RuntimeError { + if let Err(Error::Runtime(RuntimeError::Module(error))) = res { + let error2 = ModuleError { module: "Balances".into(), error: "InsufficientBalance".into(), }; diff --git a/src/frame/sudo.rs b/src/frame/sudo.rs index 8efb336b7d..733e1290d8 100644 --- a/src/frame/sudo.rs +++ b/src/frame/sudo.rs @@ -43,7 +43,10 @@ pub struct SudoCall<'a, T: Sudo> { mod tests { use super::*; use crate::{ - error::Error, + error::{ + Error, + RuntimeError, + }, extrinsic::PairSigner, frame::balances::TransferCall, tests::{ @@ -68,7 +71,7 @@ mod tests { let res = client.sudo_and_watch(&alice, &call).await; assert!( - if let Err(Error::BadOrigin) = res { + if let Err(Error::Runtime(RuntimeError::BadOrigin)) = res { true } else { false diff --git a/src/subscription.rs b/src/subscription.rs index 6208ce6f7b..6f352edeb8 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -22,6 +22,7 @@ use crate::{ error::Error, events::{ EventsDecoder, + Raw, RawEvent, }, frame::{ @@ -99,13 +100,17 @@ impl EventSubscription { Ok(events) => events, Err(error) => return Some(Err(error)), }; - for (phase, event) in raw_events { + for (phase, raw) in raw_events { if let Phase::ApplyExtrinsic(i) = phase { if let Some(ext_index) = self.extrinsic { if i as usize != ext_index { continue } } + let event = match raw { + Raw::Event(event) => event, + Raw::Error(err) => return Some(Err(err.into())), + }; if let Some((module, variant)) = self.event { if event.module != module || event.variant != variant { continue From af45c39fb1dfdc32393cee2d3c1b306fa7682cc3 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 1 Sep 2020 15:54:01 +0100 Subject: [PATCH 6/7] Release v0.12.0 (#157) * Bump version, update changelog * Bump proc-macro crate * Bump client crate --- CHANGELOG.md | 12 +++++++++++- Cargo.toml | 8 ++++---- client/Cargo.toml | 2 +- proc-macro/Cargo.toml | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b7c66570..3973b334da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# Version 0.12.0 + +* Only return an error if the extrinsic failed. [#156](https://github.com/paritytech/substrate-subxt/pull/156) +* Update to rc6. [#155](https://github.com/paritytech/substrate-subxt/pull/155) +* Different assert. [#153](https://github.com/paritytech/substrate-subxt/pull/153) +* Add a method to fetch an unhashed key, close #100 [#152](https://github.com/paritytech/substrate-subxt/pull/152) +* Fix port number. [#151](https://github.com/paritytech/substrate-subxt/pull/151) +* Implement the `concat` in `twox_64_concat` [#150](https://github.com/paritytech/substrate-subxt/pull/150) +* Storage map iter [#148](https://github.com/paritytech/substrate-subxt/pull/148) + # Version 0.11.0 * Fix build error, wabt 0.9.2 is yanked [#146](https://github.com/paritytech/substrate-subxt/pull/146) @@ -29,7 +39,7 @@ # Version 0.8.0 (2020-05-26) * Update to Substrate release candidate [#116](https://github.com/paritytech/substrate-subxt/pull/116) -* Update to alpha.8 [#114]c +* Update to alpha.8 [#114](https://github.com/paritytech/substrate-subxt/pull/114) * Refactors the api [#113](https://github.com/paritytech/substrate-subxt/pull/113) # Version 0.7.0 (2020-05-13) diff --git a/Cargo.toml b/Cargo.toml index f86ab4e8ac..16b02b4932 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "client", "proc-macro", "test-node"] [package] name = "substrate-subxt" -version = "0.11.0" +version = "0.12.0" authors = ["Parity Technologies "] edition = "2018" @@ -40,8 +40,8 @@ sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" } sp-core = { version = "2.0.0-rc6", package = "sp-core" } sc-rpc-api = { version = "0.8.0-rc6", package = "sc-rpc-api" } sp-transaction-pool = { version = "2.0.0-rc6", package = "sp-transaction-pool" } -substrate-subxt-client = { version = "0.3.0", path = "client", optional = true } -substrate-subxt-proc-macro = { version = "0.11.0", path = "proc-macro" } +substrate-subxt-client = { version = "0.4.0", path = "client", optional = true } +substrate-subxt-proc-macro = { version = "0.12.0", path = "proc-macro" } [dev-dependencies] async-std = { version = "1.6.3", features = ["attributes"] } @@ -49,7 +49,7 @@ env_logger = "0.7.1" frame-system = { version = "2.0.0-rc6", package = "frame-system" } pallet-balances = { version = "2.0.0-rc6", package = "pallet-balances" } sp-keyring = { version = "2.0.0-rc6", package = "sp-keyring" } -substrate-subxt-client = { version = "0.3.0", path = "client" } +substrate-subxt-client = { version = "0.4.0", path = "client" } tempdir = "0.3.7" test-node = { path = "test-node" } wabt = "0.10.0" diff --git a/client/Cargo.toml b/client/Cargo.toml index 8bd0a919f5..f8fe327f73 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substrate-subxt-client" -version = "0.3.0" +version = "0.4.0" authors = ["David Craven ", "Parity Technologies "] edition = "2018" diff --git a/proc-macro/Cargo.toml b/proc-macro/Cargo.toml index 0a112230f2..47072b398b 100644 --- a/proc-macro/Cargo.toml +++ b/proc-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substrate-subxt-proc-macro" -version = "0.11.0" +version = "0.12.0" authors = ["David Craven ", "Parity Technologies "] edition = "2018" autotests = false From e85d01ed08e54374d2383e390cd5c2f09b400063 Mon Sep 17 00:00:00 2001 From: Greg Hill Date: Mon, 7 Sep 2020 14:58:45 +0100 Subject: [PATCH 7/7] decode option event arg (#158) Signed-off-by: Gregory Hill --- src/events.rs | 11 +++++++++++ src/metadata.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/events.rs b/src/events.rs index 9a05de14cc..e8ae9146c5 100644 --- a/src/events.rs +++ b/src/events.rs @@ -154,6 +154,17 @@ impl EventsDecoder { self.decode_raw_bytes(&[*arg.clone()], input, output)? } } + EventArg::Option(arg) => { + match input.read_byte()? { + 0 => (), + 1 => self.decode_raw_bytes(&[*arg.clone()], input, output)?, + _ => { + return Err(Error::Other( + "unexpected first byte decoding Option".into(), + )) + } + } + } EventArg::Tuple(args) => self.decode_raw_bytes(args, input, output)?, EventArg::Primitive(name) => { let result = match name.as_str() { diff --git a/src/metadata.rs b/src/metadata.rs index 3ef160cfc9..176db3aa99 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -398,6 +398,7 @@ pub enum EventArg { Primitive(String), Vec(Box), Tuple(Vec), + Option(Box), } impl FromStr for EventArg { @@ -413,6 +414,15 @@ impl FromStr for EventArg { "Expected closing `>` for `Vec`", )) } + } else if s.starts_with("Option<") { + if s.ends_with('>') { + Ok(EventArg::Option(Box::new(s[7..s.len() - 1].parse()?))) + } else { + Err(ConversionError::InvalidEventArg( + s.to_string(), + "Expected closing `>` for `Option`", + )) + } } else if s.starts_with('(') { if s.ends_with(')') { let mut args = Vec::new(); @@ -439,6 +449,7 @@ impl EventArg { match self { EventArg::Primitive(p) => vec![p.clone()], EventArg::Vec(arg) => arg.primitives(), + EventArg::Option(arg) => arg.primitives(), EventArg::Tuple(args) => { let mut primitives = Vec::new(); for arg in args {