ic_agent 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Dockerfile +17 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +108 -0
- data/LICENSE.txt +21 -0
- data/README.md +217 -0
- data/Rakefile +4 -0
- data/ic_agent.gemspec +53 -0
- data/lib/ic_agent/agent.rb +176 -0
- data/lib/ic_agent/ast/assembler.rb +192 -0
- data/lib/ic_agent/ast/did_grammar.treetop +159 -0
- data/lib/ic_agent/ast/did_grammar_v1.treetop +111 -0
- data/lib/ic_agent/ast/nodes/named_nodes.rb +410 -0
- data/lib/ic_agent/ast/nodes/string_literal.rb +17 -0
- data/lib/ic_agent/ast/parser.rb +85 -0
- data/lib/ic_agent/ast/writer.rb +19 -0
- data/lib/ic_agent/candid.rb +1671 -0
- data/lib/ic_agent/canister.rb +270 -0
- data/lib/ic_agent/certificate.rb +55 -0
- data/lib/ic_agent/client.rb +47 -0
- data/lib/ic_agent/common/cycles_wallet.rb +275 -0
- data/lib/ic_agent/common/governance.rb +366 -0
- data/lib/ic_agent/common/ledger.rb +177 -0
- data/lib/ic_agent/common/management.rb +69 -0
- data/lib/ic_agent/identity.rb +125 -0
- data/lib/ic_agent/principal.rb +112 -0
- data/lib/ic_agent/system_state.rb +43 -0
- data/lib/ic_agent/utils.rb +71 -0
- data/lib/ic_agent/version.rb +5 -0
- data/lib/ic_agent.rb +37 -0
- data/sig/ic_agent.rbs +4 -0
- metadata +288 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
module IcAgent
|
|
2
|
+
module Common
|
|
3
|
+
class Governance
|
|
4
|
+
CANISTER_ID = 'rrkah-fqaaa-aaaaa-aaaaq-cai'
|
|
5
|
+
DID_FILE = <<~DIDL_DOC
|
|
6
|
+
type AccountIdentifier = record { hash : vec nat8 };
|
|
7
|
+
type Action = variant {
|
|
8
|
+
RegisterKnownNeuron : KnownNeuron;
|
|
9
|
+
ManageNeuron : ManageNeuron;
|
|
10
|
+
ExecuteNnsFunction : ExecuteNnsFunction;
|
|
11
|
+
RewardNodeProvider : RewardNodeProvider;
|
|
12
|
+
SetDefaultFollowees : SetDefaultFollowees;
|
|
13
|
+
RewardNodeProviders : RewardNodeProviders;
|
|
14
|
+
ManageNetworkEconomics : NetworkEconomics;
|
|
15
|
+
ApproveGenesisKyc : ApproveGenesisKyc;
|
|
16
|
+
AddOrRemoveNodeProvider : AddOrRemoveNodeProvider;
|
|
17
|
+
Motion : Motion;
|
|
18
|
+
};
|
|
19
|
+
type AddHotKey = record { new_hot_key : opt principal };
|
|
20
|
+
type AddOrRemoveNodeProvider = record { change : opt Change };
|
|
21
|
+
type Amount = record { e8s : nat64 };
|
|
22
|
+
type ApproveGenesisKyc = record { principals : vec principal };
|
|
23
|
+
type Ballot = record { vote : int32; voting_power : nat64 };
|
|
24
|
+
type BallotInfo = record { vote : int32; proposal_id : opt NeuronId };
|
|
25
|
+
type By = variant {
|
|
26
|
+
NeuronIdOrSubaccount : record {};
|
|
27
|
+
MemoAndController : ClaimOrRefreshNeuronFromAccount;
|
|
28
|
+
Memo : nat64;
|
|
29
|
+
};
|
|
30
|
+
type Change = variant { ToRemove : NodeProvider; ToAdd : NodeProvider };
|
|
31
|
+
type ClaimOrRefresh = record { by : opt By };
|
|
32
|
+
type ClaimOrRefreshNeuronFromAccount = record {
|
|
33
|
+
controller : opt principal;
|
|
34
|
+
memo : nat64;
|
|
35
|
+
};
|
|
36
|
+
type ClaimOrRefreshNeuronFromAccountResponse = record { result : opt Result_1 };
|
|
37
|
+
type ClaimOrRefreshResponse = record { refreshed_neuron_id : opt NeuronId };
|
|
38
|
+
type Command = variant {
|
|
39
|
+
Spawn : Spawn;
|
|
40
|
+
Split : Split;
|
|
41
|
+
Follow : Follow;
|
|
42
|
+
ClaimOrRefresh : ClaimOrRefresh;
|
|
43
|
+
Configure : Configure;
|
|
44
|
+
RegisterVote : RegisterVote;
|
|
45
|
+
Merge : Merge;
|
|
46
|
+
DisburseToNeuron : DisburseToNeuron;
|
|
47
|
+
MakeProposal : Proposal;
|
|
48
|
+
MergeMaturity : MergeMaturity;
|
|
49
|
+
Disburse : Disburse;
|
|
50
|
+
};
|
|
51
|
+
type Command_1 = variant {
|
|
52
|
+
Error : GovernanceError;
|
|
53
|
+
Spawn : SpawnResponse;
|
|
54
|
+
Split : SpawnResponse;
|
|
55
|
+
Follow : record {};
|
|
56
|
+
ClaimOrRefresh : ClaimOrRefreshResponse;
|
|
57
|
+
Configure : record {};
|
|
58
|
+
RegisterVote : record {};
|
|
59
|
+
Merge : record {};
|
|
60
|
+
DisburseToNeuron : SpawnResponse;
|
|
61
|
+
MakeProposal : MakeProposalResponse;
|
|
62
|
+
MergeMaturity : MergeMaturityResponse;
|
|
63
|
+
Disburse : DisburseResponse;
|
|
64
|
+
};
|
|
65
|
+
type Command_2 = variant {
|
|
66
|
+
Spawn : Spawn;
|
|
67
|
+
Split : Split;
|
|
68
|
+
Configure : Configure;
|
|
69
|
+
Merge : Merge;
|
|
70
|
+
DisburseToNeuron : DisburseToNeuron;
|
|
71
|
+
ClaimOrRefreshNeuron : ClaimOrRefresh;
|
|
72
|
+
MergeMaturity : MergeMaturity;
|
|
73
|
+
Disburse : Disburse;
|
|
74
|
+
};
|
|
75
|
+
type Configure = record { operation : opt Operation };
|
|
76
|
+
type Disburse = record {
|
|
77
|
+
to_account : opt AccountIdentifier;
|
|
78
|
+
amount : opt Amount;
|
|
79
|
+
};
|
|
80
|
+
type DisburseResponse = record { transfer_block_height : nat64 };
|
|
81
|
+
type DisburseToNeuron = record {
|
|
82
|
+
dissolve_delay_seconds : nat64;
|
|
83
|
+
kyc_verified : bool;
|
|
84
|
+
amount_e8s : nat64;
|
|
85
|
+
new_controller : opt principal;
|
|
86
|
+
nonce : nat64;
|
|
87
|
+
};
|
|
88
|
+
type DissolveState = variant {
|
|
89
|
+
DissolveDelaySeconds : nat64;
|
|
90
|
+
WhenDissolvedTimestampSeconds : nat64;
|
|
91
|
+
};
|
|
92
|
+
type ExecuteNnsFunction = record { nns_function : int32; payload : vec nat8 };
|
|
93
|
+
type Follow = record { topic : int32; followees : vec NeuronId };
|
|
94
|
+
type Followees = record { followees : vec NeuronId };
|
|
95
|
+
type Governance = record {
|
|
96
|
+
default_followees : vec record { int32; Followees };
|
|
97
|
+
wait_for_quiet_threshold_seconds : nat64;
|
|
98
|
+
metrics : opt GovernanceCachedMetrics;
|
|
99
|
+
node_providers : vec NodeProvider;
|
|
100
|
+
economics : opt NetworkEconomics;
|
|
101
|
+
latest_reward_event : opt RewardEvent;
|
|
102
|
+
to_claim_transfers : vec NeuronStakeTransfer;
|
|
103
|
+
short_voting_period_seconds : nat64;
|
|
104
|
+
proposals : vec record { nat64; ProposalData };
|
|
105
|
+
in_flight_commands : vec record { nat64; NeuronInFlightCommand };
|
|
106
|
+
neurons : vec record { nat64; Neuron };
|
|
107
|
+
genesis_timestamp_seconds : nat64;
|
|
108
|
+
};
|
|
109
|
+
type GovernanceCachedMetrics = record {
|
|
110
|
+
not_dissolving_neurons_e8s_buckets : vec record { nat64; float64 };
|
|
111
|
+
garbage_collectable_neurons_count : nat64;
|
|
112
|
+
neurons_with_invalid_stake_count : nat64;
|
|
113
|
+
not_dissolving_neurons_count_buckets : vec record { nat64; nat64 };
|
|
114
|
+
total_supply_icp : nat64;
|
|
115
|
+
neurons_with_less_than_6_months_dissolve_delay_count : nat64;
|
|
116
|
+
dissolved_neurons_count : nat64;
|
|
117
|
+
total_staked_e8s : nat64;
|
|
118
|
+
not_dissolving_neurons_count : nat64;
|
|
119
|
+
dissolved_neurons_e8s : nat64;
|
|
120
|
+
neurons_with_less_than_6_months_dissolve_delay_e8s : nat64;
|
|
121
|
+
dissolving_neurons_count_buckets : vec record { nat64; nat64 };
|
|
122
|
+
dissolving_neurons_count : nat64;
|
|
123
|
+
dissolving_neurons_e8s_buckets : vec record { nat64; float64 };
|
|
124
|
+
community_fund_total_staked_e8s : nat64;
|
|
125
|
+
timestamp_seconds : nat64;
|
|
126
|
+
};
|
|
127
|
+
type GovernanceError = record { error_message : text; error_type : int32 };
|
|
128
|
+
type IncreaseDissolveDelay = record {
|
|
129
|
+
additional_dissolve_delay_seconds : nat32;
|
|
130
|
+
};
|
|
131
|
+
type KnownNeuron = record {
|
|
132
|
+
id : opt NeuronId;
|
|
133
|
+
known_neuron_data : opt KnownNeuronData;
|
|
134
|
+
};
|
|
135
|
+
type KnownNeuronData = record { name : text; description : opt text };
|
|
136
|
+
type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
|
|
137
|
+
type ListNeurons = record {
|
|
138
|
+
neuron_ids : vec nat64;
|
|
139
|
+
include_neurons_readable_by_caller : bool;
|
|
140
|
+
};
|
|
141
|
+
type ListNeuronsResponse = record {
|
|
142
|
+
neuron_infos : vec record { nat64; NeuronInfo };
|
|
143
|
+
full_neurons : vec Neuron;
|
|
144
|
+
};
|
|
145
|
+
type ListNodeProvidersResponse = record { node_providers : vec NodeProvider };
|
|
146
|
+
type ListProposalInfo = record {
|
|
147
|
+
include_reward_status : vec int32;
|
|
148
|
+
before_proposal : opt NeuronId;
|
|
149
|
+
limit : nat32;
|
|
150
|
+
exclude_topic : vec int32;
|
|
151
|
+
include_status : vec int32;
|
|
152
|
+
};
|
|
153
|
+
type ListProposalInfoResponse = record { proposal_info : vec ProposalInfo };
|
|
154
|
+
type MakeProposalResponse = record { proposal_id : opt NeuronId };
|
|
155
|
+
type ManageNeuron = record {
|
|
156
|
+
id : opt NeuronId;
|
|
157
|
+
command : opt Command;
|
|
158
|
+
neuron_id_or_subaccount : opt NeuronIdOrSubaccount;
|
|
159
|
+
};
|
|
160
|
+
type ManageNeuronResponse = record { command : opt Command_1 };
|
|
161
|
+
type Merge = record { source_neuron_id : opt NeuronId };
|
|
162
|
+
type MergeMaturity = record { percentage_to_merge : nat32 };
|
|
163
|
+
type MergeMaturityResponse = record {
|
|
164
|
+
merged_maturity_e8s : nat64;
|
|
165
|
+
new_stake_e8s : nat64;
|
|
166
|
+
};
|
|
167
|
+
type Motion = record { motion_text : text };
|
|
168
|
+
type NetworkEconomics = record {
|
|
169
|
+
neuron_minimum_stake_e8s : nat64;
|
|
170
|
+
max_proposals_to_keep_per_topic : nat32;
|
|
171
|
+
neuron_management_fee_per_proposal_e8s : nat64;
|
|
172
|
+
reject_cost_e8s : nat64;
|
|
173
|
+
transaction_fee_e8s : nat64;
|
|
174
|
+
neuron_spawn_dissolve_delay_seconds : nat64;
|
|
175
|
+
minimum_icp_xdr_rate : nat64;
|
|
176
|
+
maximum_node_provider_rewards_e8s : nat64;
|
|
177
|
+
};
|
|
178
|
+
type Neuron = record {
|
|
179
|
+
id : opt NeuronId;
|
|
180
|
+
controller : opt principal;
|
|
181
|
+
recent_ballots : vec BallotInfo;
|
|
182
|
+
kyc_verified : bool;
|
|
183
|
+
not_for_profit : bool;
|
|
184
|
+
maturity_e8s_equivalent : nat64;
|
|
185
|
+
cached_neuron_stake_e8s : nat64;
|
|
186
|
+
created_timestamp_seconds : nat64;
|
|
187
|
+
aging_since_timestamp_seconds : nat64;
|
|
188
|
+
hot_keys : vec principal;
|
|
189
|
+
account : vec nat8;
|
|
190
|
+
joined_community_fund_timestamp_seconds : opt nat64;
|
|
191
|
+
dissolve_state : opt DissolveState;
|
|
192
|
+
followees : vec record { int32; Followees };
|
|
193
|
+
neuron_fees_e8s : nat64;
|
|
194
|
+
transfer : opt NeuronStakeTransfer;
|
|
195
|
+
known_neuron_data : opt KnownNeuronData;
|
|
196
|
+
};
|
|
197
|
+
type NeuronId = record { id : nat64 };
|
|
198
|
+
type NeuronIdOrSubaccount = variant {
|
|
199
|
+
Subaccount : vec nat8;
|
|
200
|
+
NeuronId : NeuronId;
|
|
201
|
+
};
|
|
202
|
+
type NeuronInFlightCommand = record {
|
|
203
|
+
command : opt Command_2;
|
|
204
|
+
timestamp : nat64;
|
|
205
|
+
};
|
|
206
|
+
type NeuronInfo = record {
|
|
207
|
+
dissolve_delay_seconds : nat64;
|
|
208
|
+
recent_ballots : vec BallotInfo;
|
|
209
|
+
created_timestamp_seconds : nat64;
|
|
210
|
+
state : int32;
|
|
211
|
+
stake_e8s : nat64;
|
|
212
|
+
joined_community_fund_timestamp_seconds : opt nat64;
|
|
213
|
+
retrieved_at_timestamp_seconds : nat64;
|
|
214
|
+
known_neuron_data : opt KnownNeuronData;
|
|
215
|
+
voting_power : nat64;
|
|
216
|
+
age_seconds : nat64;
|
|
217
|
+
};
|
|
218
|
+
type NeuronStakeTransfer = record {
|
|
219
|
+
to_subaccount : vec nat8;
|
|
220
|
+
neuron_stake_e8s : nat64;
|
|
221
|
+
from : opt principal;
|
|
222
|
+
memo : nat64;
|
|
223
|
+
from_subaccount : vec nat8;
|
|
224
|
+
transfer_timestamp : nat64;
|
|
225
|
+
block_height : nat64;
|
|
226
|
+
};
|
|
227
|
+
type NodeProvider = record {
|
|
228
|
+
id : opt principal;
|
|
229
|
+
reward_account : opt AccountIdentifier;
|
|
230
|
+
};
|
|
231
|
+
type Operation = variant {
|
|
232
|
+
RemoveHotKey : RemoveHotKey;
|
|
233
|
+
AddHotKey : AddHotKey;
|
|
234
|
+
StopDissolving : record {};
|
|
235
|
+
StartDissolving : record {};
|
|
236
|
+
IncreaseDissolveDelay : IncreaseDissolveDelay;
|
|
237
|
+
JoinCommunityFund : record {};
|
|
238
|
+
SetDissolveTimestamp : SetDissolveTimestamp;
|
|
239
|
+
};
|
|
240
|
+
type Proposal = record {
|
|
241
|
+
url : text;
|
|
242
|
+
title : opt text;
|
|
243
|
+
action : opt Action;
|
|
244
|
+
summary : text;
|
|
245
|
+
};
|
|
246
|
+
type ProposalData = record {
|
|
247
|
+
id : opt NeuronId;
|
|
248
|
+
failure_reason : opt GovernanceError;
|
|
249
|
+
ballots : vec record { nat64; Ballot };
|
|
250
|
+
proposal_timestamp_seconds : nat64;
|
|
251
|
+
reward_event_round : nat64;
|
|
252
|
+
failed_timestamp_seconds : nat64;
|
|
253
|
+
reject_cost_e8s : nat64;
|
|
254
|
+
latest_tally : opt Tally;
|
|
255
|
+
decided_timestamp_seconds : nat64;
|
|
256
|
+
proposal : opt Proposal;
|
|
257
|
+
proposer : opt NeuronId;
|
|
258
|
+
wait_for_quiet_state : opt WaitForQuietState;
|
|
259
|
+
executed_timestamp_seconds : nat64;
|
|
260
|
+
};
|
|
261
|
+
type ProposalInfo = record {
|
|
262
|
+
id : opt NeuronId;
|
|
263
|
+
status : int32;
|
|
264
|
+
topic : int32;
|
|
265
|
+
failure_reason : opt GovernanceError;
|
|
266
|
+
ballots : vec record { nat64; Ballot };
|
|
267
|
+
proposal_timestamp_seconds : nat64;
|
|
268
|
+
reward_event_round : nat64;
|
|
269
|
+
deadline_timestamp_seconds : opt nat64;
|
|
270
|
+
failed_timestamp_seconds : nat64;
|
|
271
|
+
reject_cost_e8s : nat64;
|
|
272
|
+
latest_tally : opt Tally;
|
|
273
|
+
reward_status : int32;
|
|
274
|
+
decided_timestamp_seconds : nat64;
|
|
275
|
+
proposal : opt Proposal;
|
|
276
|
+
proposer : opt NeuronId;
|
|
277
|
+
executed_timestamp_seconds : nat64;
|
|
278
|
+
};
|
|
279
|
+
type RegisterVote = record { vote : int32; proposal : opt NeuronId };
|
|
280
|
+
type RemoveHotKey = record { hot_key_to_remove : opt principal };
|
|
281
|
+
type Result = variant { Ok; Err : GovernanceError };
|
|
282
|
+
type Result_1 = variant { Error : GovernanceError; NeuronId : NeuronId };
|
|
283
|
+
type Result_2 = variant { Ok : Neuron; Err : GovernanceError };
|
|
284
|
+
type Result_3 = variant { Ok : RewardNodeProviders; Err : GovernanceError };
|
|
285
|
+
type Result_4 = variant { Ok : NeuronInfo; Err : GovernanceError };
|
|
286
|
+
type Result_5 = variant { Ok : NodeProvider; Err : GovernanceError };
|
|
287
|
+
type RewardEvent = record {
|
|
288
|
+
day_after_genesis : nat64;
|
|
289
|
+
actual_timestamp_seconds : nat64;
|
|
290
|
+
distributed_e8s_equivalent : nat64;
|
|
291
|
+
settled_proposals : vec NeuronId;
|
|
292
|
+
};
|
|
293
|
+
type RewardMode = variant {
|
|
294
|
+
RewardToNeuron : RewardToNeuron;
|
|
295
|
+
RewardToAccount : RewardToAccount;
|
|
296
|
+
};
|
|
297
|
+
type RewardNodeProvider = record {
|
|
298
|
+
node_provider : opt NodeProvider;
|
|
299
|
+
reward_mode : opt RewardMode;
|
|
300
|
+
amount_e8s : nat64;
|
|
301
|
+
};
|
|
302
|
+
type RewardNodeProviders = record {
|
|
303
|
+
use_registry_derived_rewards : opt bool;
|
|
304
|
+
rewards : vec RewardNodeProvider;
|
|
305
|
+
};
|
|
306
|
+
type RewardToAccount = record { to_account : opt AccountIdentifier };
|
|
307
|
+
type RewardToNeuron = record { dissolve_delay_seconds : nat64 };
|
|
308
|
+
type SetDefaultFollowees = record {
|
|
309
|
+
default_followees : vec record { int32; Followees };
|
|
310
|
+
};
|
|
311
|
+
type SetDissolveTimestamp = record { dissolve_timestamp_seconds : nat64 };
|
|
312
|
+
type Spawn = record {
|
|
313
|
+
percentage_to_spawn : opt nat32;
|
|
314
|
+
new_controller : opt principal;
|
|
315
|
+
nonce : opt nat64;
|
|
316
|
+
};
|
|
317
|
+
type SpawnResponse = record { created_neuron_id : opt NeuronId };
|
|
318
|
+
type Split = record { amount_e8s : nat64 };
|
|
319
|
+
type Tally = record {
|
|
320
|
+
no : nat64;
|
|
321
|
+
yes : nat64;
|
|
322
|
+
total : nat64;
|
|
323
|
+
timestamp_seconds : nat64;
|
|
324
|
+
};
|
|
325
|
+
type UpdateNodeProvider = record { reward_account : opt AccountIdentifier };
|
|
326
|
+
type WaitForQuietState = record { current_deadline_timestamp_seconds : nat64 };
|
|
327
|
+
service : (Governance) -> {
|
|
328
|
+
claim_gtc_neurons : (principal, vec NeuronId) -> (Result);
|
|
329
|
+
claim_or_refresh_neuron_from_account : (ClaimOrRefreshNeuronFromAccount) -> (
|
|
330
|
+
ClaimOrRefreshNeuronFromAccountResponse,
|
|
331
|
+
);
|
|
332
|
+
get_build_metadata : () -> (text) query;
|
|
333
|
+
get_full_neuron : (nat64) -> (Result_2) query;
|
|
334
|
+
get_full_neuron_by_id_or_subaccount : (NeuronIdOrSubaccount) -> (
|
|
335
|
+
Result_2,
|
|
336
|
+
) query;
|
|
337
|
+
get_monthly_node_provider_rewards : () -> (Result_3);
|
|
338
|
+
get_neuron_ids : () -> (vec nat64) query;
|
|
339
|
+
get_neuron_info : (nat64) -> (Result_4) query;
|
|
340
|
+
get_neuron_info_by_id_or_subaccount : (NeuronIdOrSubaccount) -> (
|
|
341
|
+
Result_4,
|
|
342
|
+
) query;
|
|
343
|
+
get_node_provider_by_caller : (null) -> (Result_5) query;
|
|
344
|
+
get_pending_proposals : () -> (vec ProposalInfo) query;
|
|
345
|
+
get_proposal_info : (nat64) -> (opt ProposalInfo) query;
|
|
346
|
+
list_known_neurons : () -> (ListKnownNeuronsResponse) query;
|
|
347
|
+
list_neurons : (ListNeurons) -> (ListNeuronsResponse) query;
|
|
348
|
+
list_node_providers : () -> (ListNodeProvidersResponse) query;
|
|
349
|
+
list_proposals : (ListProposalInfo) -> (ListProposalInfoResponse) query;
|
|
350
|
+
manage_neuron : (ManageNeuron) -> (ManageNeuronResponse);
|
|
351
|
+
transfer_gtc_neuron : (NeuronId, NeuronId) -> (Result);
|
|
352
|
+
update_node_provider : (UpdateNodeProvider) -> (Result);
|
|
353
|
+
}
|
|
354
|
+
DIDL_DOC
|
|
355
|
+
|
|
356
|
+
attr_accessor :identity, :client, :agent, :canister
|
|
357
|
+
|
|
358
|
+
def initialize(iden = nil)
|
|
359
|
+
@identity = iden.nil? ? IcAgent::Identity.new : iden
|
|
360
|
+
@client = IcAgent::Client.new
|
|
361
|
+
@agent = IcAgent::Agent.new(@identity, @client)
|
|
362
|
+
@canister = IcAgent::Canister.new(@agent, CANISTER_ID, DID_FILE)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
end
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
module IcAgent
|
|
2
|
+
module Common
|
|
3
|
+
class Ledger
|
|
4
|
+
CANISTER_ID = 'ryjl3-tyaaa-aaaaa-aaaba-cai'
|
|
5
|
+
DID_FILE = <<~DIDL_DOC
|
|
6
|
+
// This is the official Ledger interface that is guaranteed to be backward compatible.
|
|
7
|
+
|
|
8
|
+
// Amount of tokens, measured in 10^-8 of a token.
|
|
9
|
+
type Tokens = record {
|
|
10
|
+
e8s : nat64;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Number of nanoseconds from the UNIX epoch in UTC timezone.
|
|
14
|
+
type TimeStamp = record {
|
|
15
|
+
timestamp_nanos: nat64;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// AccountIdentifier is a 32-byte array.
|
|
19
|
+
// The first 4 bytes is big-endian encoding of a CRC32 checksum of the last 28 bytes.
|
|
20
|
+
type AccountIdentifier = blob;
|
|
21
|
+
|
|
22
|
+
// Subaccount is an arbitrary 32-byte byte array.
|
|
23
|
+
// Ledger uses subaccounts to compute the source address, which enables one
|
|
24
|
+
// principal to control multiple ledger accounts.
|
|
25
|
+
type SubAccount = blob;
|
|
26
|
+
|
|
27
|
+
// Sequence number of a block produced by the ledger.
|
|
28
|
+
type BlockIndex = nat64;
|
|
29
|
+
|
|
30
|
+
// An arbitrary number associated with a transaction.
|
|
31
|
+
// The caller can set it in a `transfer` call as a correlation identifier.
|
|
32
|
+
type Memo = nat64;
|
|
33
|
+
|
|
34
|
+
// Arguments for the `transfer` call.
|
|
35
|
+
type TransferArgs = record {
|
|
36
|
+
memo: Memo;
|
|
37
|
+
amount: Tokens;
|
|
38
|
+
fee: Tokens;
|
|
39
|
+
from_subaccount: opt SubAccount;
|
|
40
|
+
to: AccountIdentifier;
|
|
41
|
+
created_at_time: opt TimeStamp;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type TransferError = variant {
|
|
45
|
+
BadFee : record { expected_fee : Tokens; };
|
|
46
|
+
InsufficientFunds : record { balance: Tokens; };
|
|
47
|
+
TxTooOld : record { allowed_window_nanos: nat64 };
|
|
48
|
+
TxCreatedInFuture : null;
|
|
49
|
+
TxDuplicate : record { duplicate_of: BlockIndex; }
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type TransferResult = variant {
|
|
53
|
+
Ok : BlockIndex;
|
|
54
|
+
Err : TransferError;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Arguments for the `account_balance` call.
|
|
58
|
+
type AccountBalanceArgs = record {
|
|
59
|
+
account: AccountIdentifier;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type TransferFeeArg = record {};
|
|
63
|
+
|
|
64
|
+
type TransferFee = record {
|
|
65
|
+
transfer_fee: Tokens;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type GetBlocksArgs = record {
|
|
69
|
+
start : BlockIndex;
|
|
70
|
+
length : nat64;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type Operation = variant {
|
|
74
|
+
Mint : record {
|
|
75
|
+
to : AccountIdentifier;
|
|
76
|
+
amount : Tokens;
|
|
77
|
+
};
|
|
78
|
+
Burn : record {
|
|
79
|
+
from : AccountIdentifier;
|
|
80
|
+
amount : Tokens;
|
|
81
|
+
};
|
|
82
|
+
Transfer : record {
|
|
83
|
+
from : AccountIdentifier;
|
|
84
|
+
to : AccountIdentifier;
|
|
85
|
+
amount : Tokens;
|
|
86
|
+
fee : Tokens;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type Transaction = record {
|
|
91
|
+
memo : Memo;
|
|
92
|
+
operation : opt Operation;
|
|
93
|
+
created_at_time : TimeStamp;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
type Block = record {
|
|
97
|
+
parent_hash : opt blob;
|
|
98
|
+
transaction : Transaction;
|
|
99
|
+
timestamp : TimeStamp;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// A prefix of the block range specified in the [GetBlocksArgs] request.
|
|
103
|
+
type BlockRange = record {
|
|
104
|
+
blocks : vec Block;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// An error indicating that the arguments passed to [QueryArchiveFn] were invalid.
|
|
108
|
+
type QueryArchiveError = variant {
|
|
109
|
+
BadFirstBlockIndex : record {
|
|
110
|
+
requested_index : BlockIndex;
|
|
111
|
+
first_valid_index : BlockIndex;
|
|
112
|
+
};
|
|
113
|
+
Other : record {
|
|
114
|
+
error_code : nat64;
|
|
115
|
+
error_message : text;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type QueryArchiveResult = variant {
|
|
120
|
+
Ok : BlockRange;
|
|
121
|
+
Err : QueryArchiveError;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// A function that is used for fetching archived ledger blocks.
|
|
125
|
+
type QueryArchiveFn = func (GetBlocksArgs) -> (QueryArchiveResult) query;
|
|
126
|
+
|
|
127
|
+
// The result of a "query_blocks" call.
|
|
128
|
+
//
|
|
129
|
+
// The structure of the result is somewhat complicated because the main ledger canister might
|
|
130
|
+
// not have all the blocks that the caller requested: One or more "archive" canisters might
|
|
131
|
+
// store some of the requested blocks.
|
|
132
|
+
//
|
|
133
|
+
// Note: as of Q4 2021 when this interface is authored, the IC doesn't support making nested
|
|
134
|
+
// query calls within a query call.
|
|
135
|
+
type QueryBlocksResponse = record {
|
|
136
|
+
chain_length : nat64;
|
|
137
|
+
certificate : opt blob;
|
|
138
|
+
blocks : vec Block;
|
|
139
|
+
first_block_index : BlockIndex;
|
|
140
|
+
archived_blocks : vec record {
|
|
141
|
+
start : BlockIndex;
|
|
142
|
+
length : nat64;
|
|
143
|
+
callback : QueryArchiveFn;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type Archive = record {
|
|
148
|
+
canister_id: principal;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
type Archives = record {
|
|
152
|
+
archives: vec Archive;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
service : {
|
|
156
|
+
transfer : (TransferArgs) -> (TransferResult);
|
|
157
|
+
account_balance : (AccountBalanceArgs) -> (Tokens) query;
|
|
158
|
+
transfer_fee : (TransferFeeArg) -> (TransferFee) query;
|
|
159
|
+
query_blocks : (GetBlocksArgs) -> (QueryBlocksResponse) query;
|
|
160
|
+
symbol : () -> (record { symbol: text }) query;
|
|
161
|
+
name : () -> (record { name: text }) query;
|
|
162
|
+
decimals : () -> (record { decimals: nat32 }) query;
|
|
163
|
+
archives : () -> (Archives) query;
|
|
164
|
+
}
|
|
165
|
+
DIDL_DOC
|
|
166
|
+
|
|
167
|
+
attr_accessor :identity, :client, :agent, :canister
|
|
168
|
+
|
|
169
|
+
def initialize(iden = nil)
|
|
170
|
+
@identity = iden.nil? ? IcAgent::Identity.new : iden
|
|
171
|
+
@client = IcAgent::Client.new
|
|
172
|
+
@agent = IcAgent::Agent.new(@identity, @client)
|
|
173
|
+
@canister = IcAgent::Canister.new(@agent, CANISTER_ID, DID_FILE)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module IcAgent
|
|
2
|
+
module Common
|
|
3
|
+
class Management
|
|
4
|
+
CANISTER_ID = 'aaaaa-aa'
|
|
5
|
+
DID_FILE = <<~DIDL_DOC
|
|
6
|
+
type canister_id = principal;
|
|
7
|
+
type user_id = principal;
|
|
8
|
+
type wasm_module = blob;
|
|
9
|
+
|
|
10
|
+
type canister_settings = record {
|
|
11
|
+
controllers : opt vec principal;
|
|
12
|
+
compute_allocation : opt nat;
|
|
13
|
+
memory_allocation : opt nat;
|
|
14
|
+
freezing_threshold : opt nat;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type definite_canister_settings = record {
|
|
18
|
+
controllers : vec principal;
|
|
19
|
+
compute_allocation : nat;
|
|
20
|
+
memory_allocation : nat;
|
|
21
|
+
freezing_threshold : nat;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
service ic : {
|
|
25
|
+
create_canister : (record {
|
|
26
|
+
settings : opt canister_settings
|
|
27
|
+
}) -> (record {canister_id : canister_id});
|
|
28
|
+
update_settings : (record {
|
|
29
|
+
canister_id : principal;
|
|
30
|
+
settings : canister_settings
|
|
31
|
+
}) -> ();
|
|
32
|
+
install_code : (record {
|
|
33
|
+
mode : variant {install; reinstall; upgrade};
|
|
34
|
+
canister_id : canister_id;
|
|
35
|
+
wasm_module : wasm_module;
|
|
36
|
+
arg : blob;
|
|
37
|
+
}) -> ();
|
|
38
|
+
uninstall_code : (record {canister_id : canister_id}) -> ();
|
|
39
|
+
start_canister : (record {canister_id : canister_id}) -> ();
|
|
40
|
+
stop_canister : (record {canister_id : canister_id}) -> ();
|
|
41
|
+
canister_status : (record {canister_id : canister_id}) -> (record {
|
|
42
|
+
status : variant { running; stopping; stopped };
|
|
43
|
+
settings: definite_canister_settings;
|
|
44
|
+
module_hash: opt blob;
|
|
45
|
+
memory_size: nat;
|
|
46
|
+
cycles: nat;
|
|
47
|
+
});
|
|
48
|
+
delete_canister : (record {canister_id : canister_id}) -> ();
|
|
49
|
+
deposit_cycles : (record {canister_id : canister_id}) -> ();
|
|
50
|
+
provisional_create_canister_with_cycles : (record {
|
|
51
|
+
amount: opt nat;
|
|
52
|
+
settings : opt canister_settings
|
|
53
|
+
}) -> (record {canister_id : canister_id});
|
|
54
|
+
provisional_top_up_canister :
|
|
55
|
+
(record { canister_id: canister_id; amount: nat }) -> ();
|
|
56
|
+
}
|
|
57
|
+
DIDL_DOC
|
|
58
|
+
|
|
59
|
+
attr_accessor :identity, :client, :agent, :canister
|
|
60
|
+
|
|
61
|
+
def initialize(iden = nil)
|
|
62
|
+
@identity = iden.nil? ? IcAgent::Identity.new : iden
|
|
63
|
+
@client = IcAgent::Client.new
|
|
64
|
+
@agent = IcAgent::Agent.new(@identity, @client)
|
|
65
|
+
@canister = IcAgent::Canister.new(@agent, CANISTER_ID, DID_FILE)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|