-
Hugo Trentesaux authoredHugo Trentesaux authored
transfer.rs 1.93 KiB
use crate::*;
#[cfg(any(feature = "dev", feature = "gdev"))] // find how to get runtime calls
type Call = runtime::runtime_types::gdev_runtime::RuntimeCall;
type BalancesCall = runtime::runtime_types::pallet_balances::pallet::Call;
/// transfer balance to target
pub async fn transfer(
data: &Data,
balance: u64,
dest: AccountId,
keep_alive: bool,
) -> Result<(), subxt::Error> {
let progress = if keep_alive {
data.client()
.tx()
.sign_and_submit_then_watch(
&runtime::tx().balances().transfer(dest.into(), balance),
&PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(),
)
.await?
} else {
data.client()
.tx()
.sign_and_submit_then_watch(
&runtime::tx()
.balances()
.transfer_keep_alive(dest.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::balances::events::Transfer>()? {
println!("{e:?}");
}
Ok(())
}
/// transfer balance to multiple target
pub async fn transfer_multiple(
data: &Data,
amount: u64,
dests: Vec<AccountId>,
) -> Result<(), subxt::Error> {
// build the list of transactions from the destination accounts
let transactions: Vec<Call> = dests
.into_iter()
.map(|dest| {
Call::Balances(BalancesCall::transfer_keep_alive {
dest: dest.into(),
value: amount,
})
})
.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(())
}