diff --git a/CHANGELOG-Nns-Dapp-unreleased.md b/CHANGELOG-Nns-Dapp-unreleased.md index d00ef36eadc..584c27da209 100644 --- a/CHANGELOG-Nns-Dapp-unreleased.md +++ b/CHANGELOG-Nns-Dapp-unreleased.md @@ -25,6 +25,7 @@ proposal is successful, the changes it released will be moved from this file to * Reduce calls to `sns-governance` canister by getting `nervous_system_parameters` from the aggregator instead. * Move theme toggle from account menu to sidebar. * The `Markdown` UI component was migrated to `@dfinity/gix-components`. +* Migrate canister code from `dfn_core` to `ic_cdk`. #### Deprecated diff --git a/Cargo.lock b/Cargo.lock index ddaa1444c91..a7c0989029b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", @@ -3137,9 +3137,9 @@ dependencies = [ [[package]] name = "ic-wasm" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5574bf249d201ddd2c27c3fdf178ddacb1be1c705c8a5b4c1339c393758f2bf2" +checksum = "19fabaeecfe37f24b433c62489242fc54503d98d4cc8d0f9ef7544dfdfc0ddcb" dependencies = [ "anyhow", "candid", @@ -3609,9 +3609,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libflate" @@ -3834,7 +3834,6 @@ dependencies = [ "candid_parser", "cycles-minting-canister", "dfn_candid", - "dfn_core", "dfn_protobuf", "flate2", "hex", @@ -4161,9 +4160,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "powerfmt" @@ -4331,7 +4330,6 @@ dependencies = [ "candid_parser", "cycles-minting-canister", "dfn_candid", - "dfn_core", "hex", "ic-base-types", "ic-btc-interface", @@ -4515,9 +4513,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" dependencies = [ "bitflags 2.6.0", ] @@ -4951,9 +4949,9 @@ dependencies = [ [[package]] name = "simdutf8" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "simple_asn1" @@ -5014,7 +5012,7 @@ dependencies = [ "base64 0.22.1", "candid", "dfn_candid", - "dfn_core", + "ic-base-types", "ic-cdk 0.16.0", "ic-cdk-macros 0.16.0", "ic-cdk-timers 0.10.0", @@ -5183,9 +5181,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tar" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb797dad5fb5b76fcf519e702f4a589483b5ef06567f160c392832c1f5e44909" +checksum = "4ff6c40d3aedb5e06b57c6f669ad17ab063dd1e63d977c6a88e7f4dfa4f04020" dependencies = [ "filetime", "libc", @@ -5239,18 +5237,18 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -5365,9 +5363,9 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.21" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap 2.5.0", "toml_datetime", @@ -5512,9 +5510,9 @@ dependencies = [ [[package]] name = "walrus" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "160c3708e3ad718ab4d84bec8de8c3d3450cd2902bd6c3ee3bbf50ad7529c2ad" +checksum = "501ace8ec3492754a9b3c4b59eac7159ceff8414f9e43a05029fe8ef43b9218f" dependencies = [ "anyhow", "gimli 0.26.2", @@ -5746,9 +5744,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/rs/backend/Cargo.toml b/rs/backend/Cargo.toml index 0ec41236c1a..cfddee916d3 100644 --- a/rs/backend/Cargo.toml +++ b/rs/backend/Cargo.toml @@ -23,7 +23,6 @@ tar = "0.4.40" cycles-minting-canister = { workspace = true } dfn_candid = { workspace = true } -dfn_core = { workspace = true } dfn_protobuf = { workspace = true } ic-base-types = { workspace = true } ic-cdk = { workspace = true } diff --git a/rs/backend/src/accounts_store.rs b/rs/backend/src/accounts_store.rs index 95c3e984bfc..b0a4eff24df 100644 --- a/rs/backend/src/accounts_store.rs +++ b/rs/backend/src/accounts_store.rs @@ -21,7 +21,7 @@ use std::cmp::Ordering; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fmt; use std::ops::RangeBounds; -use std::time::{Duration, SystemTime}; +use std::time::Duration; pub mod constructors; pub mod histogram; @@ -614,13 +614,7 @@ impl AccountsStore { } pub fn mark_ledger_sync_complete(&mut self) { - self.last_ledger_sync_timestamp_nanos = u64::try_from( - dfn_core::api::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or_else(|err| unreachable!("The current time is well after the Unix epoch. Error: {err}")) - .as_nanos(), - ) - .unwrap_or_else(|_| unreachable!("Not impossible, but centuries in the future")); + self.last_ledger_sync_timestamp_nanos = ic_cdk::api::time(); } /// Initializes the `block_height_synced_up_to` value. @@ -827,15 +821,7 @@ impl AccountsStore { } pub fn get_stats(&self, stats: &mut Stats) { - let timestamp_now_nanos = u64::try_from( - dfn_core::api::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or_else(|err| unreachable!("Hey, we are back in the sixties! Seriously, if we get here, the system time is before the Unix epoch. This should be impossible. Error: {err}")) - .as_nanos(), - ) - .unwrap_or_else(|_| { - unreachable!("Well, this could kill us if the code is still running in 500 years. Not impossible.") - }); + let timestamp_now_nanos = ic_cdk::api::time(); let duration_since_last_sync = Duration::from_nanos(timestamp_now_nanos - self.last_ledger_sync_timestamp_nanos); diff --git a/rs/backend/src/assets.rs b/rs/backend/src/assets.rs index 2eaa58a333d..b968a8fa319 100644 --- a/rs/backend/src/assets.rs +++ b/rs/backend/src/assets.rs @@ -6,10 +6,10 @@ use crate::stats::encode_metrics; use crate::StableState; use base64::{engine::general_purpose::STANDARD as BASE64_ENGINE, Engine}; use candid::{CandidType, Decode, Encode}; -use dfn_core::api::ic0::time; use flate2::read::GzDecoder; use flate2::write::GzEncoder; use flate2::Compression; +use ic_cdk::api::time; use ic_cdk::println; use ic_certified_map::{labeled, labeled_hash, AsHashTree, Hash, RbTree}; use serde::{Deserialize, Serialize}; @@ -210,10 +210,7 @@ pub fn http_request(req: HttpRequest) -> HttpResponse { let parts: Vec<&str> = req.url.split('?').collect(); match *parts.first().unwrap_or(&"") { "/metrics" => { - let now; - unsafe { - now = time(); - }; + let now = time(); let mut writer = MetricsEncoder::new(vec![], now / 1_000_000); match encode_metrics(&mut writer) { Ok(()) => { @@ -322,15 +319,15 @@ fn security_headers() -> Vec { } fn make_asset_certificate_header(asset_hashes: &AssetHashes, asset_name: &str) -> (String, String) { - let certificate = dfn_core::api::data_certificate().unwrap_or_else(|| { - dfn_core::api::trap_with("data certificate is only available in query calls"); + let certificate = ic_cdk::api::data_certificate().unwrap_or_else(|| { + ic_cdk::api::trap("data certificate is only available in query calls"); }); let witness = asset_hashes.0.witness(asset_name.as_bytes()); let tree = labeled(LABEL_ASSETS, witness); let mut serializer = serde_cbor::ser::Serializer::new(vec![]); serializer.self_describe().unwrap(); tree.serialize(&mut serializer) - .unwrap_or_else(|e| dfn_core::api::trap_with(&format!("failed to serialize a hash tree: {e}"))); + .unwrap_or_else(|e| ic_cdk::api::trap(&format!("failed to serialize a hash tree: {e}"))); ( "IC-Certificate".to_string(), format!( @@ -419,7 +416,7 @@ pub fn insert_tar_xz(compressed: Vec) { .to_vec(); let name = String::from_utf8(name_bytes.clone()).unwrap_or_else(|e| { - dfn_core::api::trap_with(&format!( + ic_cdk::api::trap(&format!( "non-utf8 file name {}: {}", String::from_utf8_lossy(&name_bytes), e @@ -463,7 +460,7 @@ impl StableState for Assets { fn update_root_hash(a: &AssetHashes) { let prefixed_root_hash = &labeled_hash(LABEL_ASSETS, &a.0.root_hash()); - dfn_core::api::set_certified_data(&prefixed_root_hash[..]); + ic_cdk::api::set_certified_data(&prefixed_root_hash[..]); } #[test] diff --git a/rs/backend/src/canisters/cmc.rs b/rs/backend/src/canisters/cmc.rs index 165b10f09f2..06bce5c3ce6 100644 --- a/rs/backend/src/canisters/cmc.rs +++ b/rs/backend/src/canisters/cmc.rs @@ -1,17 +1,16 @@ use crate::Cycles; use cycles_minting_canister::{NotifyCreateCanister, NotifyError, NotifyTopUp}; -use dfn_candid::candid; -use dfn_core::CanisterId; +use ic_base_types::CanisterId; use ic_nns_constants::CYCLES_MINTING_CANISTER_ID; pub async fn notify_create_canister(request: NotifyCreateCanister) -> Result, String> { - dfn_core::call(CYCLES_MINTING_CANISTER_ID, "notify_create_canister", candid, (request,)) + ic_cdk::call(CYCLES_MINTING_CANISTER_ID.into(), "notify_create_canister", (request,)) .await .map_err(|e| e.1) } pub async fn notify_top_up_canister(request: NotifyTopUp) -> Result, String> { - dfn_core::call(CYCLES_MINTING_CANISTER_ID, "notify_top_up", candid, (request,)) + ic_cdk::call(CYCLES_MINTING_CANISTER_ID.into(), "notify_top_up", (request,)) .await .map_err(|e| e.1) } diff --git a/rs/backend/src/canisters/exchange_rate_canister.rs b/rs/backend/src/canisters/exchange_rate_canister.rs index d620ac12c36..12f8fca6615 100644 --- a/rs/backend/src/canisters/exchange_rate_canister.rs +++ b/rs/backend/src/canisters/exchange_rate_canister.rs @@ -102,7 +102,7 @@ mod prod { use ic_nns_constants::EXCHANGE_RATE_CANISTER_ID; pub async fn get_exchange_rate(request: GetExchangeRateRequest) -> Result { - dfn_core::call(EXCHANGE_RATE_CANISTER_ID, "get_exchange_rate", candid, (request,)) + ic_cdk::call(EXCHANGE_RATE_CANISTER_ID, "get_exchange_rate", candid, (request,)) .await .map_err(|e| e.1) } diff --git a/rs/backend/src/canisters/governance.rs b/rs/backend/src/canisters/governance.rs index f2837592e61..7c2c6c19b32 100644 --- a/rs/backend/src/canisters/governance.rs +++ b/rs/backend/src/canisters/governance.rs @@ -8,7 +8,7 @@ pub use ic_nns_governance::pb::v1::{ pub async fn claim_or_refresh_neuron_from_account( request: ClaimOrRefreshNeuronFromAccount, ) -> Result { - dfn_core::call( + ic_cdk::call( GOVERNANCE_CANISTER_ID, "claim_or_refresh_neuron_from_account", candid, @@ -31,7 +31,7 @@ mod prod { use super::{candid, GetMetricsCallResult, GOVERNANCE_CANISTER_ID}; pub async fn get_metrics() -> GetMetricsCallResult { - dfn_core::call(GOVERNANCE_CANISTER_ID, "get_metrics", candid, ()) + ic_cdk::call(GOVERNANCE_CANISTER_ID, "get_metrics", candid, ()) .await .map_err(|e| e.1) } diff --git a/rs/backend/src/canisters/ledger.rs b/rs/backend/src/canisters/ledger.rs index 399431e3966..e694bfdf8c7 100644 --- a/rs/backend/src/canisters/ledger.rs +++ b/rs/backend/src/canisters/ledger.rs @@ -1,5 +1,5 @@ -use dfn_core::CanisterId; use dfn_protobuf::protobuf; +use ic_base_types::CanisterId; use ic_ledger_core::block::EncodedBlock; use ic_nns_constants::LEDGER_CANISTER_ID; use icp_ledger::protobuf::get_blocks_response::GetBlocksContent; @@ -11,7 +11,7 @@ use icp_ledger::{BlockIndex, GetBlocksArgs}; pub async fn tip_of_chain() -> Result { let response: TipOfChainResponsePb = - dfn_core::call(LEDGER_CANISTER_ID, "tip_of_chain_pb", protobuf, TipOfChainRequestPb {}) + ic_cdk::call(LEDGER_CANISTER_ID, "tip_of_chain_pb", protobuf, TipOfChainRequestPb {}) .await .map_err(|e| e.1)?; @@ -19,13 +19,13 @@ pub async fn tip_of_chain() -> Result { } pub async fn get_archive_index() -> Result { - dfn_core::call(LEDGER_CANISTER_ID, "get_archive_index_pb", protobuf, ()) + ic_cdk::call(LEDGER_CANISTER_ID, "get_archive_index_pb", protobuf, ()) .await .map_err(|e| e.1) } pub async fn get_blocks(canister_id: CanisterId, from: BlockIndex, length: u32) -> Result, String> { - let response: GetBlocksResponsePb = dfn_core::call( + let response: GetBlocksResponsePb = ic_cdk::call( canister_id, "get_blocks_pb", protobuf, diff --git a/rs/backend/src/ledger_sync.rs b/rs/backend/src/ledger_sync.rs index edf33e4828a..cab1c7ef4d4 100644 --- a/rs/backend/src/ledger_sync.rs +++ b/rs/backend/src/ledger_sync.rs @@ -1,7 +1,7 @@ use crate::canisters::ledger; use crate::state::{with_state, with_state_mut}; use candid::Principal; -use dfn_core::CanisterId; +use ic_base_types::CanisterId; use ic_cdk::println; use ic_ledger_core::block::BlockType; use ic_ledger_core::Tokens; diff --git a/rs/backend/src/main.rs b/rs/backend/src/main.rs index 6e96ca40dda..572cadd3a8f 100644 --- a/rs/backend/src/main.rs +++ b/rs/backend/src/main.rs @@ -15,10 +15,10 @@ use candid::candid_method; use accounts_store::schema::proxy::AccountsDbAsProxy; pub use candid::{CandidType, Deserialize}; -use dfn_candid::{candid, candid_one}; -use dfn_core::{over, over_async}; +//use dfn_candid::{candid, candid_one}; use ic_cdk::api::call::RejectionCode; use ic_cdk::{eprintln, println}; +//use ic_cdk::{over, over_async}; use ic_cdk_macros::{init, post_upgrade, pre_upgrade}; use icp_ledger::AccountIdentifier; pub use serde::Serialize; @@ -99,13 +99,15 @@ fn post_upgrade(args_maybe: Option) { println!("END post-upgrade"); } +/* #[export_name = "canister_query http_request"] pub fn http_request() { over(candid_one, http_request_impl); } +*/ #[candid_method(query, rename = "http_request")] -fn http_request_impl(req: assets::HttpRequest) -> assets::HttpResponse { +fn http_request(req: assets::HttpRequest) -> assets::HttpResponse { assets::http_request(req) } @@ -116,12 +118,12 @@ fn http_request_impl(req: assets::HttpRequest) -> assets::HttpResponse { /// accounts they have registered. #[export_name = "canister_query get_account"] pub fn get_account() { - over(candid, |()| get_account_impl()); + //over(candid, |()| get_account_impl()); } #[candid_method(query, rename = "get_account")] fn get_account_impl() -> GetAccountResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state(|s| match s.accounts_store.get_account(principal) { Some(account) => GetAccountResponse::Ok(account), None => GetAccountResponse::AccountNotFound, @@ -134,12 +136,12 @@ fn get_account_impl() -> GetAccountResponse { /// an account). #[export_name = "canister_update add_account"] fn add_account() { - over(candid, |()| add_account_impl()); + //over(candid, |()| add_account_impl()); } #[candid_method(update, rename = "add_account")] fn add_account_impl() -> AccountIdentifier { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.add_account(principal)); AccountIdentifier::from(principal) } @@ -151,12 +153,12 @@ fn add_account_impl() -> AccountIdentifier { /// ledger accounts is not derivable externally). #[export_name = "canister_update create_sub_account"] pub fn create_sub_account() { - over(candid_one, create_sub_account_impl); + //over(candid_one, create_sub_account_impl); } #[candid_method(update, rename = "create_sub_account")] fn create_sub_account_impl(sub_account_name: String) -> CreateSubAccountResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.create_sub_account(principal, sub_account_name)) } @@ -165,12 +167,12 @@ fn create_sub_account_impl(sub_account_name: String) -> CreateSubAccountResponse /// These aliases are not visible externally or to anyone else. #[export_name = "canister_update rename_sub_account"] pub fn rename_sub_account() { - over(candid_one, rename_sub_account_impl); + //over(candid_one, rename_sub_account_impl); } #[candid_method(update, rename = "rename_sub_account")] fn rename_sub_account_impl(request: RenameSubAccountRequest) -> RenameSubAccountResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.rename_sub_account(principal, request)) } @@ -181,88 +183,88 @@ fn rename_sub_account_impl(request: RenameSubAccountRequest) -> RenameSubAccount /// Some read-only calls do not require signing, e.g. viewing the account's ICP balance. #[export_name = "canister_update register_hardware_wallet"] pub fn register_hardware_wallet() { - over(candid_one, register_hardware_wallet_impl); + //over(candid_one, register_hardware_wallet_impl); } #[candid_method(update, rename = "register_hardware_wallet")] fn register_hardware_wallet_impl(request: RegisterHardwareWalletRequest) -> RegisterHardwareWalletResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.register_hardware_wallet(principal, request)) } /// Returns the list of canisters which the user has attached to their account. #[export_name = "canister_query get_canisters"] pub fn get_canisters() { - over(candid, |()| get_canisters_impl()); + //over(candid, |()| get_canisters_impl()); } #[candid_method(query, rename = "get_canisters")] fn get_canisters_impl() -> Vec { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.get_canisters(principal)) } /// Attaches a canister to the user's account. #[export_name = "canister_update attach_canister"] pub fn attach_canister() { - over(candid_one, attach_canister_impl); + //over(candid_one, attach_canister_impl); } #[candid_method(update, rename = "attach_canister")] fn attach_canister_impl(request: AttachCanisterRequest) -> AttachCanisterResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.attach_canister(principal, request)) } /// Renames a canister of the user. #[export_name = "canister_update rename_canister"] pub fn rename_canister() { - over(candid_one, rename_canister_impl); + //over(candid_one, rename_canister_impl); } #[candid_method(update, rename = "rename_canister")] fn rename_canister_impl(request: RenameCanisterRequest) -> RenameCanisterResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.rename_canister(principal, request)) } /// Detaches a canister from the user's account. #[export_name = "canister_update detach_canister"] pub fn detach_canister() { - over(candid_one, detach_canister_impl); + //over(candid_one, detach_canister_impl); } #[candid_method(update, rename = "detach_canister")] fn detach_canister_impl(request: DetachCanisterRequest) -> DetachCanisterResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.detach_canister(principal, request)) } #[export_name = "canister_update set_imported_tokens"] pub fn set_imported_tokens() { - over(candid_one, set_imported_tokens_impl); + //over(candid_one, set_imported_tokens_impl); } #[candid_method(update, rename = "set_imported_tokens")] fn set_imported_tokens_impl(settings: ImportedTokens) -> SetImportedTokensResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.set_imported_tokens(principal, settings)) } #[export_name = "canister_query get_imported_tokens"] pub fn get_imported_tokens() { - over(candid_one, |()| get_imported_tokens_impl()); + //over(candid_one, |()| get_imported_tokens_impl()); } #[candid_method(query, rename = "get_imported_tokens")] fn get_imported_tokens_impl() -> GetImportedTokensResponse { - let principal = dfn_core::api::caller(); + let principal = ic_cdk::api::caller(); with_state_mut(|s| s.accounts_store.get_imported_tokens(principal)) } #[export_name = "canister_update get_proposal_payload"] pub fn get_proposal_payload() { - over_async(candid_one, get_proposal_payload_impl); + //over_async(candid_one, get_proposal_payload_impl); } #[candid_method(update, rename = "get_proposal_payload")] @@ -276,7 +278,7 @@ async fn get_proposal_payload_impl(proposal_id: u64) -> Result stats::Stats { /// accounts, so this is not included in the general stats above. #[export_name = "canister_query get_histogram"] pub fn get_histogram() { - over(candid, |()| get_histogram_impl()); + //over(candid, |()| get_histogram_impl()); } #[must_use] @@ -303,7 +305,7 @@ pub fn get_histogram_impl() -> AccountsStoreHistogram { // - Users should make query calls. let is_query_call = ic_cdk::api::data_certificate().is_some(); if !is_query_call { - dfn_core::api::trap_with("Sorry, the histogram is available only as a query call."); + ic_cdk::api::trap("Sorry, the histogram is available only as a query call."); } // Gets the histogram: with_state(|state| state.accounts_store.get_histogram()) @@ -319,17 +321,17 @@ pub fn get_histogram_impl() -> AccountsStoreHistogram { pub fn canister_heartbeat() { let future = run_periodic_tasks(); - dfn_core::api::futures::spawn(future); + ic_cdk::spawn(future); let migration_in_progress = with_state_mut(|s| s.accounts_store.migration_in_progress()); if migration_in_progress { - dfn_core::api::futures::spawn(call_step_migration_with_retries()); + ic_cdk::spawn(call_step_migration_with_retries()); } } /// Steps the migration. #[export_name = "canister_update step_migration"] pub fn step_migration() { - over(candid_one, step_migration_impl); + //over(candid_one, step_migration_impl); } #[candid_method(update, rename = "step_migration")] @@ -337,7 +339,7 @@ fn step_migration_impl(step_size: u32) { let caller = ic_cdk::caller(); let own_canister_id = ic_cdk::api::id(); if caller != own_canister_id { - dfn_core::api::trap_with("Only the canister itself may call step_migration"); + ic_cdk::api::trap("Only the canister itself may call step_migration"); } with_state_mut(|s| { s.accounts_store.step_migration(step_size); @@ -366,7 +368,7 @@ async fn call_step_migration_with_retries() { /// Only a whitelist of assets are accepted. #[export_name = "canister_update add_stable_asset"] pub fn add_stable_asset() { - over(candid_one, add_stable_asset_impl); + //over(candid_one, add_stable_asset_impl); } #[candid_method(update, rename = "add_stable_asset")] @@ -387,7 +389,7 @@ fn add_stable_asset_impl(asset_bytes: Vec) { insert_asset("/assets/canvaskit/canvaskit.js", Asset::new_stable(asset_bytes)); } unknown_hash => { - dfn_core::api::trap_with(&format!("Unknown asset with hash {unknown_hash}")); + ic_cdk::api::trap(&format!("Unknown asset with hash {unknown_hash}")); } } } @@ -398,7 +400,7 @@ fn add_stable_asset_impl(asset_bytes: Vec) { /// - Permission to upload may be denied; see `may_upload()` for details. #[export_name = "canister_update add_assets_tar_xz"] pub fn add_assets_tar_xz() { - over(candid_one, add_assets_tar_xz_impl); + //over(candid_one, add_assets_tar_xz_impl); } /// # Panics @@ -426,10 +428,11 @@ fn add_assets_tar_xz_impl(asset_bytes: Vec) { #[cfg(any(test, feature = "toy_data_gen"))] #[export_name = "canister_update create_toy_accounts"] pub fn create_toy_accounts() { + /* over(candid_one, |num_accounts: u128| { let caller = ic_cdk::caller(); if !ic_cdk::api::is_controller(&caller) { - dfn_core::api::trap_with("Only the controller may generate toy accounts"); + ic_cdk::api::trap("Only the controller may generate toy accounts"); } with_state_mut(|s| { s.accounts_store @@ -438,13 +441,14 @@ pub fn create_toy_accounts() { })) }) }); + */ } /// Gets any toy account by toy account index. #[cfg(any(test, feature = "toy_data_gen"))] #[export_name = "canister_query get_toy_account"] pub fn get_toy_account() { - over(candid_one, get_toy_account_impl); + //over(candid_one, get_toy_account_impl); } #[cfg(any(test, feature = "toy_data_gen"))] @@ -452,7 +456,7 @@ pub fn get_toy_account() { fn get_toy_account_impl(toy_account_index: u64) -> GetAccountResponse { let caller = ic_cdk::caller(); if !ic_cdk::api::is_controller(&caller) { - dfn_core::api::trap_with("Only the controller may access toy accounts"); + ic_cdk::api::trap("Only the controller may access toy accounts"); } let principal = PrincipalId::new_user_test_id(toy_account_index); with_state(|s| match s.accounts_store.get_account(principal) { @@ -463,7 +467,7 @@ fn get_toy_account_impl(toy_account_index: u64) -> GetAccountResponse { #[export_name = "canister_query get_exceptional_transactions"] pub fn get_exceptional_transactions() { - over(candid, |()| get_exceptional_transactions_impl()); + //over(candid, |()| get_exceptional_transactions_impl()); } #[candid_method(query, rename = "get_exceptional_transactions")] @@ -478,7 +482,7 @@ fn get_exceptional_transactions_impl() -> Option> { #[export_name = "canister_query get_tvl"] pub fn get_tvl() { - over(candid, |()| get_tvl_impl()); + //over(candid, |()| get_tvl_impl()); } #[candid_method(query, rename = "get_tvl")] diff --git a/rs/backend/src/periodic_tasks_runner.rs b/rs/backend/src/periodic_tasks_runner.rs index b0fc851c037..7db35c1dc37 100644 --- a/rs/backend/src/periodic_tasks_runner.rs +++ b/rs/backend/src/periodic_tasks_runner.rs @@ -4,7 +4,7 @@ use crate::multi_part_transactions_processor::MultiPartTransactionToBeProcessed; use crate::state::with_state_mut; use crate::Cycles; use cycles_minting_canister::{NotifyCreateCanister, NotifyError, NotifyTopUp}; -use dfn_core::api::{CanisterId, PrincipalId}; +use ic_base_types::{CanisterId, PrincipalId}; use ic_nns_common::types::NeuronId; use ic_nns_governance::pb::v1::{claim_or_refresh_neuron_from_account_response, ClaimOrRefreshNeuronFromAccount}; use icp_ledger::{BlockIndex, Memo}; diff --git a/rs/backend/src/state/with_accounts_in_stable_memory.rs b/rs/backend/src/state/with_accounts_in_stable_memory.rs index 4ab3594dbcd..19d10b2c172 100644 --- a/rs/backend/src/state/with_accounts_in_stable_memory.rs +++ b/rs/backend/src/state/with_accounts_in_stable_memory.rs @@ -2,7 +2,7 @@ use super::State; use crate::state::partitions::{PartitionType, PartitionsMaybe}; use crate::state::StableState; -use dfn_core::api::trap_with; +use ic_cdk::api::trap; use ic_cdk::println; use ic_stable_structures::memory_manager::VirtualMemory; use ic_stable_structures::{DefaultMemoryImpl, Memory}; @@ -17,7 +17,7 @@ impl State { let len = bytes.len(); let length_field = u64::try_from(len) .unwrap_or_else(|e| { - trap_with(&format!( + trap(&format!( "The serialized memory takes more than 2**64 bytes. Amazing: {e:?}" )); }) @@ -27,7 +27,7 @@ impl State { } PartitionsMaybe::None(_) => { println!("END state::save_heap: ()"); - trap_with("No memory manager found. Cannot save heap."); + trap("No memory manager found. Cannot save heap."); } } } @@ -46,7 +46,7 @@ impl State { candid_bytes }; State::decode(candid_bytes).unwrap_or_else(|e| { - trap_with(&format!("Decoding stable memory failed. Error: {e:?}")); + trap(&format!("Decoding stable memory failed. Error: {e:?}")); }) } } diff --git a/rs/proposals/Cargo.toml b/rs/proposals/Cargo.toml index 00657deeea8..33e96d60ae0 100644 --- a/rs/proposals/Cargo.toml +++ b/rs/proposals/Cargo.toml @@ -15,7 +15,6 @@ serde_json = "1.0.127" cycles-minting-canister = { workspace = true } dfn_candid = { workspace = true } -dfn_core = { workspace = true } ic-base-types = { workspace = true } ic-btc-interface = "0.2.0" ic-crypto-sha2 = { workspace = true } diff --git a/rs/sns_aggregator/Cargo.toml b/rs/sns_aggregator/Cargo.toml index a9dc5f0e175..61b84c916d4 100644 --- a/rs/sns_aggregator/Cargo.toml +++ b/rs/sns_aggregator/Cargo.toml @@ -12,7 +12,7 @@ anyhow = "1.0.86" base64 = "0.22.1" candid = "0.10.10" dfn_candid = { workspace = true } -dfn_core = { workspace = true } +ic-base-types = { workspace = true } # This next candid is 0.9.0_beta code that fixes serde Nat but has other issues. Keep checking until the issues are fixed. #candid = { git = "https://github.com/dfinity/candid" , rev = "42ffed660ded37585c4b9f97e3ce90919e24c518" } ic-cdk = { version = "0.16.0" } diff --git a/rs/sns_aggregator/src/lib.rs b/rs/sns_aggregator/src/lib.rs index 007f67d6ea7..cda5f84ed06 100644 --- a/rs/sns_aggregator/src/lib.rs +++ b/rs/sns_aggregator/src/lib.rs @@ -17,10 +17,11 @@ use std::time::Duration; use assets::{insert_favicon, insert_home_page, AssetHashes, HttpRequest, HttpResponse}; use candid::{candid_method, export_service, CandidType, Principal}; -use dfn_core::api::{call, CanisterId}; use fast_scheduler::FastScheduler; +use ic_cdk::api::call::call; +use ic_cdk::api::management_canister::main::CanisterIdRecord; use ic_cdk_timers::{clear_timer, set_timer, set_timer_interval}; -use ic_management_canister_types::{CanisterIdRecord, IC_00}; +use ic_management_canister_types::IC_00; use serde::Deserialize; use state::{Config, StableState, STATE}; use types::Icrc1Value; @@ -84,9 +85,11 @@ struct CanisterStatusResultV2 { #[ic_cdk_macros::update] #[allow(clippy::panic)] // This is a readonly function, only a rather arcane reason prevents it from being a query call. async fn get_canister_status() -> CanisterStatusResultV2 { - let own_canister_id = dfn_core::api::id(); - let canister_id_record: CanisterIdRecord = CanisterId::unchecked_from_principal(own_canister_id.get()).into(); - let result = call(IC_00, "canister_status", dfn_candid::candid, (canister_id_record,)).await; + let own_canister_id = ic_cdk::api::id(); + let canister_id_record = CanisterIdRecord { + canister_id: own_canister_id, + }; + let result = call(IC_00, "canister_status", (canister_id_record,)).await; result.unwrap_or_else(|err| panic!("Couldn't get canister_status of {own_canister_id}. Err: {err:#?}")) }