Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
haerdib committed Dec 19, 2023
1 parent c7c0e3c commit 9936212
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
39 changes: 33 additions & 6 deletions examples/examples/benchmark_bulk_xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use kitchensink_runtime::{AccountId, BalancesCall, RuntimeCall};
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_primitives::{
DefaultRuntimeConfig, ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic,
},
ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic},
rpc::JsonrpseeClient,
Api, SubmitExtrinsic,
};
Expand All @@ -30,15 +28,44 @@ use substrate_api_client::{
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.

// Define an extrinsic signer type which sets the generic types of the `GenericExtrinsicSigner`.
// This way, the types don't have to be reassigned with every usage of this type and makes
// the code better readable.
type ExtrinsicSigner = GenericExtrinsicSigner<AssetRuntimeConfig>;

// To access the ExtrinsicAddress type of the Signer, we need to do this via the trait `SignExtrinsic`.
// For better code readability, we define a simple type here and, at the same time, assign the
// AccountId type of the `SignExtrinsic` trait.
type ExtrinsicAddressOf<Signer> = <Signer as SignExtrinsic<AccountId>>::ExtrinsicAddress;

#[tokio::main]
async fn main() {
let alice_signer = AccountKeyring::Alice.pair();
env_logger::init();

// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).unwrap();
api.set_signer(GenericExtrinsicSigner::<DefaultRuntimeConfig>::new(alice_signer));
let mut api = Api::<AssetRuntimeConfig, _>::new(client).unwrap();
api.set_signer(signer.into());

let recipient: ExtrinsicAddressOf<ExtrinsicSigner> = AccountKeyring::Bob.to_account_id().into();
// We use a manual nonce input here, because otherwise the api retrieves the nonce via getter and needs
// to wait for the response of the node (and the actual execution of the previous extrinsic).
// But because we want to spam the node with extrinsic, we simple monotonically increase the nonce, without
// waiting for the response of the node.
let mut nonce = api.get_nonce().unwrap();
let first_nonce = nonce;
while nonce < first_nonce + 500 {
// Compose a balance extrinsic.
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: recipient.clone(),
value: 1_000_000,
});
let xt = api.compose_extrinsic_offline(call, nonce);

println!("Sending extrinsic with nonce {}", nonce);
let _tx_hash = api.submit_extrinsic(xt).unwrap();

nonce += 1;
}
}
3 changes: 1 addition & 2 deletions examples/examples/contract_instantiate_with_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/get_account_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 9936212

Please sign in to comment.