mint_cycles/rust_declarations/
cmc_service.rs

1// This is an experimental feature to generate Rust binding from Candid.
2// You may want to manually adjust some of the types.
3use candid::{self, CandidType, Deserialize, Principal};
4use ic_cdk::api::call::CallResult as Result;
5
6#[derive(CandidType, Deserialize)]
7pub enum ExchangeRateCanister {
8    Set(Principal),
9    Unset,
10}
11
12#[derive(CandidType, Deserialize)]
13pub struct AccountIdentifier {
14    bytes: Vec<u8>,
15}
16
17#[derive(CandidType, Deserialize)]
18pub struct CyclesCanisterInitPayload {
19    exchange_rate_canister: Option<ExchangeRateCanister>,
20    last_purged_notification: Option<u64>,
21    governance_canister_id: Option<Principal>,
22    minting_account_id: Option<AccountIdentifier>,
23    ledger_canister_id: Option<Principal>,
24}
25
26#[derive(CandidType, Deserialize)]
27pub struct IcpXdrConversionRate {
28    xdr_permyriad_per_icp: u64,
29    timestamp_seconds: u64,
30}
31
32#[derive(CandidType, Deserialize)]
33pub struct IcpXdrConversionRateResponse {
34    certificate: Vec<u8>,
35    data: IcpXdrConversionRate,
36    hash_tree: Vec<u8>,
37}
38
39#[derive(CandidType, Deserialize)]
40pub struct SubnetTypesToSubnetsResponse {
41    data: Vec<(String, Vec<Principal>)>,
42}
43
44pub type BlockIndex = u64;
45#[derive(CandidType, Deserialize)]
46pub struct NotifyCreateCanisterArg {
47    pub controller: Principal,
48    pub block_index: BlockIndex,
49    pub subnet_type: Option<String>,
50}
51
52#[derive(CandidType, Deserialize, Debug)]
53pub enum NotifyError {
54    Refunded {
55        block_index: Option<BlockIndex>,
56        reason: String,
57    },
58    InvalidTransaction(String),
59    Other {
60        error_message: String,
61        error_code: u64,
62    },
63    Processing,
64    TransactionTooOld(BlockIndex),
65}
66
67#[derive(CandidType, Deserialize)]
68pub enum NotifyCreateCanisterResult {
69    Ok(Principal),
70    Err(NotifyError),
71}
72
73#[derive(CandidType, Deserialize)]
74pub struct NotifyTopUpArg {
75    pub block_index: BlockIndex,
76    pub canister_id: Principal,
77}
78
79pub type Cycles = candid::Nat;
80#[derive(CandidType, Deserialize)]
81pub enum NotifyTopUpResult {
82    Ok(Cycles),
83    Err(NotifyError),
84}
85
86pub struct CmcService(pub Principal);
87impl CmcService {
88    pub async fn get_icp_xdr_conversion_rate(&self) -> Result<(IcpXdrConversionRateResponse,)> {
89        ic_cdk::call(self.0, "get_icp_xdr_conversion_rate", ()).await
90    }
91    pub async fn get_subnet_types_to_subnets(&self) -> Result<(SubnetTypesToSubnetsResponse,)> {
92        ic_cdk::call(self.0, "get_subnet_types_to_subnets", ()).await
93    }
94    pub async fn notify_create_canister(
95        &self,
96        arg0: NotifyCreateCanisterArg,
97    ) -> Result<(NotifyCreateCanisterResult,)> {
98        ic_cdk::call(self.0, "notify_create_canister", (arg0,)).await
99    }
100    pub async fn notify_top_up(&self, arg0: NotifyTopUpArg) -> Result<(NotifyTopUpResult,)> {
101        ic_cdk::call(self.0, "notify_top_up", (arg0,)).await
102    }
103}