1use candid::{self, CandidType, Deserialize, Principal};
4use ic_cdk::api::call::CallResult as Result;
5
6#[derive(CandidType, Deserialize)]
7pub struct Account {
8 owner: Principal,
9 subaccount: Option<Vec<u8>>,
10}
11
12#[derive(CandidType, Deserialize)]
13pub struct UpgradeArgs {
14 maximum_number_of_accounts: Option<u64>,
15 icrc1_minting_account: Option<Account>,
16}
17
18#[derive(CandidType, Deserialize)]
19pub struct Tokens {
20 e8s: u64,
21}
22
23#[derive(CandidType, Deserialize)]
24pub struct Duration {
25 secs: u64,
26 nanos: u32,
27}
28
29#[derive(CandidType, Deserialize)]
30pub struct ArchiveOptions {
31 num_blocks_to_archive: u64,
32 max_transactions_per_response: Option<u64>,
33 trigger_threshold: u64,
34 max_message_size_bytes: Option<u64>,
35 cycles_for_archive_creation: Option<u64>,
36 node_max_memory_size_bytes: Option<u64>,
37 controller_id: Principal,
38}
39
40#[derive(CandidType, Deserialize)]
41pub struct InitArgs {
42 send_whitelist: Vec<Principal>,
43 token_symbol: Option<String>,
44 transfer_fee: Option<Tokens>,
45 minting_account: String,
46 transaction_window: Option<Duration>,
47 max_message_size_bytes: Option<u64>,
48 icrc1_minting_account: Option<Account>,
49 archive_options: Option<ArchiveOptions>,
50 initial_values: Vec<(String, Tokens)>,
51 token_name: Option<String>,
52}
53
54#[derive(CandidType, Deserialize)]
55pub enum LedgerCanisterPayload {
56 Upgrade(Option<UpgradeArgs>),
57 Init(InitArgs),
58}
59
60#[derive(CandidType, Deserialize)]
61pub struct BinaryAccountBalanceArgs {
62 account: Vec<u8>,
63}
64
65#[derive(CandidType, Deserialize)]
66pub struct AccountBalanceArgs {
67 account: String,
68}
69
70#[derive(CandidType, Deserialize)]
71pub struct ArchiveInfo {
72 canister_id: Principal,
73}
74
75#[derive(CandidType, Deserialize)]
76pub struct Archives {
77 archives: Vec<ArchiveInfo>,
78}
79
80#[derive(CandidType, Deserialize)]
81pub struct Decimals {
82 decimals: u32,
83}
84
85#[derive(CandidType, Deserialize)]
86pub enum MetadataValue {
87 Int(candid::Int),
88 Nat(candid::Nat),
89 Blob(Vec<u8>),
90 Text(String),
91}
92
93#[derive(CandidType, Deserialize)]
94pub struct StandardRecord {
95 url: String,
96 name: String,
97}
98
99#[derive(CandidType, Deserialize)]
100pub struct TransferArg {
101 to: Account,
102 fee: Option<candid::Nat>,
103 memo: Option<Vec<u8>>,
104 from_subaccount: Option<Vec<u8>>,
105 created_at_time: Option<u64>,
106 amount: candid::Nat,
107}
108
109#[derive(CandidType, Deserialize)]
110pub enum TransferError {
111 GenericError {
112 message: String,
113 error_code: candid::Nat,
114 },
115 TemporarilyUnavailable,
116 BadBurn {
117 min_burn_amount: candid::Nat,
118 },
119 Duplicate {
120 duplicate_of: candid::Nat,
121 },
122 BadFee {
123 expected_fee: candid::Nat,
124 },
125 CreatedInFuture {
126 ledger_time: u64,
127 },
128 TooOld,
129 InsufficientFunds {
130 balance: candid::Nat,
131 },
132}
133
134#[derive(CandidType, Deserialize)]
135pub struct Name {
136 name: String,
137}
138
139#[derive(CandidType, Deserialize)]
140pub struct GetBlocksArgs {
141 start: u64,
142 length: u64,
143}
144
145#[derive(CandidType, Deserialize)]
146pub struct TimeStamp {
147 timestamp_nanos: u64,
148}
149
150#[derive(CandidType, Deserialize)]
151pub enum CandidOperation {
152 Approve {
153 fee: Tokens,
154 from: Vec<u8>,
155 allowance_e8s: candid::Int,
156 allowance: Tokens,
157 expires_at: Option<TimeStamp>,
158 spender: Vec<u8>,
159 },
160 Burn {
161 from: Vec<u8>,
162 amount: Tokens,
163 },
164 Mint {
165 to: Vec<u8>,
166 amount: Tokens,
167 },
168 Transfer {
169 to: Vec<u8>,
170 fee: Tokens,
171 from: Vec<u8>,
172 amount: Tokens,
173 },
174 TransferFrom {
175 to: Vec<u8>,
176 fee: Tokens,
177 from: Vec<u8>,
178 amount: Tokens,
179 spender: Vec<u8>,
180 },
181}
182
183#[derive(CandidType, Deserialize)]
184pub struct CandidTransaction {
185 memo: u64,
186 icrc1_memo: Option<Vec<u8>>,
187 operation: Option<CandidOperation>,
188 created_at_time: TimeStamp,
189}
190
191#[derive(CandidType, Deserialize)]
192pub struct CandidBlock {
193 transaction: CandidTransaction,
194 timestamp: TimeStamp,
195 parent_hash: Option<Vec<u8>>,
196}
197
198#[derive(CandidType, Deserialize)]
199pub struct BlockRange {
200 blocks: Vec<CandidBlock>,
201}
202
203#[derive(CandidType, Deserialize)]
204pub enum GetBlocksError {
205 BadFirstBlockIndex {
206 requested_index: u64,
207 first_valid_index: u64,
208 },
209 Other {
210 error_message: String,
211 error_code: u64,
212 },
213}
214
215#[derive(CandidType, Deserialize)]
216pub enum ArchivedBlocksRangeCallbackRet0 {
217 Ok(BlockRange),
218 Err(GetBlocksError),
219}
220
221candid::define_function!(pub ArchivedBlocksRangeCallback : (GetBlocksArgs) -> (
222 ArchivedBlocksRangeCallbackRet0,
223 ) query);
224#[derive(CandidType, Deserialize)]
225pub struct ArchivedBlocksRange {
226 callback: ArchivedBlocksRangeCallback,
227 start: u64,
228 length: u64,
229}
230
231#[derive(CandidType, Deserialize)]
232pub struct QueryBlocksResponse {
233 certificate: Option<Vec<u8>>,
234 blocks: Vec<CandidBlock>,
235 chain_length: u64,
236 first_block_index: u64,
237 archived_blocks: Vec<ArchivedBlocksRange>,
238}
239
240#[derive(CandidType, Deserialize)]
241pub enum ArchivedEncodedBlocksRangeCallbackRet0 {
242 Ok(Vec<Vec<u8>>),
243 Err(GetBlocksError),
244}
245
246candid::define_function!(pub ArchivedEncodedBlocksRangeCallback : (
247 GetBlocksArgs,
248 ) -> (ArchivedEncodedBlocksRangeCallbackRet0) query);
249#[derive(CandidType, Deserialize)]
250pub struct ArchivedEncodedBlocksRange {
251 callback: ArchivedEncodedBlocksRangeCallback,
252 start: u64,
253 length: u64,
254}
255
256#[derive(CandidType, Deserialize)]
257pub struct QueryEncodedBlocksResponse {
258 certificate: Option<Vec<u8>>,
259 blocks: Vec<Vec<u8>>,
260 chain_length: u64,
261 first_block_index: u64,
262 archived_blocks: Vec<ArchivedEncodedBlocksRange>,
263}
264
265#[derive(CandidType, Deserialize)]
266pub struct SendArgs {
267 to: String,
268 fee: Tokens,
269 memo: u64,
270 from_subaccount: Option<Vec<u8>>,
271 created_at_time: Option<TimeStamp>,
272 amount: Tokens,
273}
274
275#[derive(CandidType, Deserialize)]
276pub struct Symbol {
277 symbol: String,
278}
279
280#[derive(CandidType, Deserialize)]
281pub struct TransferArgs {
282 to: Vec<u8>,
283 fee: Tokens,
284 memo: u64,
285 from_subaccount: Option<Vec<u8>>,
286 created_at_time: Option<TimeStamp>,
287 amount: Tokens,
288}
289
290#[derive(CandidType, Deserialize)]
291pub enum TransferError1 {
292 TxTooOld { allowed_window_nanos: u64 },
293 BadFee { expected_fee: Tokens },
294 TxDuplicate { duplicate_of: u64 },
295 TxCreatedInFuture,
296 InsufficientFunds { balance: Tokens },
297}
298
299#[derive(CandidType, Deserialize)]
300pub enum Result1 {
301 Ok(u64),
302 Err(TransferError1),
303}
304
305#[derive(CandidType, Deserialize)]
306pub struct TransferFeeArg0 {}
307
308#[derive(CandidType, Deserialize)]
309pub struct TransferFee {
310 transfer_fee: Tokens,
311}
312
313#[derive(CandidType, Deserialize)]
314pub enum Result2 {
315 Ok(candid::Nat),
316 Err(TransferError),
317}
318
319pub struct IcpLedgerService(pub Principal);
320impl IcpLedgerService {
321 pub async fn account_balance(&self, arg0: BinaryAccountBalanceArgs) -> Result<(Tokens,)> {
322 ic_cdk::call(self.0, "account_balance", (arg0,)).await
323 }
324 pub async fn account_balance_dfx(&self, arg0: AccountBalanceArgs) -> Result<(Tokens,)> {
325 ic_cdk::call(self.0, "account_balance_dfx", (arg0,)).await
326 }
327 pub async fn archives(&self) -> Result<(Archives,)> {
328 ic_cdk::call(self.0, "archives", ()).await
329 }
330 pub async fn decimals(&self) -> Result<(Decimals,)> {
331 ic_cdk::call(self.0, "decimals", ()).await
332 }
333 pub async fn icrc1_balance_of(&self, arg0: Account) -> Result<(candid::Nat,)> {
334 ic_cdk::call(self.0, "icrc1_balance_of", (arg0,)).await
335 }
336 pub async fn icrc1_decimals(&self) -> Result<(u8,)> {
337 ic_cdk::call(self.0, "icrc1_decimals", ()).await
338 }
339 pub async fn icrc1_fee(&self) -> Result<(candid::Nat,)> {
340 ic_cdk::call(self.0, "icrc1_fee", ()).await
341 }
342 pub async fn icrc1_metadata(&self) -> Result<(Vec<(String, MetadataValue)>,)> {
343 ic_cdk::call(self.0, "icrc1_metadata", ()).await
344 }
345 pub async fn icrc1_minting_account(&self) -> Result<(Option<Account>,)> {
346 ic_cdk::call(self.0, "icrc1_minting_account", ()).await
347 }
348 pub async fn icrc1_name(&self) -> Result<(String,)> {
349 ic_cdk::call(self.0, "icrc1_name", ()).await
350 }
351 pub async fn icrc1_supported_standards(&self) -> Result<(Vec<StandardRecord>,)> {
352 ic_cdk::call(self.0, "icrc1_supported_standards", ()).await
353 }
354 pub async fn icrc1_symbol(&self) -> Result<(String,)> {
355 ic_cdk::call(self.0, "icrc1_symbol", ()).await
356 }
357 pub async fn icrc1_total_supply(&self) -> Result<(candid::Nat,)> {
358 ic_cdk::call(self.0, "icrc1_total_supply", ()).await
359 }
360 pub async fn icrc1_transfer(&self, arg0: TransferArg) -> Result<(Result2,)> {
361 ic_cdk::call(self.0, "icrc1_transfer", (arg0,)).await
362 }
363 pub async fn name(&self) -> Result<(Name,)> {
364 ic_cdk::call(self.0, "name", ()).await
365 }
366 pub async fn query_blocks(&self, arg0: GetBlocksArgs) -> Result<(QueryBlocksResponse,)> {
367 ic_cdk::call(self.0, "query_blocks", (arg0,)).await
368 }
369 pub async fn query_encoded_blocks(
370 &self,
371 arg0: GetBlocksArgs,
372 ) -> Result<(QueryEncodedBlocksResponse,)> {
373 ic_cdk::call(self.0, "query_encoded_blocks", (arg0,)).await
374 }
375 pub async fn send_dfx(&self, arg0: SendArgs) -> Result<(u64,)> {
376 ic_cdk::call(self.0, "send_dfx", (arg0,)).await
377 }
378 pub async fn symbol(&self) -> Result<(Symbol,)> {
379 ic_cdk::call(self.0, "symbol", ()).await
380 }
381 pub async fn transfer(&self, arg0: TransferArgs) -> Result<(Result1,)> {
382 ic_cdk::call(self.0, "transfer", (arg0,)).await
383 }
384 pub async fn transfer_fee(&self, arg0: TransferFeeArg0) -> Result<(TransferFee,)> {
385 ic_cdk::call(self.0, "transfer_fee", (arg0,)).await
386 }
387}