From d3df09f2a9eb0360632c7da934aadc0135a7db16 Mon Sep 17 00:00:00 2001 From: tuxmain <tuxmain@zettascript.org> Date: Mon, 20 Feb 2023 17:20:35 +0100 Subject: [PATCH] feat: command tech-members --- src/commands.rs | 1 + src/commands/collective.rs | 59 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 5 ++++ 3 files changed, 65 insertions(+) create mode 100644 src/commands/collective.rs diff --git a/src/commands.rs b/src/commands.rs index 976ef71..f419bf3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,3 +1,4 @@ +pub mod collective; pub mod expire; pub mod identity; pub mod net_test; diff --git a/src/commands/collective.rs b/src/commands/collective.rs new file mode 100644 index 0000000..5fa99dd --- /dev/null +++ b/src/commands/collective.rs @@ -0,0 +1,59 @@ +use crate::{gdev, indexer::*, Args, Client}; + +use anyhow::Result; + +pub async fn technical_committee_members(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 indexer = if args.no_indexer { + None + } else { + Some(Indexer { + gql_client, + gql_url: &args.indexer, + }) + }; + + for account_id in client + .storage() + .fetch( + &gdev::storage().technical_committee().members(), + Some(parent_hash), + ) + .await? + .unwrap_or_default() + { + println!( + "{}", + if let Some(indexer) = &indexer { + indexer + .username_by_pubkey(&account_id.to_string()) + .await + .ok() + .flatten() + } else { + client + .storage() + .fetch( + &gdev::storage().identity().identity_index_of(&account_id), + Some(parent_hash), + ) + .await + .ok() + .flatten() + .map(|identity_id| format!("{identity_id}")) + } + .unwrap_or_else(|| account_id.to_string(),) + ); + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index e741ac9..a7cb40b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,6 +140,8 @@ pub enum Subcommand { SudoSetKey { new_key: sp_core::crypto::AccountId32, }, + /// List members of the technical committee + TechMembers, Transfer { /// Amount to transfer amount: u64, @@ -311,6 +313,9 @@ async fn main() -> Result<()> { ) .await? } + Subcommand::TechMembers => { + commands::collective::technical_committee_members(client, &args).await? + } Subcommand::Transfer { amount, dest, -- GitLab