From 725b5f6285bf4c7a808a83a0d2eb6cdf61531b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Demay?= Date: Wed, 27 May 2026 07:26:17 +0000 Subject: [PATCH] chore: DEFI-2304 remove deprecated ic-cdk imports in ic-icp-index Migrate the ICP index canister off `ic_cdk::api::caller`, `ic_cdk::api::call::call`, `ic_cdk::api::canister_balance128` and `ic_cdk::api::stable::stable_size` (all deprecated in #6264), and drop the file-level `#![allow(deprecated)]`. The inter-canister calls now use the `ic_cdk::call::Call::unbounded_wait(...).with_arg(...).await?.candid()?` builder (returning `Response::candid` rather than the deprecated `(T,)` tuple shape). The internal `State::last_wait_time` field (tracked separately by DEFI-1144) keeps a narrowly-scoped `#[allow(deprecated)]` on its only construction site. Co-Authored-By: Claude Opus 4.7 (1M context) --- rs/ledger_suite/icp/index/src/main.rs | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/rs/ledger_suite/icp/index/src/main.rs b/rs/ledger_suite/icp/index/src/main.rs index 952a854385ea..77d596848b72 100644 --- a/rs/ledger_suite/icp/index/src/main.rs +++ b/rs/ledger_suite/icp/index/src/main.rs @@ -1,8 +1,8 @@ -#![allow(deprecated)] use candid::Principal; use ic_base_types::PrincipalId; use ic_canister_log::{export as export_logs, log}; -use ic_cdk::api::caller; +use ic_cdk::api::msg_caller; +use ic_cdk::call::Call; use ic_cdk::{init, post_upgrade, query, trap}; use ic_cdk_timers::TimerId; use ic_http_types::{HttpRequest, HttpResponse, HttpResponseBuilder}; @@ -125,6 +125,7 @@ impl State { // a Default impl for the initialization of the [STATE] variable above. impl Default for State { fn default() -> Self { + #[allow(deprecated)] Self { is_build_index_running: false, ledger_id: Principal::management_canister(), @@ -315,10 +316,12 @@ async fn get_blocks_from_ledger(start: u64) -> Result Result, String> { let length = - length.min(icp_ledger::max_blocks_per_request(&PrincipalId::from(caller())) as u64); + length.min(icp_ledger::max_blocks_per_request(&PrincipalId::from(msg_caller())) as u64); with_blocks(|blocks| { let limit = blocks.len().min(start.saturating_add(length)); let mut res = vec![]; @@ -597,12 +602,12 @@ fn get_oldest_tx_id(account_identifier: AccountIdentifier) -> Option pub fn encode_metrics(w: &mut ic_metrics_encoder::MetricsEncoder>) -> std::io::Result<()> { w.encode_gauge( "index_stable_memory_pages", - ic_cdk::api::stable::stable_size() as f64, + ic_cdk::stable::stable_size() as f64, "Size of the stable memory allocated by this canister measured in 64K Wasm pages.", )?; w.encode_gauge( "stable_memory_bytes", - (ic_cdk::api::stable::stable_size() * 64 * 1024) as f64, + (ic_cdk::stable::stable_size() * 64 * 1024) as f64, "Size of the stable memory allocated by this canister measured in bytes.", )?; w.encode_gauge( @@ -611,7 +616,7 @@ pub fn encode_metrics(w: &mut ic_metrics_encoder::MetricsEncoder>) -> st "Size of the heap memory allocated by this canister measured in bytes.", )?; - let cycle_balance = ic_cdk::api::canister_balance128() as f64; + let cycle_balance = ic_cdk::api::canister_cycle_balance() as f64; w.encode_gauge( "index_cycle_balance", cycle_balance, @@ -651,7 +656,7 @@ fn get_account_identifier_transactions( ) -> GetAccountIdentifierTransactionsResult { let length = arg .max_results - .min(icp_ledger::max_blocks_per_request(&PrincipalId::from(caller())) as u64) + .min(icp_ledger::max_blocks_per_request(&PrincipalId::from(msg_caller())) as u64) .min(usize::MAX as u64) as usize; // TODO: deal with the user setting start to u64::MAX let start = arg.start.map_or(u64::MAX, |n| n);