Skip to content

Commit

Permalink
move back management_canister mod
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Dec 4, 2024
1 parent 907b7d9 commit bd65a6a
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 218 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ members = [
"ic-cdk",
"ic-cdk-bindgen",
"ic-cdk-macros",
"ic-cdk-management-canister",
"ic-cdk-timers",
"ic0",
"library/*",
Expand All @@ -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]
Expand All @@ -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"
Expand Down
1 change: 0 additions & 1 deletion e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/bin/call_struct.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/bin/canister_info.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/src/bin/chunk.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/src/bin/management_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/canister_info.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
23 changes: 0 additions & 23 deletions ic-cdk-management-canister/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion ic-cdk-management-canister/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions ic-cdk-management-canister/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion ic-cdk-timers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use ic_cdk::api::call::RejectionCode;
thread_local! {
static TASKS: RefCell<SlotMap<TimerId, Task>> = RefCell::default();
static TIMERS: RefCell<BinaryHeap<Timer>> = RefCell::default();
static MOST_RECENT: Cell<Option<u64>> = Cell::new(None);
static MOST_RECENT: Cell<Option<u64>> = const { Cell::new(None) };
}

enum Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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).
Expand All @@ -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 {
Expand All @@ -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).
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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::*;
Expand All @@ -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.
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::id;
use candid::CandidType;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -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<u8>) -> Self {
Self {
context,
function: TransformFunc(candid::Func {
method: candid_function_name,
principal: ic_cdk::api::id(),
principal: id(),
}),
}
}
Expand Down
Loading

0 comments on commit bd65a6a

Please sign in to comment.