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: ic admin #835

Merged
merged 11 commits into from
Sep 2, 2024
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_types::PrincipalId;

use crate::{
commands::{ExecutableCommand, IcAdminRequirement},
ic_admin,
ic_admin::{self},
};

#[derive(Args, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_types::PrincipalId;

use crate::{
commands::{ExecutableCommand, IcAdminRequirement},
ic_admin,
ic_admin::{self},
};

#[derive(Args, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_types::PrincipalId;

use crate::{
commands::{ExecutableCommand, IcAdminRequirement},
ic_admin,
ic_admin::{self},
};

#[derive(Args, Debug)]
Expand Down
8 changes: 4 additions & 4 deletions rs/cli/src/commands/firewall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use log::{info, warn};
use serde::Serialize;
use tempfile::NamedTempFile;

use crate::ic_admin::{IcAdminWrapper, ProposeCommand, ProposeOptions};
use crate::ic_admin::{IcAdmin, ProposeCommand, ProposeOptions};

use super::{ExecutableCommand, IcAdminRequirement};

Expand Down Expand Up @@ -119,7 +119,7 @@ impl ExecutableCommand for Firewall {

impl Firewall {
async fn submit_proposal(
admin_wrapper: Arc<IcAdminWrapper>,
admin: Arc<dyn IcAdmin>,
modifications: Vec<FirewallRuleModification>,
propose_options: ProposeOptions,
firewall_rules_scope: &FirewallRulesScope,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl Firewall {
args: test_args.clone(),
};

let output = admin_wrapper
let output = admin
.propose_run(cmd, propose_options.clone())
.await
.map_err(|e| anyhow::anyhow!("Couldn't execute test for {}-firewall-rules: {:?}", change_type, e))?;
Expand Down Expand Up @@ -185,7 +185,7 @@ impl Firewall {
command: format!("{}-firewall-rules", change_type),
args: final_args,
};
let _ = admin_wrapper.propose_run(cmd, propose_options.clone()).await?;
let _ = admin.propose_run(cmd, propose_options.clone()).await?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/neuron/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl ExecutableCommand for Balance {
async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance = GovernanceCanisterWrapper::from(ctx.create_canister_client()?);
let neuron_info = governance
.get_neuron_info(self.neuron.unwrap_or_else(|| ctx.ic_admin().neuron.neuron_id))
.get_neuron_info(self.neuron.unwrap_or_else(|| ctx.ic_admin().neuron().neuron_id))
.await?;

println!("{}", neuron_info.stake_e8s / 10_u64.pow(8));
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/neuron/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl ExecutableCommand for Refresh {
async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance_canister = GovernanceCanisterWrapper::from(ctx.create_canister_client()?);

let resp = governance_canister.refresh_neuron(ctx.ic_admin().neuron.neuron_id).await?;
let resp = governance_canister.refresh_neuron(ctx.ic_admin().neuron().neuron_id).await?;
println!("{:?}", resp);

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions rs/cli/src/commands/neuron/top_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ impl ExecutableCommand for TopUp {

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance = GovernanceCanisterWrapper::from(ctx.create_canister_client()?);
let full_neuron = governance.get_full_neuron(ctx.ic_admin().neuron.neuron_id).await?;
let full_neuron = governance.get_full_neuron(ctx.ic_admin().neuron().neuron_id).await?;
let account_hex = full_neuron.account.iter().map(|byte| format!("{:02x}", byte)).join("");

println!("Please request ICP in the #icp-to-go slack channel:");
println!(
"> Hi! Can I please get XX ICPs on the account address `{}` for neuron ID {} in order to be able to submit more NNS proposals. Thank you\n",
account_hex,
ctx.ic_admin().neuron.neuron_id
ctx.ic_admin().neuron().neuron_id
);
println!("You can check balance by running `dre neuron balance`");

Expand Down
1 change: 1 addition & 0 deletions rs/cli/src/commands/qualify/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde_json::Value;

use crate::{
commands::{ExecutableCommand, IcAdminRequirement},
ic_admin::IcAdmin,
qualification::QualificationExecutorBuilder,
};

Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl ExecutableCommand for Vote {
),
);

let response = match client.register_vote(ctx.ic_admin().neuron.neuron_id, proposal.id.unwrap().id).await {
let response = match client.register_vote(ctx.ic_admin().neuron().neuron_id, proposal.id.unwrap().id).await {
Ok(response) => format!("Voted successfully: {}", response),
Err(e) => {
DesktopNotifier::send_critical(
Expand Down
20 changes: 10 additions & 10 deletions rs/cli/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use log::info;
use crate::{
auth::Neuron,
commands::{Args, ExecutableCommand, IcAdminRequirement},
ic_admin::{download_ic_admin, should_update_ic_admin, IcAdminWrapper},
ic_admin::{download_ic_admin, should_update_ic_admin, IcAdmin, IcAdminImpl},
runner::Runner,
subnet_manager::SubnetManager,
};
Expand All @@ -30,7 +30,7 @@ const STAGING_NEURON_ID: u64 = 49;
pub struct DreContext {
network: Network,
registry: RefCell<Option<Arc<dyn LazyRegistry>>>,
ic_admin: Option<Arc<IcAdminWrapper>>,
ic_admin: Option<Arc<dyn IcAdmin>>,
runner: RefCell<Option<Rc<Runner>>>,
verbose_runner: bool,
skip_sync: bool,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl DreContext {
proceed_without_confirmation: bool,
dry_run: bool,
requirement: IcAdminRequirement,
) -> anyhow::Result<(Option<Arc<IcAdminWrapper>>, Option<String>)> {
) -> anyhow::Result<(Option<Arc<dyn IcAdmin>>, Option<String>)> {
if let IcAdminRequirement::None = requirement {
return Ok((None, None));
}
Expand Down Expand Up @@ -138,13 +138,13 @@ impl DreContext {
(false, s) => s,
};

let ic_admin = Some(Arc::new(IcAdminWrapper::new(
let ic_admin = Some(Arc::new(IcAdminImpl::new(
network.clone(),
Some(ic_admin_path.clone()),
proceed_without_confirmation,
neuron,
dry_run,
)));
)) as Arc<dyn IcAdmin>);

Ok((ic_admin, Some(ic_admin_path)))
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl DreContext {
let nns_url = self.network.get_nns_urls().first().expect("Should have at least one NNS url");

match &self.ic_admin {
Some(a) => match &a.neuron.auth {
Some(a) => match &a.neuron().auth {
crate::auth::Auth::Hsm { pin, slot, key_id } => CanisterClient::from_hsm(pin.clone(), *slot, key_id.clone(), nns_url),
crate::auth::Auth::Keyfile { path } => CanisterClient::from_key_file(path.clone(), nns_url),
crate::auth::Auth::Anonymous => CanisterClient::from_anonymous(nns_url),
Expand All @@ -189,7 +189,7 @@ impl DreContext {
pub fn create_ic_agent_canister_client(&self, lock: Option<Mutex<()>>) -> anyhow::Result<IcAgentCanisterClient> {
let nns_url = self.network.get_nns_urls().first().expect("Should have at least one NNS url");
match &self.ic_admin {
Some(a) => match &a.neuron.auth {
Some(a) => match &a.neuron().auth {
crate::auth::Auth::Hsm { pin, slot, key_id } => {
IcAgentCanisterClient::from_hsm(pin.to_string(), *slot, key_id.to_string(), nns_url.to_owned(), lock)
}
Expand All @@ -200,15 +200,15 @@ impl DreContext {
}
}

pub fn ic_admin(&self) -> Arc<IcAdminWrapper> {
pub fn ic_admin(&self) -> Arc<dyn IcAdmin> {
match &self.ic_admin {
Some(a) => a.clone(),
None => panic!("This command is not configured to use ic admin"),
}
}

pub fn readonly_ic_admin_for_other_network(&self, network: Network) -> IcAdminWrapper {
IcAdminWrapper::new(network, self.ic_admin_path.clone(), true, Neuron::anonymous_neuron(), false)
pub fn readonly_ic_admin_for_other_network(&self, network: Network) -> impl IcAdmin {
IcAdminImpl::new(network, self.ic_admin_path.clone(), true, Neuron::anonymous_neuron(), false)
}

pub async fn subnet_manager(&self) -> SubnetManager {
Expand Down
Loading
Loading