diff --git a/src/commands.rs b/src/commands.rs index ea2a9620692d730315bb4f1bd1ca580f1e172042..1384ca8596057e27f2f857166830803c627ab4c6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -10,3 +10,4 @@ pub mod runtime; pub mod smith; pub mod sudo; pub mod transfer; +pub mod ud; diff --git a/src/commands/account.rs b/src/commands/account.rs index 3bad919407e37e81730eaae3e2e9168517c0d3e3..101e088a91d2c05e68d2fee63217f20ce00cc986 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -1,8 +1,7 @@ use crate::*; -use anyhow::Result; - -pub async fn get_balance(data: Data) -> Result<()> { +/// get balance +pub async fn get_balance(data: Data) -> Result<(), anyhow::Error> { let account_id = data.address(); let account_info = get_account_info(data.client(), &account_id).await?; if let Some(account_info) = account_info { @@ -16,12 +15,13 @@ pub async fn get_balance(data: Data) -> Result<()> { Ok(()) } +/// get account info pub async fn get_account_info( client: &Client, account_id: &AccountId, -) -> Result<Option<AccountInfo>> { - Ok(client +) -> Result<Option<AccountInfo>, subxt::Error> { + client .storage() .fetch(&runtime::storage().system().account(account_id), None) - .await?) + .await } diff --git a/src/commands/identity.rs b/src/commands/identity.rs index 0a3a4308b3049eb68c83391ae17ff8191cdc78ac..efa5c4370824da72b0ead6f7f1c9262908f471df 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -7,7 +7,6 @@ use crate::runtime::runtime_types::sp_core::sr25519::Signature; use crate::runtime::runtime_types::sp_runtime::MultiSignature; use sp_core::{crypto::AccountId32, sr25519::Pair}; use std::str::FromStr; -use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; pub async fn get_identity( data: &Data, diff --git a/src/commands/ud.rs b/src/commands/ud.rs new file mode 100644 index 0000000000000000000000000000000000000000..4f6fc134929af4cba9b4cafd80de6282731fad9a --- /dev/null +++ b/src/commands/ud.rs @@ -0,0 +1,42 @@ +use crate::*; + +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?; + + let events = track_progress(progress).await?; + + if let Some(e) = events.find_first::<runtime::universal_dividend::events::UdsClaimed>()? { + println!("{e:?}"); + } + Ok(()) +} + +#[derive(Clone, Default, Debug, clap::Parser)] +pub enum Subcommand { + #[default] + /// Claim uds + ClaimUds, +} + +/// handle ud commands +pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { + // build indexer because it is needed for all subcommands + let mut data = data.build_client().await?; + // match subcommand + match command { + Subcommand::ClaimUds => { + data = data.build_keypair(); + claim_ud(data).await?; + } + }; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 9d1687270cc7b7291d80212fe1f3a38ba3370305..c069b16743b635cfa8eb859e67168f075590bd45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,8 @@ use data::*; use keys::*; use serde::Deserialize; use sp_core::{sr25519::Pair, Pair as _, H256}; +use subxt::blocks::ExtrinsicEvents; +use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner, TxStatus}; #[cfg(feature = "gdev")] #[subxt::subxt( @@ -99,9 +101,6 @@ pub struct Args { network: Option<String>, } -use subxt::blocks::ExtrinsicEvents; -use subxt::tx::TxStatus; - /// track progress of transaction on the network /// until it is in block with success or failure pub async fn track_progress( @@ -277,6 +276,9 @@ pub enum Subcommand { RuntimeInfo, /// Check current block CurrentBlock, + /// Universal Dividend subcommands + #[clap(subcommand)] + Ud(commands::ud::Subcommand), /// Indexer subcommands #[clap(subcommand)] Indexer(indexer::Subcommand), @@ -600,6 +602,7 @@ async fn main() -> Result<(), GcliError> { .unwrap() ); } + Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?, Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?, }