diff --git a/src/commands/collective.rs b/src/commands/collective.rs index 5ca295e7958ec04e772c54edf256bd6d8081e6a9..cc7f10e5819506004c769bc56bacf3c83c67aa86 100644 --- a/src/commands/collective.rs +++ b/src/commands/collective.rs @@ -135,26 +135,14 @@ pub async fn technical_committee_vote( proposal_index: u32, vote: bool, ) -> Result<(), subxt::Error> { - let progress = data - .client() - .tx() - .sign_and_submit_then_watch( - &runtime::tx() - .technical_committee() - .vote(proposal_hash, proposal_index, vote), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - - if data.args.no_wait { - return Ok(()); - } - let events = track_progress(progress).await?; - - if let Some(e) = events.find_first::<runtime::technical_committee::events::Voted>()? { - println!("{e:?}"); - } - - Ok(()) + submit_call_and_look_event::< + runtime::technical_committee::events::Voted, + StaticTxPayload<runtime::technical_committee::calls::Vote>, + >( + data, + &runtime::tx() + .technical_committee() + .vote(proposal_hash, proposal_index, vote), + ) + .await } diff --git a/src/commands/oneshot.rs b/src/commands/oneshot.rs index a395f78bd3a006f810f5e607e323ec2948cc1c58..c4cf3c362941e21b0aea0b462bdde9b03cd5e8dc 100644 --- a/src/commands/oneshot.rs +++ b/src/commands/oneshot.rs @@ -176,46 +176,31 @@ pub async fn consume_oneshot_account_with_remaining( .fetch(&runtime::storage().system().number(), None) .await? .unwrap(); - let progress = client - .tx() - .sign_and_submit_then_watch( - &runtime::tx() - .oneshot_account() - .consume_oneshot_account_with_remaining( - number, - if dest_oneshot { - runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot( - dest.into(), - ) - } else { - runtime::runtime_types::pallet_oneshot_account::types::Account::Normal( - dest.into(), - ) - }, - if remaining_to_oneshot { - runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot( - remaining_to.into(), - ) - } else { - runtime::runtime_types::pallet_oneshot_account::types::Account::Normal( - remaining_to.into(), - ) - }, - balance, - ), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - if data.args.no_wait { - return Ok(()); - } - let events = track_progress(progress).await?; - if let Some(e) = - events.find_first::<runtime::oneshot_account::events::OneshotAccountConsumed>()? - { - println!("{e:?}"); - } - Ok(()) + let call = &runtime::tx() + .oneshot_account() + .consume_oneshot_account_with_remaining( + number, + if dest_oneshot { + runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(dest.into()) + } else { + runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into()) + }, + if remaining_to_oneshot { + runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot( + remaining_to.into(), + ) + } else { + runtime::runtime_types::pallet_oneshot_account::types::Account::Normal( + remaining_to.into(), + ) + }, + balance, + ); + + submit_call_and_look_event::< + runtime::oneshot_account::events::OneshotAccountConsumed, + StaticTxPayload<runtime::oneshot_account::calls::ConsumeOneshotAccountWithRemaining>, + >(data, call) + .await } diff --git a/src/commands/smith.rs b/src/commands/smith.rs index 8a69b7a727f52228d6749889473d12372091e85e..f7b25e21c12413cf85d7a30a7d4c783351a71f28 100644 --- a/src/commands/smith.rs +++ b/src/commands/smith.rs @@ -310,35 +310,21 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> { Ok(()) } -/// submit a certification and track progress +/// submit a smith certification and track progress pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> { - let progress = data - .client() - .tx() - .sign_and_submit_then_watch( - &runtime::tx() - .smith_cert() - .add_cert(data.idty_index(), receiver), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - + let progress = submit_call( + data, + &runtime::tx() + .smith_cert() + .add_cert(data.idty_index(), receiver), + ) + .await?; if data.args.no_wait { return Ok(()); } let events = track_progress(progress).await?; - // look for the expected event - let new_cert_event = events.find_first::<runtime::smith_cert::events::NewCert>()?; - let renew_cert_event = events.find_first::<runtime::smith_cert::events::RenewedCert>()?; - - if let Some(event) = new_cert_event { - println!("{event:?}"); - } - if let Some(event) = renew_cert_event { - println!("{event:?}"); - } - + look_event::<runtime::smith_cert::events::NewCert>(&events)?; + look_event::<runtime::smith_cert::events::RenewedCert>(&events)?; Ok(()) } diff --git a/src/commands/sudo.rs b/src/commands/sudo.rs index 9e5d56cf5ea18e3a38d641889ff4b372ce058116..7b7b5053687eb01b839ce08b5535a2ad0969e028 100644 --- a/src/commands/sudo.rs +++ b/src/commands/sudo.rs @@ -2,19 +2,9 @@ use crate::*; /// set sudo key pub async fn set_key(data: &Data, new_key: AccountId) -> Result<(), subxt::Error> { - let progress = data - .client() - .tx() - .sign_and_submit_then_watch( - &runtime::tx().sudo().set_key(new_key.into()), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - - if data.args.no_wait { - return Ok(()); - } - let _ = track_progress(progress).await?; // TODO - Ok(()) + submit_call_and_look_event::< + runtime::sudo::events::KeyChanged, + StaticTxPayload<runtime::sudo::calls::SetKey>, + >(data, &runtime::tx().sudo().set_key(new_key.into())) + .await } diff --git a/src/commands/transfer.rs b/src/commands/transfer.rs index c49512b89dc80b8acab25c1fa10a649fb7e57b87..555c05e7b428b76f75a848bbd153fe7887023feb 100644 --- a/src/commands/transfer.rs +++ b/src/commands/transfer.rs @@ -78,25 +78,10 @@ pub async fn transfer_multiple( }) }) .collect(); - // wrap these calls in a batch call - let progress = data - .client() - .tx() - .sign_and_submit_then_watch( - &runtime::tx().utility().batch(transactions), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - - if data.args.no_wait { - return Ok(()); - } - let events = track_progress(progress).await?; - // TODO all transfer - if let Some(e) = events.find_first::<runtime::balances::events::Transfer>()? { - println!("{e:?}"); - } - Ok(()) + submit_call_and_look_event::< + runtime::utility::events::BatchCompleted, + StaticTxPayload<runtime::utility::calls::Batch>, + >(data, &runtime::tx().utility().batch(transactions)) + .await } diff --git a/src/commands/ud.rs b/src/commands/ud.rs index bda66f03909c87cde64ae697a7da193ff74432c4..28d7ef4e13826a9d2c1f61a3479b2c0ee9ad8438 100644 --- a/src/commands/ud.rs +++ b/src/commands/ud.rs @@ -15,7 +15,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( // match subcommand match command { Subcommand::Claim => { - claim_ud(data).await?; + claim_ud(&data).await?; } }; @@ -23,24 +23,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( } /// claim universal dividend -pub async fn claim_ud(data: Data) -> Result<(), anyhow::Error> { - let progress = data - .client() - .tx() - .sign_and_submit_then_watch( - &runtime::tx().universal_dividend().claim_uds(), - &PairSigner::new(data.keypair()), - BaseExtrinsicParamsBuilder::new(), - ) - .await?; - - if data.args.no_wait { - return Ok(()); - } - let events = track_progress(progress).await?; - - if let Some(e) = events.find_first::<runtime::universal_dividend::events::UdsClaimed>()? { - println!("{e:?}"); - } - Ok(()) +pub async fn claim_ud(data: &Data) -> Result<(), subxt::Error> { + submit_call_and_look_event::< + runtime::universal_dividend::events::UdsClaimed, + StaticTxPayload<runtime::universal_dividend::calls::ClaimUds>, + >(data, &runtime::tx().universal_dividend().claim_uds()) + .await }