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

WIP add claim_ud command

parent b8efc89d
Branches
Tags
1 merge request!7Big refacto
......@@ -10,3 +10,4 @@ pub mod runtime;
pub mod smith;
pub mod sudo;
pub mod transfer;
pub mod ud;
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
}
......@@ -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,
......
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(())
}
......@@ -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)?,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment