From 724f7c3a701a7070d6eccdecc4d3636cf34c20de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bigna=20H=C3=A4rdi?= Date: Fri, 22 Dec 2023 13:59:09 +0100 Subject: [PATCH] Update WithExtrinsicParams to use ExtrinsicSigner (#698) * wWithExtrinsicParams now uses ExtrinsicSigner directly * simplify examples * fix clippy * fix clippy * add test * move test to cargo test * fix clippy * move test to chain atest * add comment --- examples/examples/benchmark_bulk_xt.rs | 2 +- examples/examples/check_extrinsic_events.rs | 4 ++-- examples/examples/contract_instantiate_with_code.rs | 5 ++--- examples/examples/custom_nonce.rs | 4 ++-- examples/examples/get_account_identity.rs | 4 ++-- examples/examples/get_storage.rs | 4 ++-- examples/examples/runtime_update_async.rs | 5 ++--- examples/examples/runtime_update_sync.rs | 5 ++--- examples/examples/staking_batch_payout.rs | 4 ++-- examples/examples/sudo.rs | 2 +- examples/examples/transfer_with_tungstenite_client.rs | 6 ++---- examples/examples/transfer_with_ws_client.rs | 8 +++----- primitives/src/config/mod.rs | 4 ++-- testing/examples/author_tests.rs | 2 +- testing/examples/chain_tests.rs | 10 +++++++--- testing/examples/dispatch_errors_tests.rs | 10 ++++------ testing/examples/events_tests.rs | 4 ++-- testing/examples/frame_system_tests.rs | 8 +++----- testing/examples/tungstenite_client_test.rs | 6 ++---- testing/examples/ws_client_test.rs | 8 +++----- 20 files changed, 47 insertions(+), 58 deletions(-) diff --git a/examples/examples/benchmark_bulk_xt.rs b/examples/examples/benchmark_bulk_xt.rs index b42156566..e0183ad05 100644 --- a/examples/examples/benchmark_bulk_xt.rs +++ b/examples/examples/benchmark_bulk_xt.rs @@ -46,7 +46,7 @@ async fn main() { let signer = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::new(signer)); + api.set_signer(signer.into()); let recipient: ExtrinsicAddressOf = AccountKeyring::Bob.to_account_id().into(); // We use a manual nonce input here, because otherwise the api retrieves the nonce via getter and needs diff --git a/examples/examples/check_extrinsic_events.rs b/examples/examples/check_extrinsic_events.rs index f9cf44ca6..3a4bdfcb7 100644 --- a/examples/examples/check_extrinsic_events.rs +++ b/examples/examples/check_extrinsic_events.rs @@ -16,7 +16,7 @@ use sp_keyring::AccountKeyring; use substrate_api_client::{ ac_node_api::EventDetails, - ac_primitives::{AssetRuntimeConfig, Config, ExtrinsicSigner}, + ac_primitives::{AssetRuntimeConfig, Config}, extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, GetAccountInformation, SubmitAndWatch, TransactionStatus, XtStatus, @@ -37,7 +37,7 @@ async fn main() { let alice_signer = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice_signer)); + api.set_signer(alice_signer.into()); let alice = AccountKeyring::Alice.to_account_id(); let balance_of_alice = api.get_account_data(&alice).unwrap().unwrap().free; diff --git a/examples/examples/contract_instantiate_with_code.rs b/examples/examples/contract_instantiate_with_code.rs index 7f017ab33..a4940716b 100644 --- a/examples/examples/contract_instantiate_with_code.rs +++ b/examples/examples/contract_instantiate_with_code.rs @@ -20,8 +20,7 @@ use kitchensink_runtime::AccountId; use sp_keyring::AccountKeyring; use substrate_api_client::{ ac_compose_macros::primitives::AssetRuntimeConfig, ac_node_api::StaticEvent, - ac_primitives::ExtrinsicSigner, extrinsic::ContractsExtrinsics, rpc::JsonrpseeClient, Api, - SubmitAndWatch, XtStatus, + extrinsic::ContractsExtrinsics, rpc::JsonrpseeClient, Api, SubmitAndWatch, XtStatus, }; // To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet. @@ -49,7 +48,7 @@ async fn main() { let signer = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::<_>::new(signer)); + api.set_signer(signer.into()); println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap()); diff --git a/examples/examples/custom_nonce.rs b/examples/examples/custom_nonce.rs index 546b80e73..97979a3b6 100644 --- a/examples/examples/custom_nonce.rs +++ b/examples/examples/custom_nonce.rs @@ -20,7 +20,7 @@ use kitchensink_runtime::{BalancesCall, RuntimeCall}; use sp_keyring::AccountKeyring; use sp_runtime::{generic::Era, MultiAddress}; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner, GenericAdditionalParams}, + ac_primitives::{AssetRuntimeConfig, GenericAdditionalParams}, rpc::JsonrpseeClient, Api, Error, GetChainInfo, SubmitAndWatch, UnexpectedTxStatus, XtStatus, }; @@ -38,7 +38,7 @@ async fn main() { let signer = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(signer)); + api.set_signer(signer.into()); // Information for Era for mortal transactions. let last_finalized_header_hash = api.get_finalized_head().unwrap().unwrap(); diff --git a/examples/examples/get_account_identity.rs b/examples/examples/get_account_identity.rs index 473c672dd..b57ebe062 100644 --- a/examples/examples/get_account_identity.rs +++ b/examples/examples/get_account_identity.rs @@ -22,7 +22,7 @@ use sp_core::{crypto::Pair, H256}; use sp_keyring::AccountKeyring; use substrate_api_client::{ ac_compose_macros::compose_extrinsic, - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner, UncheckedExtrinsicV4}, + ac_primitives::{AssetRuntimeConfig, UncheckedExtrinsicV4}, rpc::JsonrpseeClient, Api, GetStorage, SubmitAndWatch, XtStatus, }; @@ -46,7 +46,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); let signer = AccountKeyring::Alice.pair(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(signer.clone())); + api.set_signer(signer.clone().into()); // Fill Identity storage. let info = IdentityInfo:: { diff --git a/examples/examples/get_storage.rs b/examples/examples/get_storage.rs index 0cb715f0a..eb02737dc 100644 --- a/examples/examples/get_storage.rs +++ b/examples/examples/get_storage.rs @@ -20,7 +20,7 @@ use kitchensink_runtime::AccountId; use pallet_staking::Exposure; use sp_keyring::AccountKeyring; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, Config, ExtrinsicSigner}, + ac_primitives::{AssetRuntimeConfig, Config}, rpc::JsonrpseeClient, Api, GetAccountInformation, GetStorage, }; @@ -66,7 +66,7 @@ async fn main() { // get Alice's AccountNonce with api.get_nonce() let signer = AccountKeyring::Alice.pair(); - api.set_signer(ExtrinsicSigner::<_>::new(signer)); + api.set_signer(signer.into()); println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap()); println!( diff --git a/examples/examples/runtime_update_async.rs b/examples/examples/runtime_update_async.rs index 4de20e52f..3d313abfa 100644 --- a/examples/examples/runtime_update_async.rs +++ b/examples/examples/runtime_update_async.rs @@ -16,7 +16,7 @@ use sp_keyring::AccountKeyring; use sp_weights::Weight; use substrate_api_client::{ ac_compose_macros::{compose_call, compose_extrinsic}, - ac_primitives::{AssetRuntimeConfig, Config, ExtrinsicSigner as GenericExtrinsicSigner}, + ac_primitives::{AssetRuntimeConfig, Config}, api_client::UpdateRuntime, rpc::JsonrpseeClient, rpc_api::RuntimeUpdateDetector, @@ -25,7 +25,6 @@ use substrate_api_client::{ use tokio::select; use tokio_util::sync::CancellationToken; -type ExtrinsicSigner = GenericExtrinsicSigner; type Hash = ::Hash; #[cfg(feature = "sync-examples")] @@ -64,7 +63,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).await.unwrap(); let sudoer = AccountKeyring::Alice.pair(); - api.set_signer(ExtrinsicSigner::new(sudoer)); + api.set_signer(sudoer.into()); let subscription = api.subscribe_events().await.unwrap(); let mut update_detector: RuntimeUpdateDetector = diff --git a/examples/examples/runtime_update_sync.rs b/examples/examples/runtime_update_sync.rs index b9b26285b..c02e13cdc 100644 --- a/examples/examples/runtime_update_sync.rs +++ b/examples/examples/runtime_update_sync.rs @@ -21,14 +21,13 @@ use sp_weights::Weight; use std::{sync::Arc, thread}; use substrate_api_client::{ ac_compose_macros::{compose_call, compose_extrinsic}, - ac_primitives::{AssetRuntimeConfig, Config, ExtrinsicSigner as GenericExtrinsicSigner}, + ac_primitives::{AssetRuntimeConfig, Config}, api_client::UpdateRuntime, rpc::JsonrpseeClient, rpc_api::RuntimeUpdateDetector, Api, SubmitAndWatch, SubscribeEvents, XtStatus, }; -type ExtrinsicSigner = GenericExtrinsicSigner; type Hash = ::Hash; #[cfg(not(feature = "sync-examples"))] @@ -65,7 +64,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); let sudoer = AccountKeyring::Alice.pair(); - api.set_signer(ExtrinsicSigner::new(sudoer)); + api.set_signer(sudoer.into()); let subscription = api.subscribe_events().unwrap(); let cancellation = Arc::new(AtomicBool::new(false)); diff --git a/examples/examples/staking_batch_payout.rs b/examples/examples/staking_batch_payout.rs index e66c2787f..1c11988b2 100644 --- a/examples/examples/staking_batch_payout.rs +++ b/examples/examples/staking_batch_payout.rs @@ -16,7 +16,7 @@ use pallet_staking::{ActiveEraInfo, Exposure}; use sp_keyring::AccountKeyring; use sp_runtime::{app_crypto::Ss58Codec, AccountId32}; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, + ac_primitives::AssetRuntimeConfig, extrinsic::{StakingExtrinsics, UtilityExtrinsics}, rpc::JsonrpseeClient, Api, GetStorage, SubmitAndWatch, XtStatus, @@ -55,7 +55,7 @@ async fn main() { let alice = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice)); + api.set_signer(alice.into()); // Give a valid validator account address. In the kitchinsink runtime, this is Alice. let validator_account = AccountKeyring::Alice.to_account_id(); diff --git a/examples/examples/sudo.rs b/examples/examples/sudo.rs index 850ec65f6..43eb1a13f 100644 --- a/examples/examples/sudo.rs +++ b/examples/examples/sudo.rs @@ -52,7 +52,7 @@ async fn main() { let sudoer = AccountKeyring::Alice.pair(); let client = JsonrpseeClient::with_default_url().unwrap(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::new(sudoer)); + api.set_signer(sudoer.into()); // Set the recipient of newly issued funds. let recipient = AccountKeyring::Bob.to_account_id(); diff --git a/examples/examples/transfer_with_tungstenite_client.rs b/examples/examples/transfer_with_tungstenite_client.rs index 2fefa986c..58e10a405 100755 --- a/examples/examples/transfer_with_tungstenite_client.rs +++ b/examples/examples/transfer_with_tungstenite_client.rs @@ -21,9 +21,7 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - extrinsic::BalancesExtrinsics, - rpc::TungsteniteRpcClient, + ac_primitives::AssetRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::TungsteniteRpcClient, Api, GetAccountInformation, SubmitAndWatch, XtStatus, }; @@ -46,7 +44,7 @@ fn main() { // Initialize api and set the signer (sender) that is used to sign the extrinsics. let client = TungsteniteRpcClient::with_default_url(100); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice.clone())); + api.set_signer(alice.clone().into()); // Retrieve bobs current balance. let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") diff --git a/examples/examples/transfer_with_ws_client.rs b/examples/examples/transfer_with_ws_client.rs index 2adb39bbf..718ebd635 100755 --- a/examples/examples/transfer_with_ws_client.rs +++ b/examples/examples/transfer_with_ws_client.rs @@ -21,10 +21,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - extrinsic::BalancesExtrinsics, - rpc::WsRpcClient, - Api, GetAccountInformation, SubmitAndWatch, XtStatus, + ac_primitives::AssetRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::WsRpcClient, Api, + GetAccountInformation, SubmitAndWatch, XtStatus, }; // To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet. @@ -46,7 +44,7 @@ fn main() { // Initialize api and set the signer (sender) that is used to sign the extrinsics. let client = WsRpcClient::with_default_url(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice.clone())); + api.set_signer(alice.clone().into()); // Retrieve bobs current balance. let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") diff --git a/primitives/src/config/mod.rs b/primitives/src/config/mod.rs index cc1de2eef..c630c6766 100644 --- a/primitives/src/config/mod.rs +++ b/primitives/src/config/mod.rs @@ -20,7 +20,7 @@ use sp_runtime::traits::{ MaybeSerializeDeserialize, }; -use crate::{extrinsic_params, SignExtrinsic}; +use crate::{extrinsic_params, ExtrinsicSigner, SignExtrinsic}; pub use asset_runtime_config::*; pub use default_runtime_config::*; @@ -160,7 +160,7 @@ impl> Config type AccountData = T::AccountData; type ExtrinsicParams = E; type CryptoKey = T::CryptoKey; - type ExtrinsicSigner = T::ExtrinsicSigner; + type ExtrinsicSigner = ExtrinsicSigner; type Block = T::Block; type Balance = T::Balance; type ContractCurrency = T::ContractCurrency; diff --git a/testing/examples/author_tests.rs b/testing/examples/author_tests.rs index 87168f662..4d25fddca 100644 --- a/testing/examples/author_tests.rs +++ b/testing/examples/author_tests.rs @@ -40,7 +40,7 @@ async fn main() { let alice_pair = AccountKeyring::Alice.pair(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::new(alice_pair)); + api.set_signer(alice_pair.into()); let bob: ExtrinsicAddressOf = AccountKeyring::Bob.to_account_id().into(); diff --git a/testing/examples/chain_tests.rs b/testing/examples/chain_tests.rs index 3cf6cd591..4e12dba9c 100644 --- a/testing/examples/chain_tests.rs +++ b/testing/examples/chain_tests.rs @@ -13,10 +13,12 @@ limitations under the License. */ -//! Tests for the chain rpc interface functions. +//! Tests for the chain rpc interface functions, including testing the DefaultRuntimeConfig +//! and Signer generation for the DefaultRuntimeConfig. +use sp_keyring::AccountKeyring; use substrate_api_client::{ - ac_primitives::AssetRuntimeConfig, + ac_primitives::{DefaultRuntimeConfig, ExtrinsicSigner}, rpc::{HandleSubscription, JsonrpseeClient}, Api, GetChainInfo, SubscribeChain, }; @@ -25,7 +27,9 @@ use substrate_api_client::{ async fn main() { // Setup let client = JsonrpseeClient::with_default_url().unwrap(); - let api = Api::::new(client).unwrap(); + let mut api = Api::::new(client).unwrap(); + let signer = AccountKeyring::Alice.pair(); + api.set_signer(ExtrinsicSigner::::new(signer)); // GetChainInfo let finalized_header_hash = api.get_finalized_head().unwrap().unwrap(); diff --git a/testing/examples/dispatch_errors_tests.rs b/testing/examples/dispatch_errors_tests.rs index bb3201161..6700441aa 100644 --- a/testing/examples/dispatch_errors_tests.rs +++ b/testing/examples/dispatch_errors_tests.rs @@ -18,10 +18,8 @@ use sp_keyring::AccountKeyring; use sp_runtime::MultiAddress; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - extrinsic::BalancesExtrinsics, - rpc::JsonrpseeClient, - Api, GetAccountInformation, SubmitAndWatch, XtStatus, + ac_primitives::AssetRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, + GetAccountInformation, SubmitAndWatch, XtStatus, }; #[tokio::main] @@ -45,7 +43,7 @@ async fn main() { println!("[+] One's Free Balance is {}\n", balance_of_one); //BadOrigin - api.set_signer(ExtrinsicSigner::::new(bob_signer)); + api.set_signer(bob_signer.into()); //Can only be called by root let xt = api.balance_force_set_balance(MultiAddress::Id(alice.clone()), 10); @@ -55,7 +53,7 @@ async fn main() { println!("[+] BadOrigin error: Bob can't force set balance"); //BelowMinimum - api.set_signer(ExtrinsicSigner::::new(alice_signer)); + api.set_signer(alice_signer.into()); let xt = api.balance_transfer_allow_death(MultiAddress::Id(one.clone()), 999999); let result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock); assert!(result.is_err()); diff --git a/testing/examples/events_tests.rs b/testing/examples/events_tests.rs index de8db04a8..9debcc6c5 100644 --- a/testing/examples/events_tests.rs +++ b/testing/examples/events_tests.rs @@ -21,7 +21,7 @@ use kitchensink_runtime::RuntimeEvent; use sp_keyring::AccountKeyring; use substrate_api_client::{ ac_node_api::{EventDetails, StaticEvent}, - ac_primitives::{AssetRuntimeConfig, Config, ExtrinsicSigner}, + ac_primitives::{AssetRuntimeConfig, Config}, extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, FetchEvents, GetChainInfo, SubmitAndWatch, SubscribeEvents, XtStatus, @@ -46,7 +46,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); let alice_pair = AccountKeyring::Alice.pair(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice_pair)); + api.set_signer(alice_pair.into()); let bob = AccountKeyring::Bob.to_account_id(); diff --git a/testing/examples/frame_system_tests.rs b/testing/examples/frame_system_tests.rs index 32f5a4ec9..3870b885f 100644 --- a/testing/examples/frame_system_tests.rs +++ b/testing/examples/frame_system_tests.rs @@ -19,10 +19,8 @@ use codec::Decode; use frame_support::dispatch::DispatchInfo; use sp_keyring::AccountKeyring; use substrate_api_client::{ - ac_node_api::StaticEvent, - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - rpc::JsonrpseeClient, - Api, GetAccountInformation, SystemApi, + ac_node_api::StaticEvent, ac_primitives::AssetRuntimeConfig, rpc::JsonrpseeClient, Api, + GetAccountInformation, SystemApi, }; /// Check out frame_system::Event::ExtrinsicSuccess: @@ -42,7 +40,7 @@ async fn main() { let client = JsonrpseeClient::with_default_url().unwrap(); let alice_pair = AccountKeyring::Alice.pair(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::new(alice_pair)); + api.set_signer(alice_pair.into()); let alice = AccountKeyring::Alice.to_account_id(); diff --git a/testing/examples/tungstenite_client_test.rs b/testing/examples/tungstenite_client_test.rs index 8d4694ee6..ecfd620a0 100755 --- a/testing/examples/tungstenite_client_test.rs +++ b/testing/examples/tungstenite_client_test.rs @@ -19,9 +19,7 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - extrinsic::BalancesExtrinsics, - rpc::TungsteniteRpcClient, + ac_primitives::AssetRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::TungsteniteRpcClient, Api, GetAccountInformation, SubmitAndWatch, XtStatus, }; @@ -34,7 +32,7 @@ fn main() { .unwrap(); let client = TungsteniteRpcClient::with_default_url(100); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice.clone())); + api.set_signer(alice.clone().into()); let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") .unwrap(); diff --git a/testing/examples/ws_client_test.rs b/testing/examples/ws_client_test.rs index 10dbd0866..8c33662d5 100755 --- a/testing/examples/ws_client_test.rs +++ b/testing/examples/ws_client_test.rs @@ -19,10 +19,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, - extrinsic::BalancesExtrinsics, - rpc::WsRpcClient, - Api, GetAccountInformation, SubmitAndWatch, XtStatus, + ac_primitives::AssetRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::WsRpcClient, Api, + GetAccountInformation, SubmitAndWatch, XtStatus, }; fn main() { @@ -34,7 +32,7 @@ fn main() { .unwrap(); let client = WsRpcClient::with_default_url(); let mut api = Api::::new(client).unwrap(); - api.set_signer(ExtrinsicSigner::::new(alice.clone())); + api.set_signer(alice.clone().into()); let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") .unwrap();