From bb913abb69b1b63393a688864d7e3f54fd917c3b Mon Sep 17 00:00:00 2001 From: tuxmain <tuxmain@zettascript.org> Date: Fri, 17 Feb 2023 19:49:12 +0100 Subject: [PATCH] feat: online command --- src/commands/smith.rs | 88 ++++++++++++++++++++++++++++++++++++++++++- src/main.rs | 3 ++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/commands/smith.rs b/src/commands/smith.rs index 12ea71c..929ea03 100644 --- a/src/commands/smith.rs +++ b/src/commands/smith.rs @@ -1,4 +1,4 @@ -use crate::{gdev, Client}; +use crate::{cache, gdev, indexer::*, Args, Client}; use anyhow::{anyhow, Result}; use sp_core::{crypto::AccountId32, sr25519::Pair, Pair as _}; @@ -76,3 +76,89 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> { Ok(()) } + +pub async fn online(client: Client, args: &Args) -> Result<()> { + let parent_hash = client + .storage() + .fetch(&gdev::storage().system().parent_hash(), None) + .await? + .unwrap(); + + let gql_client = reqwest::Client::builder() + .user_agent("gcli/0.1.0") + .build()?; + + let mut identity_cache = cache::IdentityCache::new( + &client, + if args.no_indexer { + None + } else { + Some(Indexer { + gql_client, + gql_url: &args.indexer, + }) + }, + ); + + let online_authorities = client + .storage() + .fetch( + &gdev::storage().authority_members().online_authorities(), + Some(parent_hash), + ) + .await? + .unwrap_or_default(); + + println!("Online:"); + for identity_id in online_authorities { + println!( + " {}", + identity_cache + .fetch_identity(identity_id, parent_hash) + .await + .unwrap_or_else(|_| format!("{identity_id}")) + ); + } + + let incoming_authorities = client + .storage() + .fetch( + &gdev::storage().authority_members().incoming_authorities(), + Some(parent_hash), + ) + .await? + .unwrap_or_default(); + + println!("Incoming:"); + for identity_id in incoming_authorities { + println!( + " {}", + identity_cache + .fetch_identity(identity_id, parent_hash) + .await + .unwrap_or_else(|_| format!("{identity_id}")) + ); + } + + let outgoing_authorities = client + .storage() + .fetch( + &gdev::storage().authority_members().outgoing_authorities(), + Some(parent_hash), + ) + .await? + .unwrap_or_default(); + + println!("Outgoing:"); + for identity_id in outgoing_authorities { + println!( + " {}", + identity_cache + .fetch_identity(identity_id, parent_hash) + .await + .unwrap_or_else(|_| format!("{identity_id}")) + ); + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 1f7ff54..e741ac9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,8 @@ pub enum Subcommand { OneshotBalance { account: sp_core::crypto::AccountId32, }, + /// List online authorities + Online, #[clap(hide = true)] Repart { // Number of transactions per block to target @@ -280,6 +282,7 @@ async fn main() -> Result<()> { Subcommand::OneshotBalance { account } => { commands::oneshot::oneshot_account_balance(client, account).await? } + Subcommand::Online => commands::smith::online(client, &args).await?, Subcommand::Repart { target, actual_repart, -- GitLab