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
No related branches found
No related tags found
1 merge request!7Big refacto
...@@ -10,3 +10,4 @@ pub mod runtime; ...@@ -10,3 +10,4 @@ pub mod runtime;
pub mod smith; pub mod smith;
pub mod sudo; pub mod sudo;
pub mod transfer; pub mod transfer;
pub mod ud;
use crate::*; use crate::*;
use anyhow::Result; /// get balance
pub async fn get_balance(data: Data) -> Result<(), anyhow::Error> {
pub async fn get_balance(data: Data) -> Result<()> {
let account_id = data.address(); let account_id = data.address();
let account_info = get_account_info(data.client(), &account_id).await?; let account_info = get_account_info(data.client(), &account_id).await?;
if let Some(account_info) = account_info { if let Some(account_info) = account_info {
...@@ -16,12 +15,13 @@ pub async fn get_balance(data: Data) -> Result<()> { ...@@ -16,12 +15,13 @@ pub async fn get_balance(data: Data) -> Result<()> {
Ok(()) Ok(())
} }
/// get account info
pub async fn get_account_info( pub async fn get_account_info(
client: &Client, client: &Client,
account_id: &AccountId, account_id: &AccountId,
) -> Result<Option<AccountInfo>> { ) -> Result<Option<AccountInfo>, subxt::Error> {
Ok(client client
.storage() .storage()
.fetch(&runtime::storage().system().account(account_id), None) .fetch(&runtime::storage().system().account(account_id), None)
.await?) .await
} }
...@@ -7,7 +7,6 @@ use crate::runtime::runtime_types::sp_core::sr25519::Signature; ...@@ -7,7 +7,6 @@ use crate::runtime::runtime_types::sp_core::sr25519::Signature;
use crate::runtime::runtime_types::sp_runtime::MultiSignature; use crate::runtime::runtime_types::sp_runtime::MultiSignature;
use sp_core::{crypto::AccountId32, sr25519::Pair}; use sp_core::{crypto::AccountId32, sr25519::Pair};
use std::str::FromStr; use std::str::FromStr;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn get_identity( pub async fn get_identity(
data: &Data, 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::*; ...@@ -12,6 +12,8 @@ use data::*;
use keys::*; use keys::*;
use serde::Deserialize; use serde::Deserialize;
use sp_core::{sr25519::Pair, Pair as _, H256}; use sp_core::{sr25519::Pair, Pair as _, H256};
use subxt::blocks::ExtrinsicEvents;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner, TxStatus};
#[cfg(feature = "gdev")] #[cfg(feature = "gdev")]
#[subxt::subxt( #[subxt::subxt(
...@@ -99,9 +101,6 @@ pub struct Args { ...@@ -99,9 +101,6 @@ pub struct Args {
network: Option<String>, network: Option<String>,
} }
use subxt::blocks::ExtrinsicEvents;
use subxt::tx::TxStatus;
/// track progress of transaction on the network /// track progress of transaction on the network
/// until it is in block with success or failure /// until it is in block with success or failure
pub async fn track_progress( pub async fn track_progress(
...@@ -277,6 +276,9 @@ pub enum Subcommand { ...@@ -277,6 +276,9 @@ pub enum Subcommand {
RuntimeInfo, RuntimeInfo,
/// Check current block /// Check current block
CurrentBlock, CurrentBlock,
/// Universal Dividend subcommands
#[clap(subcommand)]
Ud(commands::ud::Subcommand),
/// Indexer subcommands /// Indexer subcommands
#[clap(subcommand)] #[clap(subcommand)]
Indexer(indexer::Subcommand), Indexer(indexer::Subcommand),
...@@ -600,6 +602,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -600,6 +602,7 @@ async fn main() -> Result<(), GcliError> {
.unwrap() .unwrap()
); );
} }
Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?,
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?,
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?, 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