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

WIP refac argument parsing

parent ba2e3165
No related branches found
No related tags found
1 merge request!7Big refacto
use crate::indexer::*;
use crate::*; use crate::*;
use anyhow::Result; use anyhow::Result;
use sp_core::{sr25519::Pair, H256}; use sp_core::{sr25519::Pair, H256};
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn technical_committee_members(client: Client, args: &Args) -> Result<()> { pub async fn technical_committee_members(data: &Data) -> Result<()> {
let client = data.client();
let indexer = data.indexer.clone();
let parent_hash = client let parent_hash = client
.storage() .storage()
.fetch(&runtime::storage().system().parent_hash(), None) .fetch(&runtime::storage().system().parent_hash(), None)
.await? .await?
.unwrap(); .unwrap();
let gql_client = reqwest::Client::builder()
.user_agent("gcli/0.1.0")
.build()?;
let indexer = if args.no_indexer {
None
} else {
Some(Indexer {
gql_client,
gql_url: args.indexer.clone(),
})
};
for account_id in client for account_id in client
.storage() .storage()
.fetch( .fetch(
...@@ -64,7 +53,7 @@ pub async fn technical_committee_members(client: Client, args: &Args) -> Result< ...@@ -64,7 +53,7 @@ pub async fn technical_committee_members(client: Client, args: &Args) -> Result<
// TODO: // TODO:
// * better formatting (format pubkeys to SS58 and add usernames) // * better formatting (format pubkeys to SS58 and add usernames)
// * display proposals indices // * display proposals indices
pub async fn technical_committee_proposals(client: Client) -> Result<()> { pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
let parent_hash = client let parent_hash = client
.storage() .storage()
.fetch(&runtime::storage().system().parent_hash(), None) .fetch(&runtime::storage().system().parent_hash(), None)
...@@ -92,7 +81,7 @@ pub async fn technical_committee_proposals(client: Client) -> Result<()> { ...@@ -92,7 +81,7 @@ pub async fn technical_committee_proposals(client: Client) -> Result<()> {
pub async fn technical_committee_vote( pub async fn technical_committee_vote(
pair: Pair, pair: Pair,
client: Client, client: &Client,
proposal_hash: H256, proposal_hash: H256,
proposal_index: u32, proposal_index: u32,
vote: bool, vote: bool,
......
use crate::indexer::*;
use crate::*; use crate::*;
use anyhow::Result; use anyhow::Result;
use futures::join; use futures::join;
use std::collections::BTreeMap; use std::collections::BTreeMap;
pub async fn monitor_expirations( pub async fn monitor_expirations(data: &Data, blocks: u32, sessions: u32) -> Result<()> {
client: Client, let client = data.client();
blocks: u32, let indexer = data.indexer.clone();
sessions: u32,
args: &Args,
) -> Result<()> {
let gql_client = reqwest::Client::builder()
.user_agent("gcli/0.1.0")
.build()?;
let parent_hash = client let parent_hash = client
.storage() .storage()
...@@ -36,17 +29,7 @@ pub async fn monitor_expirations( ...@@ -36,17 +29,7 @@ pub async fn monitor_expirations(
let end_block = current_block + blocks; let end_block = current_block + blocks;
let end_session = current_session + sessions; let end_session = current_session + sessions;
let mut identity_cache = cache::IdentityCache::new( let mut identity_cache = cache::IdentityCache::new(client.clone(), indexer);
client.clone(),
if args.no_indexer {
None
} else {
Some(Indexer {
gql_client,
gql_url: args.indexer.clone(),
})
},
);
// Rotate keys // Rotate keys
let mut must_rotate_keys_before_iter = client let mut must_rotate_keys_before_iter = client
......
use crate::indexer::*;
use crate::*; use crate::*;
use crate::commands::revocation::generate_revoc_doc; use crate::commands::revocation::generate_revoc_doc;
...@@ -12,23 +11,13 @@ use std::str::FromStr; ...@@ -12,23 +11,13 @@ use std::str::FromStr;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn get_identity( pub async fn get_identity(
client: &Client, data: &Data,
mut account_id: Option<AccountId32>, mut account_id: Option<AccountId32>,
mut identity_id: Option<u32>, mut identity_id: Option<u32>,
mut username: Option<String>, mut username: Option<String>,
args: &Args,
) -> Result<()> { ) -> Result<()> {
// build indexer if not disabled let client = data.client();
let indexer = if args.no_indexer { let indexer = data.indexer.clone();
None
} else {
Some(Indexer {
gql_client: reqwest::Client::builder()
.user_agent("gcli/0.1.0")
.build()?,
gql_url: args.indexer.clone(),
})
};
// fetch missing information // fetch missing information
match (&account_id, identity_id, &username) { match (&account_id, identity_id, &username) {
......
...@@ -9,7 +9,7 @@ use subxt::{ ...@@ -9,7 +9,7 @@ use subxt::{
pub async fn repart( pub async fn repart(
pair: Pair, pair: Pair,
client: Client, client: &Client,
target: u32, target: u32,
actual_repart: Option<u32>, actual_repart: Option<u32>,
) -> Result<()> { ) -> Result<()> {
...@@ -48,7 +48,7 @@ pub async fn repart( ...@@ -48,7 +48,7 @@ pub async fn repart(
Ok(()) Ok(())
} }
pub async fn spam_roll(pair: Pair, client: Client, actual_repart: usize) -> Result<()> { pub async fn spam_roll(pair: Pair, client: &Client, actual_repart: usize) -> Result<()> {
let mut nonce = 0; let mut nonce = 0;
let mut pairs = Vec::<(PairSigner<Runtime, Pair>, AccountId32)>::with_capacity(actual_repart); let mut pairs = Vec::<(PairSigner<Runtime, Pair>, AccountId32)>::with_capacity(actual_repart);
for i in 0..actual_repart { for i in 0..actual_repart {
......
...@@ -6,7 +6,7 @@ use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; ...@@ -6,7 +6,7 @@ use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn create_oneshot_account( pub async fn create_oneshot_account(
pair: Pair, pair: Pair,
client: Client, client: &Client,
balance: u64, balance: u64,
dest: AccountId32, dest: AccountId32,
) -> Result<()> { ) -> Result<()> {
...@@ -26,7 +26,7 @@ pub async fn create_oneshot_account( ...@@ -26,7 +26,7 @@ pub async fn create_oneshot_account(
pub async fn consume_oneshot_account( pub async fn consume_oneshot_account(
pair: Pair, pair: Pair,
client: Client, client: &Client,
dest: AccountId32, dest: AccountId32,
dest_oneshot: bool, dest_oneshot: bool,
) -> Result<()> { ) -> Result<()> {
...@@ -60,7 +60,7 @@ pub async fn consume_oneshot_account( ...@@ -60,7 +60,7 @@ pub async fn consume_oneshot_account(
pub async fn consume_oneshot_account_with_remaining( pub async fn consume_oneshot_account_with_remaining(
pair: Pair, pair: Pair,
client: Client, client: &Client,
balance: u64, balance: u64,
dest: AccountId32, dest: AccountId32,
dest_oneshot: bool, dest_oneshot: bool,
...@@ -107,7 +107,7 @@ pub async fn consume_oneshot_account_with_remaining( ...@@ -107,7 +107,7 @@ pub async fn consume_oneshot_account_with_remaining(
Ok(()) Ok(())
} }
pub async fn oneshot_account_balance(client: Client, account: AccountId32) -> Result<()> { pub async fn oneshot_account_balance(client: &Client, account: AccountId32) -> Result<()> {
log::info!( log::info!(
"{}", "{}",
client client
......
use crate::indexer::Indexer;
use crate::*; use crate::*;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
...@@ -18,7 +17,11 @@ pub async fn rotate_keys(client: &Client) -> Result<SessionKeys> { ...@@ -18,7 +17,11 @@ pub async fn rotate_keys(client: &Client) -> Result<SessionKeys> {
.map_err(|e| anyhow!("Session keys have wrong length: {:?}", e)) .map_err(|e| anyhow!("Session keys have wrong length: {:?}", e))
} }
pub async fn set_session_keys(pair: Pair, client: Client, session_keys: SessionKeys) -> Result<()> { pub async fn set_session_keys(
pair: Pair,
client: &Client,
session_keys: SessionKeys,
) -> Result<()> {
client client
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
...@@ -33,12 +36,12 @@ pub async fn set_session_keys(pair: Pair, client: Client, session_keys: SessionK ...@@ -33,12 +36,12 @@ pub async fn set_session_keys(pair: Pair, client: Client, session_keys: SessionK
Ok(()) Ok(())
} }
pub async fn update_session_keys(pair: Pair, client: Client) -> Result<()> { pub async fn update_session_keys(pair: Pair, client: &Client) -> Result<()> {
let session_keys = rotate_keys(&client).await?; let session_keys = rotate_keys(&client).await?;
set_session_keys(pair, client, session_keys).await set_session_keys(pair, client, session_keys).await
} }
pub async fn go_online(pair: Pair, client: Client) -> Result<()> { pub async fn go_online(pair: Pair, client: &Client) -> Result<()> {
if client if client
.storage() .storage()
.fetch( .fetch(
...@@ -65,7 +68,7 @@ pub async fn go_online(pair: Pair, client: Client) -> Result<()> { ...@@ -65,7 +68,7 @@ pub async fn go_online(pair: Pair, client: Client) -> Result<()> {
Ok(()) Ok(())
} }
pub async fn go_offline(pair: Pair, client: Client) -> Result<()> { pub async fn go_offline(pair: Pair, client: &Client) -> Result<()> {
client client
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
...@@ -78,7 +81,10 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> { ...@@ -78,7 +81,10 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> {
Ok(()) Ok(())
} }
pub async fn online(client: Client, args: &Args) -> Result<()> { pub async fn online(data: &Data) -> Result<()> {
let client = data.client();
let indexer = data.indexer.clone();
let parent_hash = client let parent_hash = client
.clone() .clone()
.storage() .storage()
...@@ -86,21 +92,7 @@ pub async fn online(client: Client, args: &Args) -> Result<()> { ...@@ -86,21 +92,7 @@ pub async fn online(client: Client, args: &Args) -> Result<()> {
.await? .await?
.unwrap(); .unwrap();
let gql_client = reqwest::Client::builder() let mut identity_cache = cache::IdentityCache::new(client.clone(), indexer);
.user_agent("gcli/0.1.0")
.build()?;
let mut identity_cache = cache::IdentityCache::new(
client.clone(),
if args.no_indexer {
None
} else {
Some(Indexer {
gql_client,
gql_url: args.indexer.clone(),
})
},
);
let online_authorities = client let online_authorities = client
.storage() .storage()
......
...@@ -10,7 +10,7 @@ type BalancesCall = runtime::runtime_types::pallet_balances::pallet::Call; ...@@ -10,7 +10,7 @@ type BalancesCall = runtime::runtime_types::pallet_balances::pallet::Call;
pub async fn transfer( pub async fn transfer(
pair: Pair, pair: Pair,
client: Client, client: &Client,
balance: u64, balance: u64,
dest: AccountId32, dest: AccountId32,
keep_alive: bool, keep_alive: bool,
...@@ -42,7 +42,7 @@ pub async fn transfer( ...@@ -42,7 +42,7 @@ pub async fn transfer(
pub async fn transfer_multiple( pub async fn transfer_multiple(
pair: Pair, pair: Pair,
client: Client, client: &Client,
amount: u64, amount: u64,
dests: Vec<AccountId32>, dests: Vec<AccountId32>,
) -> Result<()> { ) -> Result<()> {
......
...@@ -5,8 +5,8 @@ const APP_NAME: &str = "gcli"; ...@@ -5,8 +5,8 @@ const APP_NAME: &str = "gcli";
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Config { pub struct Config {
duniter_endpoint: String, pub duniter_endpoint: String,
indexer_endpoint: String, pub indexer_endpoint: String,
} }
impl std::default::Default for Config { impl std::default::Default for Config {
...@@ -47,7 +47,10 @@ pub fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { ...@@ -47,7 +47,10 @@ pub fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
// match subcommand // match subcommand
match command { match command {
Subcommand::Where => { Subcommand::Where => {
println!("{}", confy::get_configuration_file_path(APP_NAME, None)?.display()); println!(
"{}",
confy::get_configuration_file_path(APP_NAME, None)?.display()
);
} }
Subcommand::Show => { Subcommand::Show => {
println!("{:?}", data.cfg); println!("{:?}", data.cfg);
......
...@@ -50,6 +50,7 @@ impl Data { ...@@ -50,6 +50,7 @@ impl Data {
token_symbol: "tokens".into(), token_symbol: "tokens".into(),
..Default::default() ..Default::default()
} }
.overwrite_from_args()
} }
// --- getters --- // --- getters ---
// the "unwrap" should not fail if data is well prepared // the "unwrap" should not fail if data is well prepared
...@@ -78,6 +79,16 @@ impl Data { ...@@ -78,6 +79,16 @@ impl Data {
) )
} }
// --- mutators --- // --- mutators ---
/// use arguments to overwrite config
pub fn overwrite_from_args(mut self) -> Self {
if let Some(duniter_endpoint) = self.args.url.clone() {
self.cfg.duniter_endpoint = duniter_endpoint;
}
if let Some(indexer_endpoint) = self.args.indexer.clone() {
self.cfg.indexer_endpoint = indexer_endpoint
}
self
}
/// force an address if needed /// force an address if needed
pub fn build_address(mut self) -> Self { pub fn build_address(mut self) -> Self {
self.address = Some( self.address = Some(
...@@ -109,12 +120,17 @@ impl Data { ...@@ -109,12 +120,17 @@ impl Data {
/// build a client from url /// build a client from url
// TODO get client from a pre-defined list // TODO get client from a pre-defined list
pub async fn build_client(mut self) -> Self { pub async fn build_client(mut self) -> Self {
self.client = Some(Client::from_url(&self.args.url).await.unwrap_or_else(|_| { let duniter_endpoint = self.cfg.duniter_endpoint.clone();
self.client = Some(
Client::from_url(&duniter_endpoint)
.await
.unwrap_or_else(|_| {
panic!( panic!(
"could not establish connection with the server {}", "could not establish connection with the server {}",
self.args.url duniter_endpoint
) )
})); }),
);
self self
} }
/// build an indexer if not disabled /// build an indexer if not disabled
...@@ -127,7 +143,7 @@ impl Data { ...@@ -127,7 +143,7 @@ impl Data {
gql_client: reqwest::Client::builder() gql_client: reqwest::Client::builder()
.user_agent("gcli/0.1.0") .user_agent("gcli/0.1.0")
.build()?, .build()?,
gql_url: self.args.indexer.clone(), gql_url: self.cfg.indexer_endpoint.clone(),
}) })
}; };
Ok(self) Ok(self)
......
...@@ -76,8 +76,8 @@ pub struct Args { ...@@ -76,8 +76,8 @@ pub struct Args {
#[clap(subcommand)] #[clap(subcommand)]
pub subcommand: Subcommand, pub subcommand: Subcommand,
/// Overwrite indexer endpoint /// Overwrite indexer endpoint
#[clap(short, long, default_value = "")] #[clap(short, long)]
indexer: String, indexer: Option<String>,
/// Do not use indexer /// Do not use indexer
#[clap(long)] #[clap(long)]
no_indexer: bool, no_indexer: bool,
...@@ -92,8 +92,8 @@ pub struct Args { ...@@ -92,8 +92,8 @@ pub struct Args {
#[clap(short, long)] #[clap(short, long)]
address: Option<String>, address: Option<String>,
/// Overwrite duniter websocket RPC endpoint /// Overwrite duniter websocket RPC endpoint
#[clap(short, long, default_value = "")] #[clap(short, long)]
url: String, url: Option<String>,
} }
/// track progress of transaction on the network /// track progress of transaction on the network
...@@ -312,6 +312,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -312,6 +312,7 @@ async fn main() -> Result<(), GcliError> {
track_progress(progress).await? track_progress(progress).await?
} }
Subcommand::CreateOneshot { balance, dest } => { Subcommand::CreateOneshot { balance, dest } => {
data = data.build_client().await;
commands::oneshot::create_oneshot_account( commands::oneshot::create_oneshot_account(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -321,13 +322,14 @@ async fn main() -> Result<(), GcliError> { ...@@ -321,13 +322,14 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
balance, balance,
dest, dest,
) )
.await? .await?
} }
Subcommand::ConsumeOneshot { dest, dest_oneshot } => { Subcommand::ConsumeOneshot { dest, dest_oneshot } => {
data = data.build_client().await;
commands::oneshot::consume_oneshot_account( commands::oneshot::consume_oneshot_account(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -337,7 +339,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -337,7 +339,7 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
dest, dest,
dest_oneshot, dest_oneshot,
) )
...@@ -350,6 +352,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -350,6 +352,7 @@ async fn main() -> Result<(), GcliError> {
remaining_to, remaining_to,
remaining_to_oneshot, remaining_to_oneshot,
} => { } => {
data = data.build_client().await;
commands::oneshot::consume_oneshot_account_with_remaining( commands::oneshot::consume_oneshot_account_with_remaining(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -359,7 +362,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -359,7 +362,7 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
balance, balance,
dest, dest,
dest_oneshot, dest_oneshot,
...@@ -369,13 +372,8 @@ async fn main() -> Result<(), GcliError> { ...@@ -369,13 +372,8 @@ async fn main() -> Result<(), GcliError> {
.await? .await?
} }
Subcommand::Expire { blocks, sessions } => { Subcommand::Expire { blocks, sessions } => {
commands::expire::monitor_expirations( data = data.build_client().await;
Client::from_url(&args.url).await.unwrap(), commands::expire::monitor_expirations(&data, blocks, sessions).await?
blocks,
sessions,
&args,
)
.await?
} }
Subcommand::Identity { Subcommand::Identity {
ref account_id, ref account_id,
...@@ -384,11 +382,10 @@ async fn main() -> Result<(), GcliError> { ...@@ -384,11 +382,10 @@ async fn main() -> Result<(), GcliError> {
} => { } => {
data = data.build_client().await; data = data.build_client().await;
commands::identity::get_identity( commands::identity::get_identity(
data.client(), &data,
account_id.clone(), account_id.clone(),
identity_id, identity_id,
username.clone(), username.clone(),
&args,
) )
.await? .await?
} }
...@@ -404,6 +401,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -404,6 +401,7 @@ async fn main() -> Result<(), GcliError> {
commands::revocation::print_revoc_sig(&data) commands::revocation::print_revoc_sig(&data)
} }
Subcommand::GoOffline => { Subcommand::GoOffline => {
data = data.build_client().await;
commands::smith::go_offline( commands::smith::go_offline(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -413,11 +411,12 @@ async fn main() -> Result<(), GcliError> { ...@@ -413,11 +411,12 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
) )
.await? .await?
} }
Subcommand::GoOnline => { Subcommand::GoOnline => {
data = data.build_client().await;
commands::smith::go_online( commands::smith::go_online(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -427,24 +426,23 @@ async fn main() -> Result<(), GcliError> { ...@@ -427,24 +426,23 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
) )
.await? .await?
} }
Subcommand::OneshotBalance { account } => { Subcommand::OneshotBalance { account } => {
commands::oneshot::oneshot_account_balance( data = data.build_client().await;
Client::from_url(&args.url).await.unwrap(), commands::oneshot::oneshot_account_balance(data.client(), account).await?
account,
)
.await?
} }
Subcommand::Online => { Subcommand::Online => {
commands::smith::online(Client::from_url(&args.url).await.unwrap(), &args).await? data = data.build_client().await;
commands::smith::online(&data).await?
} }
Subcommand::Repart { Subcommand::Repart {
target, target,
actual_repart, actual_repart,
} => { } => {
data = data.build_client().await;
commands::net_test::repart( commands::net_test::repart(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -454,13 +452,14 @@ async fn main() -> Result<(), GcliError> { ...@@ -454,13 +452,14 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
target, target,
actual_repart, actual_repart,
) )
.await? .await?
} }
Subcommand::SpamRoll { actual_repart } => { Subcommand::SpamRoll { actual_repart } => {
data = data.build_client().await;
commands::net_test::spam_roll( commands::net_test::spam_roll(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -470,7 +469,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -470,7 +469,7 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
actual_repart, actual_repart,
) )
.await? .await?
...@@ -489,19 +488,15 @@ async fn main() -> Result<(), GcliError> { ...@@ -489,19 +488,15 @@ async fn main() -> Result<(), GcliError> {
commands::smith::cert(data.client(), data.keypair(), data.idty_index(), to).await? commands::smith::cert(data.client(), data.keypair(), data.idty_index(), to).await?
} }
Subcommand::TechMembers => { Subcommand::TechMembers => {
commands::collective::technical_committee_members( data = data.build_client().await;
Client::from_url(&args.url).await.unwrap(), commands::collective::technical_committee_members(&data).await?
&args,
)
.await?
} }
Subcommand::TechProposals => { Subcommand::TechProposals => {
commands::collective::technical_committee_proposals( data = data.build_client().await;
Client::from_url(&args.url).await.unwrap(), commands::collective::technical_committee_proposals(data.client()).await?
)
.await?
} }
Subcommand::TechVote { hash, index, vote } => { Subcommand::TechVote { hash, index, vote } => {
data = data.build_client().await;
let vote = match vote { let vote = match vote {
0 => false, 0 => false,
1 => true, 1 => true,
...@@ -516,7 +511,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -516,7 +511,7 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
hash, //H256::from_str(&hash).expect("Invalid hash formatting"), hash, //H256::from_str(&hash).expect("Invalid hash formatting"),
index, index,
vote, vote,
...@@ -528,6 +523,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -528,6 +523,7 @@ async fn main() -> Result<(), GcliError> {
dest, dest,
keep_alive, keep_alive,
} => { } => {
data = data.build_client().await;
commands::transfer::transfer( commands::transfer::transfer(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -537,7 +533,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -537,7 +533,7 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
amount, amount,
dest, dest,
keep_alive, keep_alive,
...@@ -545,6 +541,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -545,6 +541,7 @@ async fn main() -> Result<(), GcliError> {
.await? .await?
} }
Subcommand::TransferMultiple { amount, dests } => { Subcommand::TransferMultiple { amount, dests } => {
data = data.build_client().await;
commands::transfer::transfer_multiple( commands::transfer::transfer_multiple(
get_keys( get_keys(
args.secret_format, args.secret_format,
...@@ -554,13 +551,15 @@ async fn main() -> Result<(), GcliError> { ...@@ -554,13 +551,15 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
amount, amount,
dests, dests,
) )
.await? .await?
} }
Subcommand::UpdateKeys => commands::smith::update_session_keys( Subcommand::UpdateKeys => {
data = data.build_client().await;
commands::smith::update_session_keys(
get_keys( get_keys(
args.secret_format, args.secret_format,
&args.address, &args.address,
...@@ -569,10 +568,11 @@ async fn main() -> Result<(), GcliError> { ...@@ -569,10 +568,11 @@ async fn main() -> Result<(), GcliError> {
)? )?
.1 .1
.unwrap(), .unwrap(),
Client::from_url(&args.url).await.unwrap(), data.client(),
) )
.await .await
.unwrap(), .unwrap()
}
Subcommand::RuntimeInfo => { Subcommand::RuntimeInfo => {
data = data.build_client().await.fetch_system_properties().await?; data = data.build_client().await.fetch_system_properties().await?;
commands::runtime::runtime_info(data).await; commands::runtime::runtime_info(data).await;
...@@ -600,14 +600,14 @@ async fn main() -> Result<(), GcliError> { ...@@ -600,14 +600,14 @@ async fn main() -> Result<(), GcliError> {
if data.genesis_hash == data.indexer_genesis_hash { if data.genesis_hash == data.indexer_genesis_hash {
println!( println!(
"{} and {} have the same genesis hash: {}", "{} and {} have the same genesis hash: {}",
data.args.url, data.cfg.duniter_endpoint,
data.indexer().gql_url, data.indexer().gql_url,
data.genesis_hash data.genesis_hash
); );
} else { } else {
println!( println!(
"⚠️ {} ({}) and {} ({}) do not share same genesis", "⚠️ {} ({}) and {} ({}) do not share same genesis",
data.args.url, data.cfg.duniter_endpoint,
data.genesis_hash, data.genesis_hash,
data.indexer().gql_url, data.indexer().gql_url,
data.indexer_genesis_hash data.indexer_genesis_hash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment