From bd65a6a811f5c1b6de79cd370ef82edec9edb167 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Wed, 4 Dec 2024 14:47:09 -0500 Subject: [PATCH] move back management_canister mod --- Cargo.toml | 4 +- e2e-tests/Cargo.toml | 1 - e2e-tests/src/bin/call_struct.rs | 2 +- e2e-tests/src/bin/canister_info.rs | 2 +- e2e-tests/src/bin/chunk.rs | 4 +- e2e-tests/src/bin/management_caller.rs | 6 +- e2e-tests/tests/canister_info.rs | 4 +- ic-cdk-management-canister/Cargo.toml | 23 --- ic-cdk-management-canister/LICENSE | 1 - ic-cdk-management-canister/README.md | 7 - ic-cdk-timers/src/lib.rs | 2 +- .../api/management_canister}/bitcoin/mod.rs | 45 +++-- .../api/management_canister}/bitcoin/types.rs | 0 .../src/api/management_canister}/ecdsa/mod.rs | 21 +- .../api/management_canister}/ecdsa/types.rs | 2 +- .../management_canister}/http_request/mod.rs | 15 +- .../http_request/types.rs | 6 +- .../src/api/management_canister/main}/mod.rs | 184 ++++++++---------- .../api/management_canister/main}/types.rs | 21 +- .../src/api/management_canister/mod.rs | 5 +- .../api/management_canister}/provisional.rs | 18 +- .../api/management_canister}/schnorr/mod.rs | 26 +-- .../api/management_canister}/schnorr/types.rs | 2 +- ic-cdk/src/api/mod.rs | 1 + library/ic-certified-map/src/rbtree.rs | 1 + rust-toolchain.toml | 2 +- 26 files changed, 187 insertions(+), 218 deletions(-) delete mode 100644 ic-cdk-management-canister/Cargo.toml delete mode 120000 ic-cdk-management-canister/LICENSE delete mode 100644 ic-cdk-management-canister/README.md rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/bitcoin/mod.rs (87%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/bitcoin/types.rs (100%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/ecdsa/mod.rs (73%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/ecdsa/types.rs (98%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/http_request/mod.rs (94%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/http_request/types.rs (95%) rename {ic-cdk-management-canister/src/core => ic-cdk/src/api/management_canister/main}/mod.rs (68%) rename {ic-cdk-management-canister/src/core => ic-cdk/src/api/management_canister/main}/types.rs (97%) rename ic-cdk-management-canister/src/lib.rs => ic-cdk/src/api/management_canister/mod.rs (89%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/provisional.rs (87%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/schnorr/mod.rs (75%) rename {ic-cdk-management-canister/src => ic-cdk/src/api/management_canister}/schnorr/types.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 0605dfddc..9c83ffd22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ members = [ "ic-cdk", "ic-cdk-bindgen", "ic-cdk-macros", - "ic-cdk-management-canister", "ic-cdk-timers", "ic0", "library/*", @@ -19,7 +18,7 @@ repository = "https://github.com/dfinity/cdk-rs" # MSRV # Avoid updating this field unless we use new Rust features # Sync with rust-toolchain.toml -rust-version = "1.75.0" +rust-version = "1.78.0" license = "Apache-2.0" [profile.canister-release] @@ -32,7 +31,6 @@ opt-level = 'z' [workspace.dependencies] ic0 = { path = "ic0", version = "0.24.0-alpha.1" } ic-cdk = { path = "ic-cdk", version = "0.18.0-alpha.1" } -ic-cdk-management-canister = { path = "ic-cdk-management-canister", version = "0.1.0-alpha.1" } ic-cdk-timers = { path = "ic-cdk-timers", version = "0.12.0-alpha.1" } candid = "0.10.4" diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index 6f3c580fa..37603ef8b 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -13,7 +13,6 @@ candid.workspace = true cargo_metadata = "0.18" escargot = { version = "0.5.7", features = ["print"] } ic-cdk.workspace = true -ic-cdk-management-canister.workspace = true ic-cdk-timers.workspace = true lazy_static = "1.4.0" serde_bytes.workspace = true diff --git a/e2e-tests/src/bin/call_struct.rs b/e2e-tests/src/bin/call_struct.rs index e89a29965..96ad57641 100644 --- a/e2e-tests/src/bin/call_struct.rs +++ b/e2e-tests/src/bin/call_struct.rs @@ -1,6 +1,6 @@ use candid::Principal; +use ic_cdk::api::management_canister::main::{CanisterIdRecord, CreateCanisterArgument}; use ic_cdk::prelude::*; -use ic_cdk_management_canister::core::{CanisterIdRecord, CreateCanisterArgument}; #[update] async fn create_canister_via_struct() -> Principal { diff --git a/e2e-tests/src/bin/canister_info.rs b/e2e-tests/src/bin/canister_info.rs index 163fef972..9a4bc2078 100644 --- a/e2e-tests/src/bin/canister_info.rs +++ b/e2e-tests/src/bin/canister_info.rs @@ -1,5 +1,5 @@ use candid::Principal; -use ic_cdk_management_canister::core::{ +use ic_cdk::api::management_canister::main::{ canister_info, create_canister, install_code, uninstall_code, update_settings, CanisterIdRecord, CanisterInfoRequest, CanisterInfoResponse, CanisterInstallMode::{Install, Reinstall, Upgrade}, diff --git a/e2e-tests/src/bin/chunk.rs b/e2e-tests/src/bin/chunk.rs index 142ddfe3b..8eb977cdf 100644 --- a/e2e-tests/src/bin/chunk.rs +++ b/e2e-tests/src/bin/chunk.rs @@ -1,10 +1,10 @@ use candid::Principal; -use ic_cdk::update; -use ic_cdk_management_canister::core::{ +use ic_cdk::api::management_canister::main::{ clear_chunk_store, create_canister, install_chunked_code, stored_chunks, upload_chunk, CanisterInstallMode, ChunkHash, ClearChunkStoreArgument, CreateCanisterArgument, InstallChunkedCodeArgument, StoredChunksArgument, UploadChunkArgument, }; +use ic_cdk::update; #[update] async fn call_create_canister() -> Principal { diff --git a/e2e-tests/src/bin/management_caller.rs b/e2e-tests/src/bin/management_caller.rs index fec75bb63..1add9484f 100644 --- a/e2e-tests/src/bin/management_caller.rs +++ b/e2e-tests/src/bin/management_caller.rs @@ -5,7 +5,7 @@ use ic_cdk::prelude::*; /// - chunk.rs mod main { use super::*; - use ic_cdk_management_canister::core::*; + use ic_cdk::api::management_canister::main::*; #[update] async fn execute_main_methods() { let arg = CreateCanisterArgument { @@ -77,7 +77,7 @@ mod main { mod provisional { use super::*; - use ic_cdk_management_canister::{core::LogVisibility, provisional::*}; + use ic_cdk::api::management_canister::{main::LogVisibility, provisional::*}; #[update] async fn execute_provisional_methods() { @@ -110,7 +110,7 @@ mod provisional { mod snapshot { use super::*; - use ic_cdk_management_canister::core::*; + use ic_cdk::api::management_canister::main::*; #[update] async fn execute_snapshot_methods() { diff --git a/e2e-tests/tests/canister_info.rs b/e2e-tests/tests/canister_info.rs index 18d8d7361..827ee0689 100644 --- a/e2e-tests/tests/canister_info.rs +++ b/e2e-tests/tests/canister_info.rs @@ -1,12 +1,12 @@ use candid::Principal; -use ic_cdk_e2e_tests::cargo_build_canister; -use ic_cdk_management_canister::core::{ +use ic_cdk::api::management_canister::main::{ CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, CanisterIdRecord, CanisterInfoResponse, CanisterInstallMode, CodeDeploymentMode::{Install, Reinstall, Upgrade}, CodeDeploymentRecord, ControllersChangeRecord, CreationRecord, FromCanisterRecord, FromUserRecord, InstallCodeArgument, }; +use ic_cdk_e2e_tests::cargo_build_canister; use pocket_ic::common::rest::RawEffectivePrincipal; use pocket_ic::{call_candid, call_candid_as, PocketIc}; use std::time::UNIX_EPOCH; diff --git a/ic-cdk-management-canister/Cargo.toml b/ic-cdk-management-canister/Cargo.toml deleted file mode 100644 index ee2ccdb25..000000000 --- a/ic-cdk-management-canister/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "ic-cdk-management-canister" -version = "0.1.0-alpha.1" -authors.workspace = true -edition.workspace = true -repository.workspace = true -rust-version.workspace = true -license.workspace = true -description = "Call IC Management Canister APIs." -homepage = "https://docs.rs/ic-cdk-management-canister" -documentation = "https://docs.rs/ic-cdk-management-canister" -readme = "README.md" -categories = [ - "api-bindings", - "data-structures" -] -keywords = ["internet-computer", "types", "dfinity", "canister", "cdk"] - -[dependencies] -candid.workspace = true -ic-cdk.workspace = true -serde.workspace = true -serde_bytes.workspace = true diff --git a/ic-cdk-management-canister/LICENSE b/ic-cdk-management-canister/LICENSE deleted file mode 120000 index ea5b60640..000000000 --- a/ic-cdk-management-canister/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/ic-cdk-management-canister/README.md b/ic-cdk-management-canister/README.md deleted file mode 100644 index 891b15661..000000000 --- a/ic-cdk-management-canister/README.md +++ /dev/null @@ -1,7 +0,0 @@ -[![Documentation](https://docs.rs/ic-cdk-management-canister/badge.svg)](https://docs.rs/ic-cdk-management-canister/) -[![Crates.io](https://img.shields.io/crates/v/ic-cdk-management-canister.svg)](https://crates.io/crates/ic-cdk-management-canister) -[![License](https://img.shields.io/crates/l/ic-cdk-management-canister.svg)](https://github.com/dfinity/cdk-rs/blob/main/src/ic-cdk-management-canister/LICENSE) -[![Downloads](https://img.shields.io/crates/d/ic-cdk-management-canister.svg)](https://crates.io/crates/ic-cdk-management-canister) -[![CI](https://github.com/dfinity/cdk-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/dfinity/cdk-rs/actions/workflows/ci.yml) - -# ic-cdk-management-canister diff --git a/ic-cdk-timers/src/lib.rs b/ic-cdk-timers/src/lib.rs index a60ab6693..7d7a149dc 100644 --- a/ic-cdk-timers/src/lib.rs +++ b/ic-cdk-timers/src/lib.rs @@ -38,7 +38,7 @@ use ic_cdk::api::call::RejectionCode; thread_local! { static TASKS: RefCell> = RefCell::default(); static TIMERS: RefCell> = RefCell::default(); - static MOST_RECENT: Cell> = Cell::new(None); + static MOST_RECENT: Cell> = const { Cell::new(None) }; } enum Task { diff --git a/ic-cdk-management-canister/src/bitcoin/mod.rs b/ic-cdk/src/api/management_canister/bitcoin/mod.rs similarity index 87% rename from ic-cdk-management-canister/src/bitcoin/mod.rs rename to ic-cdk/src/api/management_canister/bitcoin/mod.rs index 835e834a7..4769f17ee 100644 --- a/ic-cdk-management-canister/src/bitcoin/mod.rs +++ b/ic-cdk/src/api/management_canister/bitcoin/mod.rs @@ -2,8 +2,8 @@ //! //! Check [Bitcoin integration](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api) for more details. +use crate::api::call::{call_with_payment128, CallResult}; use candid::Principal; -use ic_cdk::prelude::*; mod types; pub use types::*; @@ -34,11 +34,13 @@ pub async fn bitcoin_get_balance(arg: GetBalanceRequest) -> CallResult<(Satoshi, BitcoinNetwork::Testnet => GET_BALANCE_TESTNET, BitcoinNetwork::Regtest => 0, }; - Call::new(Principal::management_canister(), "bitcoin_get_balance") - .with_cycles(cycles) - .with_args((arg,)) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "bitcoin_get_balance", + (arg,), + cycles, + ) + .await } /// See [IC method `bitcoin_get_utxos`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_utxos). @@ -52,11 +54,13 @@ pub async fn bitcoin_get_utxos(arg: GetUtxosRequest) -> CallResult<(GetUtxosResp BitcoinNetwork::Testnet => GET_UTXO_TESTNET, BitcoinNetwork::Regtest => 0, }; - Call::new(Principal::management_canister(), "bitcoin_get_utxos") - .with_cycles(cycles) - .with_args((arg,)) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "bitcoin_get_utxos", + (arg,), + cycles, + ) + .await } fn send_transaction_fee(arg: &SendTransactionRequest) -> u128 { @@ -81,11 +85,13 @@ fn send_transaction_fee(arg: &SendTransactionRequest) -> u128 { /// Check [API fees & Pricing](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api-fees--pricing) for more details. pub async fn bitcoin_send_transaction(arg: SendTransactionRequest) -> CallResult<()> { let cycles = send_transaction_fee(&arg); - Call::new(Principal::management_canister(), "bitcoin_send_transaction") - .with_cycles(cycles) - .with_args((arg,)) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "bitcoin_send_transaction", + (arg,), + cycles, + ) + .await } /// See [IC method `bitcoin_get_current_fee_percentiles`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_current_fee_percentiles). @@ -101,12 +107,11 @@ pub async fn bitcoin_get_current_fee_percentiles( BitcoinNetwork::Testnet => GET_CURRENT_FEE_PERCENTILES_TESTNET, BitcoinNetwork::Regtest => 0, }; - Call::new( + call_with_payment128( Principal::management_canister(), "bitcoin_get_current_fee_percentiles", + (arg,), + cycles, ) - .with_cycles(cycles) - .with_args((arg,)) - .call() .await } diff --git a/ic-cdk-management-canister/src/bitcoin/types.rs b/ic-cdk/src/api/management_canister/bitcoin/types.rs similarity index 100% rename from ic-cdk-management-canister/src/bitcoin/types.rs rename to ic-cdk/src/api/management_canister/bitcoin/types.rs diff --git a/ic-cdk-management-canister/src/ecdsa/mod.rs b/ic-cdk/src/api/management_canister/ecdsa/mod.rs similarity index 73% rename from ic-cdk-management-canister/src/ecdsa/mod.rs rename to ic-cdk/src/api/management_canister/ecdsa/mod.rs index 5b46b9543..4be77769c 100644 --- a/ic-cdk-management-canister/src/ecdsa/mod.rs +++ b/ic-cdk/src/api/management_canister/ecdsa/mod.rs @@ -1,7 +1,7 @@ //! Threshold ECDSA signing API. +use crate::api::call::{call, call_with_payment128, CallResult}; use candid::Principal; -use ic_cdk::prelude::*; mod types; pub use types::*; @@ -14,11 +14,7 @@ const SIGN_WITH_ECDSA_FEE: u128 = 26_153_846_153; pub async fn ecdsa_public_key( arg: EcdsaPublicKeyArgument, ) -> CallResult<(EcdsaPublicKeyResponse,)> { - Call::new(Principal::management_canister(), "ecdsa_public_key") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "ecdsa_public_key", (arg,)).await } /// Return a new ECDSA signature of the given message_hash that can be separately verified against a derived ECDSA public key. @@ -29,10 +25,11 @@ pub async fn ecdsa_public_key( /// This method handles the cycles cost under the hood. /// Check [Threshold signatures](https://internetcomputer.org/docs/current/references/t-sigs-how-it-works) for more details. pub async fn sign_with_ecdsa(arg: SignWithEcdsaArgument) -> CallResult<(SignWithEcdsaResponse,)> { - Call::new(Principal::management_canister(), "sign_with_ecdsa") - .with_guaranteed_response() - .with_args((arg,)) - .with_cycles(SIGN_WITH_ECDSA_FEE) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "sign_with_ecdsa", + (arg,), + SIGN_WITH_ECDSA_FEE, + ) + .await } diff --git a/ic-cdk-management-canister/src/ecdsa/types.rs b/ic-cdk/src/api/management_canister/ecdsa/types.rs similarity index 98% rename from ic-cdk-management-canister/src/ecdsa/types.rs rename to ic-cdk/src/api/management_canister/ecdsa/types.rs index 9d6ddf8ee..395e3f5f4 100644 --- a/ic-cdk-management-canister/src/ecdsa/types.rs +++ b/ic-cdk/src/api/management_canister/ecdsa/types.rs @@ -1,7 +1,7 @@ use candid::CandidType; use serde::{Deserialize, Serialize}; -use crate::CanisterId; +use super::super::main::CanisterId; /// Argument type of [ecdsa_public_key](super::ecdsa_public_key). #[derive( diff --git a/ic-cdk-management-canister/src/http_request/mod.rs b/ic-cdk/src/api/management_canister/http_request/mod.rs similarity index 94% rename from ic-cdk-management-canister/src/http_request/mod.rs rename to ic-cdk/src/api/management_canister/http_request/mod.rs index 354dbc193..48e214d2e 100644 --- a/ic-cdk-management-canister/src/http_request/mod.rs +++ b/ic-cdk/src/api/management_canister/http_request/mod.rs @@ -1,7 +1,6 @@ //! Canister HTTP request. -use ic_cdk::prelude::*; - +use crate::api::call::{call_with_payment128, CallResult}; use candid::Principal; #[cfg(feature = "transform-closure")] use slotmap::{DefaultKey, Key, KeyData, SlotMap}; @@ -21,11 +20,13 @@ pub async fn http_request( arg: CanisterHttpRequestArgument, cycles: u128, ) -> CallResult<(HttpResponse,)> { - Call::new(Principal::management_canister(), "http_request") - .with_args((arg,)) - .with_cycles(cycles) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "http_request", + (arg,), + cycles, + ) + .await } #[cfg(feature = "transform-closure")] diff --git a/ic-cdk-management-canister/src/http_request/types.rs b/ic-cdk/src/api/management_canister/http_request/types.rs similarity index 95% rename from ic-cdk-management-canister/src/http_request/types.rs rename to ic-cdk/src/api/management_canister/http_request/types.rs index 07f7fb4c1..1e4fafe8c 100644 --- a/ic-cdk-management-canister/src/http_request/types.rs +++ b/ic-cdk/src/api/management_canister/http_request/types.rs @@ -1,3 +1,4 @@ +use crate::id; use candid::CandidType; use serde::{Deserialize, Serialize}; @@ -47,14 +48,13 @@ pub struct TransformContext { } impl TransformContext { - /// Constructs a TransformContext from a name and context. - /// The principal is assumed to be the current canister's id. + /// Constructs a TransformContext from a name and context. The principal is assumed to be the [current canister's](id). pub fn from_name(candid_function_name: String, context: Vec) -> Self { Self { context, function: TransformFunc(candid::Func { method: candid_function_name, - principal: ic_cdk::api::id(), + principal: id(), }), } } diff --git a/ic-cdk-management-canister/src/core/mod.rs b/ic-cdk/src/api/management_canister/main/mod.rs similarity index 68% rename from ic-cdk-management-canister/src/core/mod.rs rename to ic-cdk/src/api/management_canister/main/mod.rs index 1093a284b..283608686 100644 --- a/ic-cdk-management-canister/src/core/mod.rs +++ b/ic-cdk/src/api/management_canister/main/mod.rs @@ -5,9 +5,9 @@ //! //! [1]: https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-management-canister +use crate::api::call::{call, call_with_payment128, CallResult}; +use crate::api::canister_version; use candid::Principal; -use ic_cdk::api::canister_version; -use ic_cdk::prelude::*; mod types; pub use types::*; @@ -26,12 +26,13 @@ pub async fn create_canister( settings: arg.settings, sender_canister_version: Some(canister_version()), }; - Call::new(Principal::management_canister(), "create_canister") - .with_guaranteed_response() - .with_args((extended_arg,)) - .with_cycles(cycles) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "create_canister", + (extended_arg,), + cycles, + ) + .await } /// Update the settings of a canister. @@ -43,38 +44,32 @@ pub async fn update_settings(arg: UpdateSettingsArgument) -> CallResult<()> { settings: arg.settings, sender_canister_version: Some(canister_version()), }; - Call::new(Principal::management_canister(), "update_settings") - .with_guaranteed_response() - .with_args((extended_arg,)) - .call() - .await + call( + Principal::management_canister(), + "update_settings", + (extended_arg,), + ) + .await } /// See [IC method `upload_chunk`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-upload_chunk). pub async fn upload_chunk(arg: UploadChunkArgument) -> CallResult<(ChunkHash,)> { - Call::new(Principal::management_canister(), "upload_chunk") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "upload_chunk", (arg,)).await } /// See [IC method `clear_chunk_store`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-clear_chunk_store). pub async fn clear_chunk_store(arg: ClearChunkStoreArgument) -> CallResult<()> { - Call::new(Principal::management_canister(), "clear_chunk_store") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "clear_chunk_store", + (arg,), + ) + .await } /// See [IC method `stored_chunks`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-stored_chunks). pub async fn stored_chunks(arg: StoredChunksArgument) -> CallResult<(Vec,)> { - Call::new(Principal::management_canister(), "stored_chunks") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "stored_chunks", (arg,)).await } /// Install code into a canister. @@ -88,11 +83,12 @@ pub async fn install_code(arg: InstallCodeArgument) -> CallResult<()> { arg: arg.arg, sender_canister_version: Some(canister_version()), }; - Call::new(Principal::management_canister(), "install_code") - .with_guaranteed_response() - .with_args((extended_arg,)) - .call() - .await + call( + Principal::management_canister(), + "install_code", + (extended_arg,), + ) + .await } /// Install code into a canister where the code has previously been uploaded in chunks. @@ -108,11 +104,12 @@ pub async fn install_chunked_code(arg: InstallChunkedCodeArgument) -> CallResult arg: arg.arg, sender_canister_version: Some(canister_version()), }; - Call::new(Principal::management_canister(), "install_chunked_code") - .with_guaranteed_response() - .with_args((extended_arg,)) - .call() - .await + call( + Principal::management_canister(), + "install_chunked_code", + (extended_arg,), + ) + .await } /// Remove a canister's code and state, making the canister empty again. @@ -123,55 +120,40 @@ pub async fn uninstall_code(arg: CanisterIdRecord) -> CallResult<()> { canister_id: arg.canister_id, sender_canister_version: Some(canister_version()), }; - Call::new(Principal::management_canister(), "uninstall_code") - .with_guaranteed_response() - .with_args((extended_arg,)) - .call() - .await + call( + Principal::management_canister(), + "uninstall_code", + (extended_arg,), + ) + .await } /// Start a canister if the canister status was `stopped` or `stopping`. /// /// See [IC method `start_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-start_canister). pub async fn start_canister(arg: CanisterIdRecord) -> CallResult<()> { - Call::new(Principal::management_canister(), "start_canister") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "start_canister", (arg,)).await } /// Stop a canister. /// /// See [IC method `stop_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-stop_canister). pub async fn stop_canister(arg: CanisterIdRecord) -> CallResult<()> { - Call::new(Principal::management_canister(), "stop_canister") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "stop_canister", (arg,)).await } /// Get status information about the canister. /// /// See [IC method `canister_status`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-canister_status). pub async fn canister_status(arg: CanisterIdRecord) -> CallResult<(CanisterStatusResponse,)> { - Call::new(Principal::management_canister(), "canister_status") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "canister_status", (arg,)).await } /// Delete a canister from the IC. /// /// See [IC method `delete_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-delete_canister). pub async fn delete_canister(arg: CanisterIdRecord) -> CallResult<()> { - Call::new(Principal::management_canister(), "delete_canister") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "delete_canister", (arg,)).await } /// Deposit cycles into the specified canister. @@ -181,34 +163,27 @@ pub async fn delete_canister(arg: CanisterIdRecord) -> CallResult<()> { /// /// See [IC method `deposit_cycles`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-deposit_cycles). pub async fn deposit_cycles(arg: CanisterIdRecord, cycles: u128) -> CallResult<()> { - Call::new(Principal::management_canister(), "deposit_cycles") - .with_guaranteed_response() - .with_args((arg,)) - .with_cycles(cycles) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "deposit_cycles", + (arg,), + cycles, + ) + .await } /// Get 32 pseudo-random bytes. /// /// See [IC method `raw_rand`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-raw_rand). pub async fn raw_rand() -> CallResult<(Vec,)> { - Call::new(Principal::management_canister(), "raw_rand") - .with_guaranteed_response() - .with_args(()) - .call() - .await + call(Principal::management_canister(), "raw_rand", ()).await } /// Get public information about the canister. /// /// See [IC method `canister_info`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-canister_info). pub async fn canister_info(arg: CanisterInfoRequest) -> CallResult<(CanisterInfoResponse,)> { - Call::new(Principal::management_canister(), "canister_info") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call(Principal::management_canister(), "canister_info", (arg,)).await } /// Take a snapshot of the specified canister. @@ -217,11 +192,12 @@ pub async fn canister_info(arg: CanisterInfoRequest) -> CallResult<(CanisterInfo /// /// See [IC method `take_canister_snapshot`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-take_canister_snapshot). pub async fn take_canister_snapshot(arg: TakeCanisterSnapshotArgs) -> CallResult<(Snapshot,)> { - Call::new(Principal::management_canister(), "take_canister_snapshot") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "take_canister_snapshot", + (arg,), + ) + .await } /// Load a snapshot onto the canister. @@ -230,22 +206,24 @@ pub async fn take_canister_snapshot(arg: TakeCanisterSnapshotArgs) -> CallResult /// /// See [IC method `load_canister_snapshot`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-load_canister_snapshot). pub async fn load_canister_snapshot(arg: LoadCanisterSnapshotArgs) -> CallResult<()> { - Call::new(Principal::management_canister(), "load_canister_snapshot") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "load_canister_snapshot", + (arg,), + ) + .await } /// List the snapshots of the canister. /// /// See [IC method `list_canister_snapshots`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-list_canister_snapshots). pub async fn list_canister_snapshots(arg: CanisterIdRecord) -> CallResult<(Vec,)> { - Call::new(Principal::management_canister(), "list_canister_snapshots") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "list_canister_snapshots", + (arg,), + ) + .await } /// Delete a specified snapshot that belongs to an existing canister. @@ -254,9 +232,17 @@ pub async fn list_canister_snapshots(arg: CanisterIdRecord) -> CallResult<(Vec CallResult<()> { - Call::new(Principal::management_canister(), "delete_canister_snapshot") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "delete_canister_snapshot", + (arg,), + ) + .await +} + +/// Get subnet metadata. +/// +/// See [IC method `subnet_info`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-subnet-info). +pub async fn subnet_info(arg: SubnetInfoArgs) -> CallResult<(SubnetInfoResult,)> { + call(Principal::management_canister(), "subnet_info", (arg,)).await } diff --git a/ic-cdk-management-canister/src/core/types.rs b/ic-cdk/src/api/management_canister/main/types.rs similarity index 97% rename from ic-cdk-management-canister/src/core/types.rs rename to ic-cdk/src/api/management_canister/main/types.rs index 1a8de046c..3b9c701c9 100644 --- a/ic-cdk-management-canister/src/core/types.rs +++ b/ic-cdk/src/api/management_canister/main/types.rs @@ -1,7 +1,8 @@ use candid::{CandidType, Nat, Principal}; use serde::{Deserialize, Serialize}; -use crate::CanisterId; +/// Canister ID is Principal. +pub type CanisterId = Principal; /// todo #[derive( @@ -627,3 +628,21 @@ pub struct DeleteCanisterSnapshotArgs { /// ID of the snapshot to be deleted. pub snapshot_id: SnapshotId, } + +/// Argument type of [subnet_info](super::subnet_info). +#[derive( + CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, +)] +pub struct SubnetInfoArgs { + /// Principal of the subnet. + pub subnet_id: Principal, +} + +/// Result type of [subnet_info](super::subnet_info). +#[derive( + CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, +)] +pub struct SubnetInfoResult { + /// Replica version of the subnet. + pub replica_version: String, +} diff --git a/ic-cdk-management-canister/src/lib.rs b/ic-cdk/src/api/management_canister/mod.rs similarity index 89% rename from ic-cdk-management-canister/src/lib.rs rename to ic-cdk/src/api/management_canister/mod.rs index 802a77e1e..dd9c83a77 100644 --- a/ic-cdk-management-canister/src/lib.rs +++ b/ic-cdk/src/api/management_canister/mod.rs @@ -11,11 +11,8 @@ //! [2]: https://internetcomputer.org/assets/files/ic-a45d11feb0ba0494055083f9d2d21ddf.did pub mod bitcoin; -pub mod core; pub mod ecdsa; pub mod http_request; +pub mod main; pub mod provisional; pub mod schnorr; - -/// Canister ID is Principal. -pub type CanisterId = candid::Principal; diff --git a/ic-cdk-management-canister/src/provisional.rs b/ic-cdk/src/api/management_canister/provisional.rs similarity index 87% rename from ic-cdk-management-canister/src/provisional.rs rename to ic-cdk/src/api/management_canister/provisional.rs index 30622dd42..504648fb1 100644 --- a/ic-cdk-management-canister/src/provisional.rs +++ b/ic-cdk/src/api/management_canister/provisional.rs @@ -1,12 +1,10 @@ //! Provisional functions only available in local development instances. -use ic_cdk::prelude::*; - +use crate::api::call::{call, CallResult}; use candid::{CandidType, Nat, Principal}; use serde::{Deserialize, Serialize}; -pub use super::core::{CanisterIdRecord, CanisterSettings}; -use crate::CanisterId; +pub use super::main::{CanisterId, CanisterIdRecord, CanisterSettings}; /// Argument type of [provisional_create_canister_with_cycles]. #[derive( @@ -38,13 +36,11 @@ pub struct ProvisionalTopUpCanisterArgument { pub async fn provisional_create_canister_with_cycles( arg: ProvisionalCreateCanisterWithCyclesArgument, ) -> CallResult<(CanisterIdRecord,)> { - Call::new( + call( Principal::management_canister(), "provisional_create_canister_with_cycles", + (arg,), ) - .with_guaranteed_response() - .with_args((arg,)) - .call() .await } @@ -54,12 +50,10 @@ pub async fn provisional_create_canister_with_cycles( /// /// See [IC method `provisional_top_up_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-provisional_top_up_canister). pub async fn provisional_top_up_canister(arg: ProvisionalTopUpCanisterArgument) -> CallResult<()> { - Call::new( + call( Principal::management_canister(), "provisional_top_up_canister", + (arg,), ) - .with_guaranteed_response() - .with_args((arg,)) - .call() .await } diff --git a/ic-cdk-management-canister/src/schnorr/mod.rs b/ic-cdk/src/api/management_canister/schnorr/mod.rs similarity index 75% rename from ic-cdk-management-canister/src/schnorr/mod.rs rename to ic-cdk/src/api/management_canister/schnorr/mod.rs index c6a77e710..36e6fe15c 100644 --- a/ic-cdk-management-canister/src/schnorr/mod.rs +++ b/ic-cdk/src/api/management_canister/schnorr/mod.rs @@ -1,7 +1,7 @@ //! Threshold Schnorr signing API. +use crate::api::call::{call, call_with_payment128, CallResult}; use candid::Principal; -use ic_cdk::prelude::*; mod types; pub use types::*; @@ -15,11 +15,12 @@ const SIGN_WITH_SCHNORR_FEE: u128 = 26_153_846_153; pub async fn schnorr_public_key( arg: SchnorrPublicKeyArgument, ) -> CallResult<(SchnorrPublicKeyResponse,)> { - Call::new(Principal::management_canister(), "schnorr_public_key") - .with_guaranteed_response() - .with_args((arg,)) - .call() - .await + call( + Principal::management_canister(), + "schnorr_public_key", + (arg,), + ) + .await } /// Return a new Schnorr signature of the given message that can be separately verified against a derived Schnorr public key. @@ -32,10 +33,11 @@ pub async fn schnorr_public_key( pub async fn sign_with_schnorr( arg: SignWithSchnorrArgument, ) -> CallResult<(SignWithSchnorrResponse,)> { - Call::new(Principal::management_canister(), "sign_with_schnorr") - .with_guaranteed_response() - .with_args((arg,)) - .with_cycles(SIGN_WITH_SCHNORR_FEE) - .call() - .await + call_with_payment128( + Principal::management_canister(), + "sign_with_schnorr", + (arg,), + SIGN_WITH_SCHNORR_FEE, + ) + .await } diff --git a/ic-cdk-management-canister/src/schnorr/types.rs b/ic-cdk/src/api/management_canister/schnorr/types.rs similarity index 98% rename from ic-cdk-management-canister/src/schnorr/types.rs rename to ic-cdk/src/api/management_canister/schnorr/types.rs index 803a8c36a..6760b9097 100644 --- a/ic-cdk-management-canister/src/schnorr/types.rs +++ b/ic-cdk/src/api/management_canister/schnorr/types.rs @@ -1,7 +1,7 @@ use candid::CandidType; use serde::{Deserialize, Serialize}; -use crate::CanisterId; +use super::super::main::CanisterId; /// Argument Type of [schnorr_public_key](super::schnorr_public_key). #[derive( diff --git a/ic-cdk/src/api/mod.rs b/ic-cdk/src/api/mod.rs index f05b8fae7..54d4470b8 100644 --- a/ic-cdk/src/api/mod.rs +++ b/ic-cdk/src/api/mod.rs @@ -3,6 +3,7 @@ use candid::Principal; use std::convert::TryFrom; pub mod call; +pub mod management_canister; pub mod stable; /// Prints the given message. diff --git a/library/ic-certified-map/src/rbtree.rs b/library/ic-certified-map/src/rbtree.rs index cccbd9668..5fcb2feab 100644 --- a/library/ic-certified-map/src/rbtree.rs +++ b/library/ic-certified-map/src/rbtree.rs @@ -1077,6 +1077,7 @@ fn is_balanced(root: &NodeRef) -> bool { go(root, num_black) } +#[allow(dead_code)] struct DebugView<'a, K, V>(&'a NodeRef); impl<'a, K: AsRef<[u8]>, V> fmt::Debug for DebugView<'a, K, V> { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 954f9d75d..1e64dc740 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.75.0" # sync with rust-version in root Cargo.toml +channel = "1.78.0" # sync with rust-version in root Cargo.toml targets = ["wasm32-unknown-unknown"] components = ["rustfmt", "clippy"]