Skip to content

Commit

Permalink
refactor(cli): streamline neuron balance execution (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic authored Jan 20, 2025
1 parent f9a1911 commit 36d986c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 3 additions & 13 deletions rs/cli/src/commands/neuron/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@ use ic_canisters::governance::GovernanceCanisterWrapper;
use crate::commands::ExecutableCommand;

#[derive(Args, Debug)]
pub struct Balance {
/// Neuron to query, by default will use the one from configured identity
#[clap(long)]
neuron_override: Option<u64>,
}
pub struct Balance {}

impl ExecutableCommand for Balance {
fn require_auth(&self) -> crate::commands::AuthRequirement {
match &self.neuron_override {
Some(_) => crate::commands::AuthRequirement::Anonymous,
None => crate::commands::AuthRequirement::Neuron,
}
crate::commands::AuthRequirement::Neuron
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let (neuron, client) = ctx.create_ic_agent_canister_client().await?;
let governance = GovernanceCanisterWrapper::from(client);
let neuron_id = match self.neuron_override {
Some(n) => n,
None => neuron.neuron_id,
};
let neuron_id = ctx.neuron_id().unwrap_or(neuron.neuron_id);
let neuron_info = governance.get_neuron_info(neuron_id).await?;

println!("{}", neuron_info.stake_e8s / 10_u64.pow(8));
Expand Down
4 changes: 4 additions & 0 deletions rs/cli/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ impl DreContext {
Ok(neuron)
}

pub fn neuron_id(&self) -> Option<u64> {
self.neuron_opts.neuron_id
}

pub async fn readonly_ic_admin_for_other_network(&self, network: Network) -> anyhow::Result<impl IcAdmin> {
let ic_admin = self.ic_admin().await?;
Ok(IcAdminImpl::new(
Expand Down

0 comments on commit 36d986c

Please sign in to comment.