From e1441a8b13a2aaa4e87cd85bb315be2fb797251d Mon Sep 17 00:00:00 2001 From: nikolamilosa Date: Tue, 26 Nov 2024 11:57:04 +0100 Subject: [PATCH] integrating a call to cmc canister to fetch previous public subnets --- .../src/commands/update_authorized_subnets.rs | 15 +++++++++-- rs/ic-canisters/src/cycles_minting.rs | 26 +++++++++++++++++++ rs/ic-canisters/src/lib.rs | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 rs/ic-canisters/src/cycles_minting.rs diff --git a/rs/cli/src/commands/update_authorized_subnets.rs b/rs/cli/src/commands/update_authorized_subnets.rs index d4e0acf4d..43a511657 100644 --- a/rs/cli/src/commands/update_authorized_subnets.rs +++ b/rs/cli/src/commands/update_authorized_subnets.rs @@ -1,3 +1,4 @@ +use ic_canisters::cycles_minting::CyclesMintingCanisterWrapper; use indexmap::IndexMap; use std::{path::PathBuf, sync::Arc}; @@ -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() @@ -141,6 +145,7 @@ impl UpdateAuthorizedSubnets { fn construct_summary( subnets: &Arc>, excluded_subnets: &IndexMap, + current_public_subnets: Vec, forum_post_link: Option, ) -> anyhow::Result { Ok(format!( @@ -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().find(|principal| *principal == &s.principal).is_some(); 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() ) }) diff --git a/rs/ic-canisters/src/cycles_minting.rs b/rs/ic-canisters/src/cycles_minting.rs new file mode 100644 index 000000000..018ea1239 --- /dev/null +++ b/rs/ic-canisters/src/cycles_minting.rs @@ -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 for CyclesMintingCanisterWrapper { + fn from(value: IcAgentCanisterClient) -> Self { + Self { + agent: value, + canister_id: CYCLES_MINTING_CANISTER_ID.clone(), + } + } +} + +impl CyclesMintingCanisterWrapper { + pub async fn get_authorized_subnets(&self) -> anyhow::Result> { + self.agent + .query(&self.canister_id.into(), "get_default_subnets", candid::encode_one(())?) + .await + } +} diff --git a/rs/ic-canisters/src/lib.rs b/rs/ic-canisters/src/lib.rs index 331968b59..19c58e584 100644 --- a/rs/ic-canisters/src/lib.rs +++ b/rs/ic-canisters/src/lib.rs @@ -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;