ex3_ic_management_client/
lib.rs

1use async_trait::async_trait;
2#[cfg(feature = "bitcoin")]
3use ic_cdk::api::management_canister::bitcoin::{
4    GetBalanceRequest, GetCurrentFeePercentilesRequest, GetUtxosRequest, GetUtxosResponse,
5    MillisatoshiPerByte, Satoshi, SendTransactionRequest,
6};
7#[cfg(feature = "ecdsa")]
8use ic_cdk::api::management_canister::ecdsa::{
9    EcdsaPublicKeyArgument, EcdsaPublicKeyResponse, SignWithEcdsaArgument, SignWithEcdsaResponse,
10};
11#[cfg(feature = "main")]
12use ic_cdk::api::management_canister::main::{
13    CanisterIdRecord, CanisterInfoRequest, CanisterInfoResponse, CanisterStatusResponse,
14    CreateCanisterArgument, InstallCodeArgument, UpdateSettingsArgument,
15};
16
17pub use canister_impl::ICManagementClient;
18use ex3_canister_client::CanisterResult;
19
20#[cfg(feature = "mock")]
21pub mod mock;
22
23mod canister_impl;
24
25#[async_trait]
26pub trait ICManagement: Send + Sync {
27    /// See [IC method `bitcoin_get_balance`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_balance).
28    ///
29    /// This call requires cycles payment.
30    /// This method handles the cycles cost under the hood.
31    /// Check [API fees & Pricing](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api-fees--pricing) for more details.
32    #[cfg(feature = "bitcoin")]
33    async fn bitcoin_get_balance(&self, arg: GetBalanceRequest) -> CanisterResult<Satoshi>;
34
35    /// See [IC method `bitcoin_get_utxos`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_utxos).
36    ///
37    /// This call requires cycles payment.
38    /// This method handles the cycles cost under the hood.
39    /// Check [API fees & Pricing](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api-fees--pricing) for more details.
40    #[cfg(feature = "bitcoin")]
41    async fn bitcoin_get_utxos(&self, arg: GetUtxosRequest) -> CanisterResult<GetUtxosResponse>;
42
43    /// See [IC method `bitcoin_send_transaction`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_send_transaction).
44    ///
45    /// This call requires cycles payment.
46    /// This method handles the cycles cost under the hood.
47    /// Check [API fees & Pricing](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api-fees--pricing) for more details.
48    #[cfg(feature = "bitcoin")]
49    async fn bitcoin_send_transaction(&self, arg: SendTransactionRequest) -> CanisterResult<()>;
50
51    /// See [IC method `bitcoin_get_current_fee_percentiles`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_current_fee_percentiles).
52    ///
53    /// This call requires cycles payment.
54    /// This method handles the cycles cost under the hood.
55    /// Check [API fees & Pricing](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/bitcoin-how-it-works/#api-fees--pricing) for more details.
56    #[cfg(feature = "bitcoin")]
57    async fn bitcoin_get_current_fee_percentiles(
58        &self,
59        arg: GetCurrentFeePercentilesRequest,
60    ) -> CanisterResult<Vec<MillisatoshiPerByte>>;
61
62    ///! ECDSA management canister interface
63
64    /// Return a SEC1 encoded ECDSA public key for the given canister using the given derivation path.
65    ///
66    /// See [IC method `ecdsa_public_key`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-ecdsa_public_key).
67    #[cfg(feature = "ecdsa")]
68    async fn ecdsa_public_key(
69        &self,
70        arg: EcdsaPublicKeyArgument,
71    ) -> CanisterResult<EcdsaPublicKeyResponse>;
72
73    /// Return a new ECDSA signature of the given message_hash that can be separately verified against a derived ECDSA public key.
74    ///
75    /// See [IC method `sign_with_ecdsa`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_ecdsa).
76    #[cfg(feature = "ecdsa")]
77    async fn sign_with_ecdsa(
78        &self,
79        arg: SignWithEcdsaArgument,
80    ) -> CanisterResult<SignWithEcdsaResponse>;
81
82    ///! Management canister main interface
83
84    /// Register a new canister and get its canister id.
85    ///
86    /// See [IC method `create_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-create_canister).
87    ///
88    /// This call requires cycles payment. The required cycles varies according to the subnet size (number of nodes).
89    /// Check [Gas and cycles cost](https://internetcomputer.org/docs/current/developer-docs/gas-cost) for more details.
90    #[cfg(feature = "main")]
91    async fn create_canister(
92        &self,
93        arg: CreateCanisterArgument,
94        cycles: u128,
95    ) -> CanisterResult<CanisterIdRecord>;
96
97    /// Update the settings of a canister.
98    ///
99    /// See [IC method `update_settings`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-update_settings).
100    #[cfg(feature = "main")]
101    async fn update_settings(&self, arg: UpdateSettingsArgument) -> CanisterResult<()>;
102
103    /// Install code into a canister.
104    ///
105    /// See [IC method `install_code`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-install_code).
106    #[cfg(feature = "main")]
107    async fn install_code(&self, arg: InstallCodeArgument) -> CanisterResult<()>;
108
109    /// Remove a canister's code and state, making the canister empty again.
110    ///
111    /// See [IC method `uninstall_code`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-uninstall_code)
112    #[cfg(feature = "main")]
113    async fn uninstall_code(&self, arg: CanisterIdRecord) -> CanisterResult<()>;
114
115    /// Start a canister if the canister status was `stopped` or `stopping`.
116    ///
117    /// See [IC method `start_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-start_canister)
118    #[cfg(feature = "main")]
119    async fn start_canister(&self, arg: CanisterIdRecord) -> CanisterResult<()>;
120
121    /// Stop a canister.
122    ///
123    /// See [IC method `stop_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-stop_canister)
124    #[cfg(feature = "main")]
125    async fn stop_canister(&self, arg: CanisterIdRecord) -> CanisterResult<()>;
126
127    /// Get status information about the canister.
128    ///
129    /// See [IC method `canister_status`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-canister_status)
130    #[cfg(feature = "main")]
131    async fn canister_status(
132        &self,
133        arg: CanisterIdRecord,
134    ) -> CanisterResult<CanisterStatusResponse>;
135
136    /// Delete a canister from the IC.
137    ///
138    /// See [IC method `delete_canister`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-delete_canister)
139    #[cfg(feature = "main")]
140    async fn delete_canister(&self, arg: CanisterIdRecord) -> CanisterResult<()>;
141
142    /// Deposit cycles into the specified canister.
143    ///
144    /// Note that, beyond the argument as specified in the interface description,
145    /// there is a second parameter `cycles` which is the amount of cycles to be deposited.
146    ///
147    /// See [IC method `deposit_cycles`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-deposit_cycles)
148    #[cfg(feature = "main")]
149    async fn deposit_cycles(&self, arg: CanisterIdRecord, cycles: u128) -> CanisterResult<()>;
150
151    /// Get 32 pseudo-random bytes.
152    ///
153    /// See [IC method `raw_rand`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-raw_rand)
154    #[cfg(feature = "main")]
155    async fn raw_rand(&self) -> CanisterResult<Vec<u8>>;
156
157    /// Get public information about the canister.
158    ///
159    /// See [IC method `canister_info`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-canister_info).
160    #[cfg(feature = "main")]
161    async fn canister_info(&self, arg: CanisterInfoRequest)
162        -> CanisterResult<CanisterInfoResponse>;
163}