Skip to content
Snippets Groups Projects
Commit b33ba8c4 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

refac calls to use submit_call_and_look_event

parent 0ded4217
No related branches found
No related tags found
1 merge request!11refac call submission and event watch
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
...@@ -135,26 +135,14 @@ pub async fn technical_committee_vote( ...@@ -135,26 +135,14 @@ pub async fn technical_committee_vote(
proposal_index: u32, proposal_index: u32,
vote: bool, vote: bool,
) -> Result<(), subxt::Error> { ) -> Result<(), subxt::Error> {
let progress = data submit_call_and_look_event::<
.client() runtime::technical_committee::events::Voted,
.tx() StaticTxPayload<runtime::technical_committee::calls::Vote>,
.sign_and_submit_then_watch( >(
&runtime::tx() data,
.technical_committee() &runtime::tx()
.vote(proposal_hash, proposal_index, vote), .technical_committee()
&PairSigner::new(data.keypair()), .vote(proposal_hash, proposal_index, vote),
BaseExtrinsicParamsBuilder::new(), )
) .await
.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(())
} }
...@@ -176,46 +176,31 @@ pub async fn consume_oneshot_account_with_remaining( ...@@ -176,46 +176,31 @@ pub async fn consume_oneshot_account_with_remaining(
.fetch(&runtime::storage().system().number(), None) .fetch(&runtime::storage().system().number(), None)
.await? .await?
.unwrap(); .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 { let call = &runtime::tx()
return Ok(()); .oneshot_account()
} .consume_oneshot_account_with_remaining(
let events = track_progress(progress).await?; number,
if let Some(e) = if dest_oneshot {
events.find_first::<runtime::oneshot_account::events::OneshotAccountConsumed>()? runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(dest.into())
{ } else {
println!("{e:?}"); runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into())
} },
Ok(()) 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
} }
...@@ -310,35 +310,21 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> { ...@@ -310,35 +310,21 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
Ok(()) 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> { pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
let progress = data let progress = submit_call(
.client() data,
.tx() &runtime::tx()
.sign_and_submit_then_watch( .smith_cert()
&runtime::tx() .add_cert(data.idty_index(), receiver),
.smith_cert() )
.add_cert(data.idty_index(), receiver), .await?;
&PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
if data.args.no_wait { if data.args.no_wait {
return Ok(()); return Ok(());
} }
let events = track_progress(progress).await?; let events = track_progress(progress).await?;
// look for the expected event // look for the expected event
let new_cert_event = events.find_first::<runtime::smith_cert::events::NewCert>()?; look_event::<runtime::smith_cert::events::NewCert>(&events)?;
let renew_cert_event = events.find_first::<runtime::smith_cert::events::RenewedCert>()?; look_event::<runtime::smith_cert::events::RenewedCert>(&events)?;
if let Some(event) = new_cert_event {
println!("{event:?}");
}
if let Some(event) = renew_cert_event {
println!("{event:?}");
}
Ok(()) Ok(())
} }
...@@ -2,19 +2,9 @@ use crate::*; ...@@ -2,19 +2,9 @@ use crate::*;
/// set sudo key /// set sudo key
pub async fn set_key(data: &Data, new_key: AccountId) -> Result<(), subxt::Error> { pub async fn set_key(data: &Data, new_key: AccountId) -> Result<(), subxt::Error> {
let progress = data submit_call_and_look_event::<
.client() runtime::sudo::events::KeyChanged,
.tx() StaticTxPayload<runtime::sudo::calls::SetKey>,
.sign_and_submit_then_watch( >(data, &runtime::tx().sudo().set_key(new_key.into()))
&runtime::tx().sudo().set_key(new_key.into()), .await
&PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
if data.args.no_wait {
return Ok(());
}
let _ = track_progress(progress).await?; // TODO
Ok(())
} }
...@@ -78,25 +78,10 @@ pub async fn transfer_multiple( ...@@ -78,25 +78,10 @@ pub async fn transfer_multiple(
}) })
}) })
.collect(); .collect();
// wrap these calls in a batch call // wrap these calls in a batch call
let progress = data submit_call_and_look_event::<
.client() runtime::utility::events::BatchCompleted,
.tx() StaticTxPayload<runtime::utility::calls::Batch>,
.sign_and_submit_then_watch( >(data, &runtime::tx().utility().batch(transactions))
&runtime::tx().utility().batch(transactions), .await
&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(())
} }
...@@ -15,7 +15,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( ...@@ -15,7 +15,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
// match subcommand // match subcommand
match command { match command {
Subcommand::Claim => { 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<( ...@@ -23,24 +23,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
} }
/// claim universal dividend /// claim universal dividend
pub async fn claim_ud(data: Data) -> Result<(), anyhow::Error> { pub async fn claim_ud(data: &Data) -> Result<(), subxt::Error> {
let progress = data submit_call_and_look_event::<
.client() runtime::universal_dividend::events::UdsClaimed,
.tx() StaticTxPayload<runtime::universal_dividend::calls::ClaimUds>,
.sign_and_submit_then_watch( >(data, &runtime::tx().universal_dividend().claim_uds())
&runtime::tx().universal_dividend().claim_uds(), .await
&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(())
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment