forked from mystical-prog/irsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icrc1.did
276 lines (241 loc) · 8.71 KB
/
icrc1.did
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
type BlockIndex = nat;
type Subaccount = blob;
// Number of nanoseconds since the UNIX epoch in UTC timezone.
type Timestamp = nat64;
// Number of nanoseconds between two [Timestamp]s.
type Duration = nat64;
type Tokens = nat;
type TxIndex = nat;
type Account = record {
owner : principal;
subaccount : opt Subaccount;
};
type TransferArg = record {
from_subaccount : opt Subaccount;
to : Account;
amount : Tokens;
fee : opt Tokens;
memo : opt blob;
created_at_time: opt Timestamp;
};
type TransferError = variant {
BadFee : record { expected_fee : Tokens };
BadBurn : record { min_burn_amount : Tokens };
InsufficientFunds : record { balance : Tokens };
TooOld;
CreatedInFuture : record { ledger_time : nat64 };
TemporarilyUnavailable;
Duplicate : record { duplicate_of : BlockIndex };
GenericError : record { error_code : nat; message : text };
};
type TransferResult = variant {
Ok : BlockIndex;
Err : TransferError;
};
// The value returned from the [icrc1_metadata] endpoint.
type MetadataValue = variant {
Nat : nat;
Int : int;
Text : text;
Blob : blob;
};
// The initialization parameters of the Ledger
type InitArgs = record {
minting_account : Account;
fee_collector_account : opt Account;
transfer_fee : nat64;
token_symbol : text;
token_name : text;
metadata : vec record { text; MetadataValue };
initial_balances : vec record { Account; nat64 };
archive_options : record {
num_blocks_to_archive : nat64;
trigger_threshold : nat64;
max_message_size_bytes : opt nat64;
cycles_for_archive_creation : opt nat64;
node_max_memory_size_bytes : opt nat64;
controller_id : principal;
};
};
type ChangeFeeCollector = variant {
Unset; SetTo: Account;
};
type UpgradeArgs = record {
metadata : opt vec record { text; MetadataValue };
token_symbol : opt text;
token_name : opt text;
transfer_fee : opt nat64;
change_fee_collector : opt ChangeFeeCollector;
};
type LedgerArg = variant {
Init: InitArgs;
Upgrade: opt UpgradeArgs;
};
type GetTransactionsRequest = record {
// The index of the first tx to fetch.
start : TxIndex;
// The number of transactions to fetch.
length : nat;
};
type GetTransactionsResponse = record {
// The total number of transactions in the log.
log_length : nat;
// List of transaction that were available in the ledger when it processed the call.
//
// The transactions form a contiguous range, with the first transaction having index
// [first_index] (see below), and the last transaction having index
// [first_index] + len(transactions) - 1.
//
// The transaction range can be an arbitrary sub-range of the originally requested range.
transactions : vec Transaction;
// The index of the first transaction in [transactions].
// If the transaction vector is empty, the exact value of this field is not specified.
first_index : TxIndex;
// Encoding of instructions for fetching archived transactions whose indices fall into the
// requested range.
//
// For each entry `e` in [archived_transactions], `[e.from, e.from + len)` is a sub-range
// of the originally requested transaction range.
archived_transactions : vec record {
// The index of the first archived transaction you can fetch using the [callback].
start : TxIndex;
// The number of transactions you can fetch using the callback.
length : nat;
// The function you should call to fetch the archived transactions.
// The range of the transaction accessible using this function is given by [from]
// and [len] fields above.
callback : QueryArchiveFn;
};
};
// A prefix of the transaction range specified in the [GetTransactionsRequest] request.
type TransactionRange = record {
// A prefix of the requested transaction range.
// The index of the first transaction is equal to [GetTransactionsRequest.from].
//
// Note that the number of transactions might be less than the requested
// [GetTransactionsRequest.length] for various reasons, for example:
//
// 1. The query might have hit the replica with an outdated state
// that doesn't have the whole range yet.
// 2. The requested range is too large to fit into a single reply.
//
// NOTE: the list of transactions can be empty if:
//
// 1. [GetTransactionsRequest.length] was zero.
// 2. [GetTransactionsRequest.from] was larger than the last transaction known to
// the canister.
transactions : vec Transaction;
};
// A function for fetching archived transaction.
type QueryArchiveFn = func (GetTransactionsRequest) -> (TransactionRange) query;
type Transaction = record {
kind : text;
mint : opt record {
amount : nat;
to : Account;
memo : opt blob;
created_at_time : opt nat64;
};
burn : opt record {
amount : nat;
from : Account;
memo : opt blob;
created_at_time : opt nat64;
};
transfer : opt record {
amount : nat;
from : Account;
to : Account;
memo : opt blob;
created_at_time : opt nat64;
fee : opt nat;
};
timestamp : nat64;
};
type Value = variant {
Blob : blob;
Text : text;
Nat : nat;
Nat64: nat64;
Int : int;
Array : vec Value;
Map : Map;
};
type Map = vec record { text; Value };
type Block = Value;
type GetBlocksArgs = record {
// The index of the first block to fetch.
start : BlockIndex;
// Max number of blocks to fetch.
length : nat;
};
// A prefix of the block range specified in the [GetBlocksArgs] request.
type BlockRange = record {
// A prefix of the requested block range.
// The index of the first block is equal to [GetBlocksArgs.start].
//
// Note that the number of blocks might be less than the requested
// [GetBlocksArgs.length] for various reasons, for example:
//
// 1. The query might have hit the replica with an outdated state
// that doesn't have the whole range yet.
// 2. The requested range is too large to fit into a single reply.
//
// NOTE: the list of blocks can be empty if:
//
// 1. [GetBlocksArgs.length] was zero.
// 2. [GetBlocksArgs.start] was larger than the last block known to
// the canister.
blocks : vec Block;
};
// A function for fetching archived blocks.
type QueryBlockArchiveFn = func (GetBlocksArgs) -> (BlockRange) query;
// The result of a "get_blocks" call.
type GetBlocksResponse = record {
// The index of the first block in "blocks".
// If the blocks vector is empty, the exact value of this field is not specified.
first_index : BlockIndex;
// The total number of blocks in the chain.
// If the chain length is positive, the index of the last block is `chain_len - 1`.
chain_length : nat64;
// System certificate for the hash of the latest block in the chain.
// Only present if `get_blocks` is called in a non-replicated query context.
certificate : opt blob;
// List of blocks that were available in the ledger when it processed the call.
//
// The blocks form a contiguous range, with the first block having index
// [first_block_index] (see below), and the last block having index
// [first_block_index] + len(blocks) - 1.
//
// The block range can be an arbitrary sub-range of the originally requested range.
blocks : vec Block;
// Encoding of instructions for fetching archived blocks.
archived_blocks : vec record {
// The index of the first archived block.
start : BlockIndex;
// The number of blocks that can be fetched.
length : nat;
// Callback to fetch the archived blocks.
callback : QueryBlockArchiveFn;
};
};
// Certificate for the block at `block_index`.
type DataCertificate = record {
certificate : opt blob;
hash_tree : blob;
};
service : (ledger_arg : LedgerArg) -> {
icrc1_name : () -> (text) query;
icrc1_symbol : () -> (text) query;
icrc1_decimals : () -> (nat8) query;
icrc1_metadata : () -> (vec record { text; MetadataValue }) query;
icrc1_total_supply : () -> (Tokens) query;
icrc1_fee : () -> (Tokens) query;
icrc1_minting_account : () -> (opt Account) query;
icrc1_balance_of : (Account) -> (Tokens) query;
icrc1_transfer : (TransferArg) -> (TransferResult);
icrc1_supported_standards : () -> (vec record { name : text; url : text }) query;
get_transactions : (GetTransactionsRequest) -> (GetTransactionsResponse) query;
get_blocks : (GetBlocksArgs) -> (GetBlocksResponse) query;
get_data_certificate : () -> (DataCertificate) query;
}