1#![allow(dead_code, unused_imports)]
4use candid::{self, CandidType, Deserialize, Principal};
5use ic_cdk::api::call::CallResult as Result;
6
7#[derive(CandidType, Deserialize, Debug, Clone)]
8pub enum ChangeIndexId {
9 SetTo(Principal),
10 Unset,
11}
12#[derive(CandidType, Deserialize, Debug, Clone)]
13pub struct UpgradeArgs {
14 pub change_index_id: Option<ChangeIndexId>,
15 pub max_blocks_per_request: Option<u64>,
16}
17#[derive(CandidType, Deserialize, Debug, Clone)]
18pub struct InitArgs {
19 pub index_id: Option<Principal>,
20 pub max_blocks_per_request: u64,
21}
22#[derive(CandidType, Deserialize, Debug, Clone)]
23pub enum LedgerArgs {
24 Upgrade(Option<UpgradeArgs>),
25 Init(InitArgs),
26}
27#[derive(CandidType, Deserialize, Debug, Clone)]
28pub struct SubnetFilter {
29 pub subnet_type: Option<String>,
30}
31#[derive(CandidType, Deserialize, Debug, Clone)]
32pub enum SubnetSelection {
33 Filter(SubnetFilter),
34 Subnet { subnet: Principal },
35}
36#[derive(CandidType, Deserialize, Debug, Clone)]
37pub struct CanisterSettings {
38 pub freezing_threshold: Option<candid::Nat>,
39 pub controllers: Option<Vec<Principal>>,
40 pub reserved_cycles_limit: Option<candid::Nat>,
41 pub memory_allocation: Option<candid::Nat>,
42 pub compute_allocation: Option<candid::Nat>,
43}
44#[derive(CandidType, Deserialize, Debug, Clone)]
45pub struct CmcCreateCanisterArgs {
46 pub subnet_selection: Option<SubnetSelection>,
47 pub settings: Option<CanisterSettings>,
48}
49#[derive(CandidType, Deserialize, Debug, Clone)]
50pub struct CreateCanisterArgs {
51 pub from_subaccount: Option<serde_bytes::ByteBuf>,
52 pub created_at_time: Option<u64>,
53 pub amount: candid::Nat,
54 pub creation_args: Option<CmcCreateCanisterArgs>,
55}
56pub type BlockIndex = candid::Nat;
57#[derive(CandidType, Deserialize, Debug, Clone)]
58pub struct CreateCanisterSuccess {
59 pub block_id: BlockIndex,
60 pub canister_id: Principal,
61}
62#[derive(CandidType, Deserialize, Debug, Clone)]
63pub enum CreateCanisterError {
64 GenericError {
65 message: String,
66 error_code: candid::Nat,
67 },
68 TemporarilyUnavailable,
69 Duplicate {
70 duplicate_of: candid::Nat,
71 canister_id: Option<Principal>,
72 },
73 CreatedInFuture {
74 ledger_time: u64,
75 },
76 FailedToCreate {
77 error: String,
78 refund_block: Option<BlockIndex>,
79 fee_block: Option<BlockIndex>,
80 },
81 TooOld,
82 InsufficientFunds {
83 balance: candid::Nat,
84 },
85}
86#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)]
87pub struct Account {
88 pub owner: Principal,
89 pub subaccount: Option<serde_bytes::ByteBuf>,
90}
91#[derive(CandidType, Deserialize, Debug, Clone)]
92pub struct CreateCanisterFromArgs {
93 pub spender_subaccount: Option<serde_bytes::ByteBuf>,
94 pub from: Account,
95 pub created_at_time: Option<u64>,
96 pub amount: candid::Nat,
97 pub creation_args: Option<CmcCreateCanisterArgs>,
98}
99#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)]
100pub enum RejectionCode {
101 NoError,
102 CanisterError,
103 SysTransient,
104 DestinationInvalid,
105 Unknown,
106 SysFatal,
107 CanisterReject,
108}
109#[derive(CandidType, Deserialize, Debug, Clone)]
110pub enum CreateCanisterFromError {
111 FailedToCreateFrom {
112 create_from_block: Option<BlockIndex>,
113 rejection_code: RejectionCode,
114 refund_block: Option<BlockIndex>,
115 approval_refund_block: Option<BlockIndex>,
116 rejection_reason: String,
117 },
118 GenericError {
119 message: String,
120 error_code: candid::Nat,
121 },
122 TemporarilyUnavailable,
123 InsufficientAllowance {
124 allowance: candid::Nat,
125 },
126 Duplicate {
127 duplicate_of: candid::Nat,
128 canister_id: Option<Principal>,
129 },
130 CreatedInFuture {
131 ledger_time: u64,
132 },
133 TooOld,
134 InsufficientFunds {
135 balance: candid::Nat,
136 },
137}
138#[derive(CandidType, Deserialize, Debug, Clone)]
139pub struct DepositArgs {
140 pub to: Account,
141 pub memo: Option<serde_bytes::ByteBuf>,
142}
143#[derive(CandidType, Deserialize, Debug, Clone)]
144pub struct DepositResult {
145 pub balance: candid::Nat,
146 pub block_index: BlockIndex,
147}
148#[derive(CandidType, Deserialize, Debug, Clone)]
149pub struct HttpRequest {
150 pub url: String,
151 pub method: String,
152 pub body: serde_bytes::ByteBuf,
153 pub headers: Vec<(String, String)>,
154}
155#[derive(CandidType, Deserialize, Debug, Clone)]
156pub struct HttpResponse {
157 pub body: serde_bytes::ByteBuf,
158 pub headers: Vec<(String, String)>,
159 pub status_code: u16,
160}
161#[derive(CandidType, Deserialize, Debug, Clone)]
162pub enum MetadataValue {
163 Int(candid::Int),
164 Nat(candid::Nat),
165 Blob(serde_bytes::ByteBuf),
166 Text(String),
167}
168#[derive(CandidType, Deserialize, Debug, Clone)]
169pub struct SupportedStandard {
170 pub url: String,
171 pub name: String,
172}
173#[derive(CandidType, Deserialize, Debug, Clone)]
174pub struct TransferArgs {
175 pub to: Account,
176 pub fee: Option<candid::Nat>,
177 pub memo: Option<serde_bytes::ByteBuf>,
178 pub from_subaccount: Option<serde_bytes::ByteBuf>,
179 pub created_at_time: Option<u64>,
180 pub amount: candid::Nat,
181}
182#[derive(CandidType, Deserialize, Debug, Clone)]
183pub enum TransferError {
184 GenericError {
185 message: String,
186 error_code: candid::Nat,
187 },
188 TemporarilyUnavailable,
189 BadBurn {
190 min_burn_amount: candid::Nat,
191 },
192 Duplicate {
193 duplicate_of: candid::Nat,
194 },
195 BadFee {
196 expected_fee: candid::Nat,
197 },
198 CreatedInFuture {
199 ledger_time: u64,
200 },
201 TooOld,
202 InsufficientFunds {
203 balance: candid::Nat,
204 },
205}
206#[derive(CandidType, Deserialize, Debug, Clone)]
207pub struct AllowanceArgs {
208 pub account: Account,
209 pub spender: Account,
210}
211#[derive(CandidType, Deserialize, Debug, Clone)]
212pub struct Allowance {
213 pub allowance: candid::Nat,
214 pub expires_at: Option<u64>,
215}
216#[derive(CandidType, Deserialize, Debug, Clone)]
217pub struct ApproveArgs {
218 pub fee: Option<candid::Nat>,
219 pub memo: Option<serde_bytes::ByteBuf>,
220 pub from_subaccount: Option<serde_bytes::ByteBuf>,
221 pub created_at_time: Option<u64>,
222 pub amount: candid::Nat,
223 pub expected_allowance: Option<candid::Nat>,
224 pub expires_at: Option<u64>,
225 pub spender: Account,
226}
227#[derive(CandidType, Deserialize, Debug, Clone)]
228pub enum ApproveError {
229 GenericError {
230 message: String,
231 error_code: candid::Nat,
232 },
233 TemporarilyUnavailable,
234 Duplicate {
235 duplicate_of: candid::Nat,
236 },
237 BadFee {
238 expected_fee: candid::Nat,
239 },
240 AllowanceChanged {
241 current_allowance: candid::Nat,
242 },
243 CreatedInFuture {
244 ledger_time: u64,
245 },
246 TooOld,
247 Expired {
248 ledger_time: u64,
249 },
250 InsufficientFunds {
251 balance: candid::Nat,
252 },
253}
254#[derive(CandidType, Deserialize, Debug, Clone)]
255pub struct TransferFromArgs {
256 pub to: Account,
257 pub fee: Option<candid::Nat>,
258 pub spender_subaccount: Option<serde_bytes::ByteBuf>,
259 pub from: Account,
260 pub memo: Option<serde_bytes::ByteBuf>,
261 pub created_at_time: Option<u64>,
262 pub amount: candid::Nat,
263}
264#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)]
265pub enum TransferFromError {
266 GenericError {
267 message: String,
268 error_code: candid::Nat,
269 },
270 TemporarilyUnavailable,
271 InsufficientAllowance {
272 allowance: candid::Nat,
273 },
274 BadBurn {
275 min_burn_amount: candid::Nat,
276 },
277 Duplicate {
278 duplicate_of: candid::Nat,
279 },
280 BadFee {
281 expected_fee: candid::Nat,
282 },
283 CreatedInFuture {
284 ledger_time: u64,
285 },
286 TooOld,
287 InsufficientFunds {
288 balance: candid::Nat,
289 },
290}
291#[derive(CandidType, Deserialize, Debug, Clone)]
292pub struct GetArchivesArgs {
293 pub from: Option<Principal>,
294}
295#[derive(CandidType, Deserialize, Debug, Clone)]
296pub struct GetArchivesResultItem {
297 pub end: candid::Nat,
298 pub canister_id: Principal,
299 pub start: candid::Nat,
300}
301pub type GetArchivesResult = Vec<GetArchivesResultItem>;
302#[derive(CandidType, Deserialize, Debug, Clone)]
303pub struct GetBlocksArgsItem {
304 pub start: candid::Nat,
305 pub length: candid::Nat,
306}
307pub type GetBlocksArgs = Vec<GetBlocksArgsItem>;
308#[derive(CandidType, Deserialize, Debug, Clone)]
309pub enum Value {
310 Int(candid::Int),
311 Map(Vec<(String, Box<Value>)>),
312 Nat(candid::Nat),
313 Nat64(u64),
314 Blob(serde_bytes::ByteBuf),
315 Text(String),
316 Array(Vec<Box<Value>>),
317}
318#[derive(CandidType, Deserialize, Debug, Clone)]
319pub struct GetBlocksResultBlocksItem {
320 pub id: candid::Nat,
321 pub block: Box<Value>,
322}
323candid::define_function!(pub GetBlocksResultArchivedBlocksItemCallback : (
324 GetBlocksArgs,
325 ) -> (GetBlocksResult) query);
326#[derive(CandidType, Deserialize, Debug, Clone)]
327pub struct GetBlocksResultArchivedBlocksItem {
328 pub args: GetBlocksArgs,
329 pub callback: GetBlocksResultArchivedBlocksItemCallback,
330}
331#[derive(CandidType, Deserialize, Debug, Clone)]
332pub struct GetBlocksResult {
333 pub log_length: candid::Nat,
334 pub blocks: Vec<GetBlocksResultBlocksItem>,
335 pub archived_blocks: Vec<GetBlocksResultArchivedBlocksItem>,
336}
337#[derive(CandidType, Deserialize, Debug, Clone)]
338pub struct DataCertificate {
339 pub certificate: serde_bytes::ByteBuf,
340 pub hash_tree: serde_bytes::ByteBuf,
341}
342#[derive(CandidType, Deserialize, Debug, Clone)]
343pub struct SupportedBlockType {
344 pub url: String,
345 pub block_type: String,
346}
347#[derive(CandidType, Deserialize, Debug, Clone)]
348pub struct WithdrawArgs {
349 pub to: Principal,
350 pub from_subaccount: Option<serde_bytes::ByteBuf>,
351 pub created_at_time: Option<u64>,
352 pub amount: candid::Nat,
353}
354#[derive(CandidType, Deserialize, Debug, Clone)]
355pub enum WithdrawError {
356 FailedToWithdraw {
357 rejection_code: RejectionCode,
358 fee_block: Option<candid::Nat>,
359 rejection_reason: String,
360 },
361 GenericError {
362 message: String,
363 error_code: candid::Nat,
364 },
365 TemporarilyUnavailable,
366 Duplicate {
367 duplicate_of: candid::Nat,
368 },
369 BadFee {
370 expected_fee: candid::Nat,
371 },
372 InvalidReceiver {
373 receiver: Principal,
374 },
375 CreatedInFuture {
376 ledger_time: u64,
377 },
378 TooOld,
379 InsufficientFunds {
380 balance: candid::Nat,
381 },
382}
383#[derive(CandidType, Deserialize, Debug, Clone)]
384pub struct WithdrawFromArgs {
385 pub to: Principal,
386 pub spender_subaccount: Option<serde_bytes::ByteBuf>,
387 pub from: Account,
388 pub created_at_time: Option<u64>,
389 pub amount: candid::Nat,
390}
391#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)]
392pub enum WithdrawFromError {
393 GenericError {
394 message: String,
395 error_code: candid::Nat,
396 },
397 TemporarilyUnavailable,
398 InsufficientAllowance {
399 allowance: candid::Nat,
400 },
401 Duplicate {
402 duplicate_of: BlockIndex,
403 },
404 InvalidReceiver {
405 receiver: Principal,
406 },
407 CreatedInFuture {
408 ledger_time: u64,
409 },
410 TooOld,
411 FailedToWithdrawFrom {
412 withdraw_from_block: Option<candid::Nat>,
413 rejection_code: RejectionCode,
414 refund_block: Option<candid::Nat>,
415 approval_refund_block: Option<candid::Nat>,
416 rejection_reason: String,
417 },
418 InsufficientFunds {
419 balance: candid::Nat,
420 },
421}
422
423pub struct Service(pub Principal);
424impl Service {
425 pub async fn create_canister(
426 &self,
427 arg0: &CreateCanisterArgs,
428 ) -> Result<(std::result::Result<CreateCanisterSuccess, CreateCanisterError>,)> {
429 ic_cdk::call(self.0, "create_canister", (arg0,)).await
430 }
431 pub async fn create_canister_from(
432 &self,
433 arg0: &CreateCanisterFromArgs,
434 ) -> Result<(std::result::Result<CreateCanisterSuccess, CreateCanisterFromError>,)> {
435 ic_cdk::call(self.0, "create_canister_from", (arg0,)).await
436 }
437 pub async fn deposit(&self, arg0: &DepositArgs) -> Result<(DepositResult,)> {
438 ic_cdk::call(self.0, "deposit", (arg0,)).await
439 }
440 pub async fn http_request(&self, arg0: &HttpRequest) -> Result<(HttpResponse,)> {
441 ic_cdk::call(self.0, "http_request", (arg0,)).await
442 }
443 pub async fn icrc_1_balance_of(&self, arg0: &Account) -> Result<(candid::Nat,)> {
444 ic_cdk::call(self.0, "icrc1_balance_of", (arg0,)).await
445 }
446 pub async fn icrc_1_decimals(&self) -> Result<(u8,)> {
447 ic_cdk::call(self.0, "icrc1_decimals", ()).await
448 }
449 pub async fn icrc_1_fee(&self) -> Result<(candid::Nat,)> {
450 ic_cdk::call(self.0, "icrc1_fee", ()).await
451 }
452 pub async fn icrc_1_metadata(&self) -> Result<(Vec<(String, MetadataValue)>,)> {
453 ic_cdk::call(self.0, "icrc1_metadata", ()).await
454 }
455 pub async fn icrc_1_minting_account(&self) -> Result<(Option<Account>,)> {
456 ic_cdk::call(self.0, "icrc1_minting_account", ()).await
457 }
458 pub async fn icrc_1_name(&self) -> Result<(String,)> {
459 ic_cdk::call(self.0, "icrc1_name", ()).await
460 }
461 pub async fn icrc_1_supported_standards(&self) -> Result<(Vec<SupportedStandard>,)> {
462 ic_cdk::call(self.0, "icrc1_supported_standards", ()).await
463 }
464 pub async fn icrc_1_symbol(&self) -> Result<(String,)> {
465 ic_cdk::call(self.0, "icrc1_symbol", ()).await
466 }
467 pub async fn icrc_1_total_supply(&self) -> Result<(candid::Nat,)> {
468 ic_cdk::call(self.0, "icrc1_total_supply", ()).await
469 }
470 pub async fn icrc_1_transfer(
471 &self,
472 arg0: &TransferArgs,
473 ) -> Result<(std::result::Result<BlockIndex, TransferError>,)> {
474 ic_cdk::call(self.0, "icrc1_transfer", (arg0,)).await
475 }
476 pub async fn icrc_2_allowance(&self, arg0: &AllowanceArgs) -> Result<(Allowance,)> {
477 ic_cdk::call(self.0, "icrc2_allowance", (arg0,)).await
478 }
479 pub async fn icrc_2_approve(
480 &self,
481 arg0: &ApproveArgs,
482 ) -> Result<(std::result::Result<candid::Nat, ApproveError>,)> {
483 ic_cdk::call(self.0, "icrc2_approve", (arg0,)).await
484 }
485 pub async fn icrc_2_transfer_from(
486 &self,
487 arg0: &TransferFromArgs,
488 ) -> Result<(std::result::Result<candid::Nat, TransferFromError>,)> {
489 ic_cdk::call(self.0, "icrc2_transfer_from", (arg0,)).await
490 }
491 pub async fn icrc_3_get_archives(
492 &self,
493 arg0: &GetArchivesArgs,
494 ) -> Result<(GetArchivesResult,)> {
495 ic_cdk::call(self.0, "icrc3_get_archives", (arg0,)).await
496 }
497 pub async fn icrc_3_get_blocks(&self, arg0: &GetBlocksArgs) -> Result<(GetBlocksResult,)> {
498 ic_cdk::call(self.0, "icrc3_get_blocks", (arg0,)).await
499 }
500 pub async fn icrc_3_get_tip_certificate(&self) -> Result<(Option<DataCertificate>,)> {
501 ic_cdk::call(self.0, "icrc3_get_tip_certificate", ()).await
502 }
503 pub async fn icrc_3_supported_block_types(&self) -> Result<(Vec<SupportedBlockType>,)> {
504 ic_cdk::call(self.0, "icrc3_supported_block_types", ()).await
505 }
506 pub async fn withdraw(
507 &self,
508 arg0: &WithdrawArgs,
509 ) -> Result<(std::result::Result<BlockIndex, WithdrawError>,)> {
510 ic_cdk::call(self.0, "withdraw", (arg0,)).await
511 }
512 pub async fn withdraw_from(
513 &self,
514 arg0: &WithdrawFromArgs,
515 ) -> Result<(std::result::Result<BlockIndex, WithdrawFromError>,)> {
516 ic_cdk::call(self.0, "withdraw_from", (arg0,)).await
517 }
518}