Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): streamline neuron balance execution #1227

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading