ic_cdk/api/management_canister/
provisional.rs

1//! Provisional functions only available in local development instances.
2
3use crate::api::call::{call, CallResult};
4use candid::{CandidType, Nat, Principal};
5use serde::{Deserialize, Serialize};
6
7pub use super::main::{CanisterId, CanisterIdRecord, CanisterSettings};
8
9/// Argument type of [provisional_create_canister_with_cycles].
10#[derive(
11    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
12)]
13pub struct ProvisionalCreateCanisterWithCyclesArgument {
14    /// The created canister will have this amount of cycles.
15    pub amount: Option<Nat>,
16    /// See [CanisterSettings].
17    pub settings: Option<CanisterSettings>,
18}
19
20/// Argument type of [provisional_top_up_canister].
21#[derive(
22    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
23)]
24pub struct ProvisionalTopUpCanisterArgument {
25    /// Canister ID.
26    pub canister_id: CanisterId,
27    /// Amount of cycles to be added.
28    pub amount: Nat,
29}
30
31/// Create a new canister with specified amount of cycles balance.
32///
33/// This method is only available in local development instances.
34///
35/// See [IC method `provisional_create_canister_with_cycles`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-provisional_create_canister_with_cycles).
36pub async fn provisional_create_canister_with_cycles(
37    arg: ProvisionalCreateCanisterWithCyclesArgument,
38) -> CallResult<(CanisterIdRecord,)> {
39    call(
40        Principal::management_canister(),
41        "provisional_create_canister_with_cycles",
42        (arg,),
43    )
44    .await
45}
46
47/// Add cycles to a canister.
48///
49/// This method is only available in local development instances.
50///
51/// See [IC method `provisional_top_up_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-provisional_top_up_canister).
52pub async fn provisional_top_up_canister(arg: ProvisionalTopUpCanisterArgument) -> CallResult<()> {
53    call(
54        Principal::management_canister(),
55        "provisional_top_up_canister",
56        (arg,),
57    )
58    .await
59}