Skip to content
Snippets Groups Projects
Verified Commit bb913abb authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

feat: online command

parent 45cce8b9
No related branches found
No related tags found
No related merge requests found
use crate::{gdev, Client}; use crate::{cache, gdev, indexer::*, Args, Client};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use sp_core::{crypto::AccountId32, sr25519::Pair, Pair as _}; use sp_core::{crypto::AccountId32, sr25519::Pair, Pair as _};
...@@ -76,3 +76,89 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> { ...@@ -76,3 +76,89 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> {
Ok(()) 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(())
}
...@@ -123,6 +123,8 @@ pub enum Subcommand { ...@@ -123,6 +123,8 @@ pub enum Subcommand {
OneshotBalance { OneshotBalance {
account: sp_core::crypto::AccountId32, account: sp_core::crypto::AccountId32,
}, },
/// List online authorities
Online,
#[clap(hide = true)] #[clap(hide = true)]
Repart { Repart {
// Number of transactions per block to target // Number of transactions per block to target
...@@ -280,6 +282,7 @@ async fn main() -> Result<()> { ...@@ -280,6 +282,7 @@ async fn main() -> Result<()> {
Subcommand::OneshotBalance { account } => { Subcommand::OneshotBalance { account } => {
commands::oneshot::oneshot_account_balance(client, account).await? commands::oneshot::oneshot_account_balance(client, account).await?
} }
Subcommand::Online => commands::smith::online(client, &args).await?,
Subcommand::Repart { Subcommand::Repart {
target, target,
actual_repart, actual_repart,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment