From 917135b3cde8bb487a48855979458e886f2d3710 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 4 Jan 2023 10:56:53 +0100 Subject: [PATCH 1/2] test --- src/api/api_client.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api/api_client.rs b/src/api/api_client.rs index 6b800818a..fd358fb82 100644 --- a/src/api/api_client.rs +++ b/src/api/api_client.rs @@ -86,20 +86,18 @@ use sp_runtime::MultiSignature; pub struct Api where Runtime: FrameSystemConfig, - Params: ExtrinsicParams, { signer: Option, genesis_hash: Runtime::Hash, metadata: Metadata, runtime_version: RuntimeVersion, client: Client, - extrinsic_params_builder: Option, + extrinsic_params_builder: Option, } impl Api where Runtime: FrameSystemConfig, - Params: ExtrinsicParams, { /// Create a new api instance without any node interaction. pub fn new_offline( @@ -152,9 +150,17 @@ where pub fn client(&self) -> &Client { &self.client } +} +impl Api +where + Runtime: FrameSystemConfig, +{ /// Set the extrinscs param builder. - pub fn set_extrinsic_params_builder(&mut self, extrinsic_params: Params::OtherParams) { + pub fn set_extrinsic_params_builder>( + &mut self, + extrinsic_params: Params::OtherParams, + ) { self.extrinsic_params_builder = Some(extrinsic_params); } From 25cf54bf315767f13195e882bd5c193e84f6121f Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 4 Jan 2023 12:55:39 +0100 Subject: [PATCH 2/2] impl () for ExtrinsicParams --- examples/examples/batch_payout.rs | 6 +++--- .../contract_instantiate_with_code.rs | 4 ++-- examples/examples/event_callback.rs | 3 +-- examples/examples/get_blocks.rs | 3 +-- examples/examples/get_storage.rs | 2 +- examples/examples/print_metadata.rs | 3 +-- primitives/src/extrinsic_params.rs | 21 +++++++++++++++++++ src/api/api_client.rs | 14 ++++--------- 8 files changed, 34 insertions(+), 22 deletions(-) diff --git a/examples/examples/batch_payout.rs b/examples/examples/batch_payout.rs index 3387cedc7..8aef7b851 100644 --- a/examples/examples/batch_payout.rs +++ b/examples/examples/batch_payout.rs @@ -18,7 +18,7 @@ use serde_json::Value; use sp_keyring::AccountKeyring; use sp_runtime::{app_crypto::Ss58Codec, AccountId32}; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, GetStorage, PlainTipExtrinsicParams, SubmitAndWatch, XtStatus, + rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage, SubmitAndWatch, XtStatus, }; const MAX_BATCHED_TRANSACTION: u32 = 9; @@ -46,7 +46,7 @@ async fn main() { // Initialize api and set the signer (sender) that is used to sign the extrinsics. let alice = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); - let mut api = Api::<_, _, PlainTipExtrinsicParams, Runtime>::new(client).unwrap(); + let mut api = Api::<_, _, AssetTipExtrinsicParams, Runtime>::new(client).unwrap(); api.set_signer(alice); // Give a valid validator account address, given one is westend chain validator account. @@ -120,7 +120,7 @@ pub fn get_last_reward( api: &substrate_api_client::Api< sp_core::sr25519::Pair, JsonrpseeClient, - PlainTipExtrinsicParams, + AssetTipExtrinsicParams, Runtime, >, ) -> u32 { diff --git a/examples/examples/contract_instantiate_with_code.rs b/examples/examples/contract_instantiate_with_code.rs index e8669fdad..29c4530e0 100644 --- a/examples/examples/contract_instantiate_with_code.rs +++ b/examples/examples/contract_instantiate_with_code.rs @@ -19,7 +19,7 @@ use codec::{Decode, Encode}; use kitchensink_runtime::Runtime; use sp_keyring::AccountKeyring; use substrate_api_client::{ - rpc::JsonrpseeClient, AccountId, Api, PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch, + rpc::JsonrpseeClient, AccountId, Api, AssetTipExtrinsicParams, StaticEvent, SubmitAndWatch, SubscribeEvents, SubscribeFrameSystem, XtStatus, }; @@ -44,7 +44,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); // ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most // runtimes, the PlainTipExtrinsicParams needs to be used. - let mut api = Api::<_, _, PlainTipExtrinsicParams, Runtime>::new(client).unwrap(); + let mut api = Api::<_, _, AssetTipExtrinsicParams, Runtime>::new(client).unwrap(); api.set_signer(signer); println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap()); diff --git a/examples/examples/event_callback.rs b/examples/examples/event_callback.rs index 5c132e185..481512563 100644 --- a/examples/examples/event_callback.rs +++ b/examples/examples/event_callback.rs @@ -35,8 +35,7 @@ async fn main() { // Initialize the api. let client = JsonrpseeClient::with_default_url().unwrap(); - let api = - Api::, Runtime>::new(client).unwrap(); + let api = Api::<(), _, (), Runtime>::new(client).unwrap(); println!("Subscribe to events"); let mut subscription = api.subscribe_system_events().unwrap(); diff --git a/examples/examples/get_blocks.rs b/examples/examples/get_blocks.rs index deba27da3..c0eab41e0 100644 --- a/examples/examples/get_blocks.rs +++ b/examples/examples/get_blocks.rs @@ -29,8 +29,7 @@ async fn main() { // Initialize the api. let client = JsonrpseeClient::with_default_url().unwrap(); - let api = - Api::, Runtime>::new(client).unwrap(); + let api = Api::<(), _, (), Runtime>::new(client).unwrap(); println!("Genesis block: \n {:?} \n", api.get_block_by_num(Some(0)).unwrap()); diff --git a/examples/examples/get_storage.rs b/examples/examples/get_storage.rs index 35fffbb2c..222133f57 100644 --- a/examples/examples/get_storage.rs +++ b/examples/examples/get_storage.rs @@ -31,7 +31,7 @@ async fn main() { // Initialize the api. let client = JsonrpseeClient::with_default_url().unwrap(); - let mut api = Api::<_, _, PlainTipExtrinsicParams, Runtime>::new(client).unwrap(); + let mut api = Api::<_, _, (), Runtime>::new(client).unwrap(); // get some plain storage value let result: u128 = api.get_storage_value("Balances", "TotalIssuance", None).unwrap().unwrap(); diff --git a/examples/examples/print_metadata.rs b/examples/examples/print_metadata.rs index 081914b9c..fc6378520 100644 --- a/examples/examples/print_metadata.rs +++ b/examples/examples/print_metadata.rs @@ -26,8 +26,7 @@ async fn main() { // Initialize the api, which retrieves the metadata from the node upon initialization. let client = JsonrpseeClient::with_default_url().unwrap(); - let mut api = - Api::, Runtime>::new(client).unwrap(); + let mut api = Api::<(), _, (), Runtime>::new(client).unwrap(); let meta = api.metadata().clone(); diff --git a/primitives/src/extrinsic_params.rs b/primitives/src/extrinsic_params.rs index f99e29f89..0f1365f63 100644 --- a/primitives/src/extrinsic_params.rs +++ b/primitives/src/extrinsic_params.rs @@ -17,6 +17,7 @@ use codec::{Decode, Encode}; use core::{hash::Hash as HashTrait, marker::PhantomData}; +use sp_core::H256; use sp_runtime::{ generic::Era, traits::{BlakeTwo256, Hash}, @@ -291,3 +292,23 @@ impl From> for u128 { tip.tip } } + +/// Emtpy implementation in case no ExtrinsicParams are needed, such as unsigned extrinsics or getter calls. +impl ExtrinsicParams for () { + type OtherParams = (); + type SignedExtra = (); + type AdditionalSigned = (); + + fn new( + _spec_version: u32, + _transaction_version: u32, + _nonce: u32, + _genesis_hash: H256, + _other_params: Self::OtherParams, + ) -> Self { + } + + fn signed_extra(&self) -> Self::SignedExtra {} + + fn additional_signed(&self) -> Self::AdditionalSigned {} +} diff --git a/src/api/api_client.rs b/src/api/api_client.rs index fd358fb82..6b800818a 100644 --- a/src/api/api_client.rs +++ b/src/api/api_client.rs @@ -86,18 +86,20 @@ use sp_runtime::MultiSignature; pub struct Api where Runtime: FrameSystemConfig, + Params: ExtrinsicParams, { signer: Option, genesis_hash: Runtime::Hash, metadata: Metadata, runtime_version: RuntimeVersion, client: Client, - extrinsic_params_builder: Option, + extrinsic_params_builder: Option, } impl Api where Runtime: FrameSystemConfig, + Params: ExtrinsicParams, { /// Create a new api instance without any node interaction. pub fn new_offline( @@ -150,17 +152,9 @@ where pub fn client(&self) -> &Client { &self.client } -} -impl Api -where - Runtime: FrameSystemConfig, -{ /// Set the extrinscs param builder. - pub fn set_extrinsic_params_builder>( - &mut self, - extrinsic_params: Params::OtherParams, - ) { + pub fn set_extrinsic_params_builder(&mut self, extrinsic_params: Params::OtherParams) { self.extrinsic_params_builder = Some(extrinsic_params); }