1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//! ICRC2 标准接口
//! <https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-2>
use crate::;
// ICRC2 标准
// icrc2_allowance : (AllowanceArgs) -> (Allowance) query;
// icrc2_approve : (ApproveArgs) -> (Result_1);
// icrc2_transfer_from : (TransferFromArgs) -> (Result_2);
// =================== 账本方法 ===================
// https://dashboard.internetcomputer.org/canister/ryjl3-tyaaa-aaaaa-aaaba-cai
// ============== 查询是否授权 ==============
// icrc2_allowance : (AllowanceArgs) -> (Allowance) query;
// type AllowanceArgs = record { account : Account; spender : Account };
// type Allowance = record { allowance : nat; expires_at : opt nat64 };
/// 授权对象
pub type Icrc2AllowanceArgs = AllowanceArgs;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub struct Icrc2AllowanceArgs {
// /// 被授权的账户 出钱的
// pub account: Icrc1Account,
// /// 授权的账户 花钱的
// pub spender: Icrc1Account,
// }
/// 授权额度
pub type Icrc2Allowance = Allowance;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub struct Icrc2Allowance {
// /// 授权的额度
// pub allowance: candid::Nat,
// /// 过期时间
// pub expires_at: Option<u64>,
// }
/// 查询授权额度
pub async
// ============== 进行授权 ==============
// icrc2_approve : (ApproveArgs) -> (Result_1);
// type ApproveArgs = record {
// fee : opt nat;
// memo : opt vec nat8;
// from_subaccount : opt vec nat8;
// created_at_time : opt nat64;
// amount : nat;
// expected_allowance : opt nat;
// expires_at : opt nat64;
// spender : Account;
// };
// type Result_1 = variant { Ok : nat; Err : ApproveError };
// type ApproveError = variant {
// GenericError : record { message : text; error_code : nat };
// TemporarilyUnavailable;
// Duplicate : record { duplicate_of : nat };
// BadFee : record { expected_fee : nat };
// AllowanceChanged : record { current_allowance : nat };
// CreatedInFuture : record { ledger_time : nat64 };
// TooOld;
// Expired : record { ledger_time : nat64 };
// InsufficientFunds : record { balance : nat };
// };
/// 授权参数
pub type Icrc2ApproveArgs = ApproveArgs;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub struct Icrc2ApproveArgs {
// /// 被授权的子账户
// pub from_subaccount: Option<Icrc1Subaccount>,
// /// 授权的账户
// pub spender: Icrc1Account,
// /// 授权的额度
// pub amount: candid::Nat,
// /// 授权的费用
// pub fee: Option<candid::Nat>,
// /// memo
// pub memo: Option<Icrc1Memo>,
// /// 创建时间
// pub created_at_time: Option<u64>,
// /// 期望转移的数量
// pub expected_allowance: Option<candid::Nat>,
// /// 过期时间
// pub expires_at: Option<u64>,
// }
/// 授权错误
pub type Icrc2ApproveError = ApproveError;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub enum Icrc2ApproveError {
// /// 通用错误
// GenericError {
// /// 错误码
// error_code: candid::Nat,
// /// 错误消息
// message: String,
// },
// /// 临时不可用
// TemporarilyUnavailable,
// /// 交易重复
// Duplicate {
// /// 交易重复
// duplicate_of: candid::Nat,
// },
// /// 错误的费用
// BadFee {
// /// 期望的费用
// expected_fee: candid::Nat,
// },
// /// 授权额度发生变化
// AllowanceChanged {
// /// 当前的授权额度
// current_allowance: candid::Nat,
// },
// /// 未来的转账
// CreatedInFuture {
// /// 当前账本时间
// ledger_time: u64,
// },
// /// 订单太老
// TooOld,
// /// 订单过期
// Expired {
// /// 当前账本时间
// ledger_time: u64,
// },
// /// 余额不足
// InsufficientFunds {
// /// 当前余额
// balance: candid::Nat,
// },
// }
/// 授权结果
pub type Icrc2ApproveResult = ;
/// 授权额度
pub async
// ============== 转账 ==============
// icrc2_transfer_from : (TransferFromArgs) -> (Result_2);
// type TransferFromArgs = record {
// to : Account;
// fee : opt nat;
// spender_subaccount : opt vec nat8;
// from : Account;
// memo : opt vec nat8;
// created_at_time : opt nat64;
// amount : nat;
// };
// type Result_2 = variant { Ok : nat; Err : TransferFromError };
// type TransferFromError = variant {
// GenericError : record { message : text; error_code : nat };
// TemporarilyUnavailable;
// InsufficientAllowance : record { allowance : nat };
// BadBurn : record { min_burn_amount : nat };
// Duplicate : record { duplicate_of : nat };
// BadFee : record { expected_fee : nat };
// CreatedInFuture : record { ledger_time : nat64 };
// TooOld;
// InsufficientFunds : record { balance : nat };
// };
/// 转账参数
pub type Icrc2TransferFromArgs = TransferFromArgs;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub struct Icrc2TransferFromArgs {
// spender_subaccount: Option<Icrc1Subaccount>,
// from: Icrc1Account,
// to: Icrc1Account,
// amount: candid::Nat,
// fee: Option<candid::Nat>,
// memo: Option<Icrc1Memo>,
// created_at_time: Option<u64>,
// }
/// 转账可能出现的错误
pub type Icrc2TransferFromError = TransferFromError;
// #[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
// pub enum Icrc2TransferFromError {
// /// 通用错误
// GenericError {
// /// 错误码
// error_code: candid::Nat,
// /// 错误消息
// message: String,
// },
// /// 临时不可用
// TemporarilyUnavailable,
// /// 授权额度不足
// InsufficientAllowance {
// /// 授权额度
// allowance: candid::Nat,
// },
// /// 错误的燃烧数量
// BadBurn {
// /// 最小的燃烧数量
// min_burn_amount: candid::Nat,
// },
// /// 交易重复
// Duplicate {
// /// 重复的交易
// duplicate_of: candid::Nat,
// },
// /// 错误的费用
// BadFee {
// /// 期望的费用
// expected_fee: candid::Nat,
// },
// /// 未来的转账
// CreatedInFuture {
// /// 当前账本时间
// ledger_time: u64,
// },
// /// 订单太老
// TooOld,
// /// 余额不足
// InsufficientFunds {
// /// 当前余额
// balance: candid::Nat,
// },
// }
/// 转账结果
pub type Icrc1TransferFromResult = ;
/// 通过授权进行转账
pub async