Skip to content

Commit

Permalink
chore: integrating call cmc to show diff (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosa authored Nov 27, 2024
1 parent 1ea97a9 commit 76c0c79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rs/cli/src/commands/update_authorized_subnets.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ic_canisters::cycles_minting::CyclesMintingCanisterWrapper;
use indexmap::IndexMap;
use std::{path::PathBuf, sync::Arc};

Expand Down Expand Up @@ -89,7 +90,10 @@ impl ExecutableCommand for UpdateAuthorizedSubnets {
}
}

let summary = construct_summary(&subnets, &excluded_subnets, ctx.forum_post_link())?;
let (_, agent) = ctx.create_ic_agent_canister_client().await?;
let cmc = CyclesMintingCanisterWrapper::from(agent);
let public_subnets = cmc.get_authorized_subnets().await?;
let summary = construct_summary(&subnets, &excluded_subnets, public_subnets, ctx.forum_post_link())?;

let authorized = subnets
.keys()
Expand Down Expand Up @@ -141,6 +145,7 @@ impl UpdateAuthorizedSubnets {
fn construct_summary(
subnets: &Arc<IndexMap<PrincipalId, Subnet>>,
excluded_subnets: &IndexMap<PrincipalId, String>,
current_public_subnets: Vec<PrincipalId>,
forum_post_link: Option<String>,
) -> anyhow::Result<String> {
Ok(format!(
Expand All @@ -155,10 +160,16 @@ fn construct_summary(
.values()
.map(|s| {
let excluded_desc = excluded_subnets.get(&s.principal);
let was_public = current_public_subnets.iter().any(|principal| principal == &s.principal);
format!(
"| {} | {} | {} |",
s.principal,
excluded_desc.is_none(),
match (was_public, excluded_desc.is_none()) {
// The state doesn't change
(was_public, is_excluded) if was_public == is_excluded => was_public.to_string(),
// It changed from `was_public` to `is_excluded`
(was_public, is_excluded) => format!("~~{}~~ ⇒ {}", was_public, is_excluded),
},
excluded_desc.map(|s| s.to_string()).unwrap_or_default()
)
})
Expand Down
26 changes: 26 additions & 0 deletions rs/ic-canisters/src/cycles_minting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use ic_nns_constants::CYCLES_MINTING_CANISTER_ID;
use ic_types::{CanisterId, PrincipalId};

use crate::IcAgentCanisterClient;

pub struct CyclesMintingCanisterWrapper {
agent: IcAgentCanisterClient,
canister_id: CanisterId,
}

impl From<IcAgentCanisterClient> for CyclesMintingCanisterWrapper {
fn from(value: IcAgentCanisterClient) -> Self {
Self {
agent: value,
canister_id: CYCLES_MINTING_CANISTER_ID,
}
}
}

impl CyclesMintingCanisterWrapper {
pub async fn get_authorized_subnets(&self) -> anyhow::Result<Vec<PrincipalId>> {
self.agent
.query(&self.canister_id.into(), "get_default_subnets", candid::encode_one(())?)
.await
}
}
1 change: 1 addition & 0 deletions rs/ic-canisters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::str::FromStr;
use std::time::Duration;
use url::Url;

pub mod cycles_minting;
pub mod governance;
pub mod ledger;
pub mod management;
Expand Down

0 comments on commit 76c0c79

Please sign in to comment.