Skip to content

Commit d7cc790

Browse files
fix: Remove usage of deprecated functions (#235)
1 parent 25321e9 commit d7cc790

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+282
-219
lines changed

e2e/tests-quill/create_neuron.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ teardown() {
1919
SEND_OUTPUT="$(quill send stake.call --yes --insecure-local-dev-mode)"
2020
assert_command echo "$SEND_OUTPUT" # replay the output so string matches work
2121
echo "$SEND_OUTPUT"
22-
assert_string_match "Method name: claim_or_refresh_neuron_from_account"
22+
assert_string_match "Method name: manage_neuron"
2323
NEURON_ID="$(echo "$SEND_OUTPUT" | grep -E ' neuron ' | sed 's/[^0-9]//g')"
2424
echo "NEURON: $NEURON_ID"
2525
assert_string_match "

src/commands/account_balance.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
use crate::{
22
commands::{send::submit_unsigned_ingress, SendingOpts},
33
lib::{
4-
get_account_id, ledger_canister_id, AnyhowResult, AuthInfo, ParsedNnsAccount,
5-
ROLE_ICRC1_LEDGER, ROLE_NNS_LEDGER,
4+
ledger_canister_id, AnyhowResult, AuthInfo, ParsedNnsAccount, ROLE_ICRC1_LEDGER,
5+
ROLE_NNS_LEDGER,
66
},
77
AUTH_FLAGS,
88
};
9-
use candid::{CandidType, Encode};
9+
use candid::Encode;
1010
use clap::Parser;
11+
use icp_ledger::BinaryAccountBalanceArgs;
12+
use icrc_ledger_types::icrc1::account::Account;
1113

1214
use super::get_principal;
1315

14-
#[derive(CandidType)]
15-
pub struct AccountBalanceArgs {
16-
pub account: String,
17-
}
18-
1916
/// Queries a ledger account balance.
2017
#[derive(Parser)]
2118
pub struct AccountBalanceOpts {
@@ -33,18 +30,21 @@ pub async fn exec(auth: &AuthInfo, opts: AccountBalanceOpts, fetch_root_key: boo
3330
let account_id = if let Some(id) = opts.account_id {
3431
id
3532
} else {
36-
let id = get_account_id(get_principal(auth)?, None)?;
37-
ParsedNnsAccount::Original(id)
33+
let account = Account {
34+
owner: get_principal(auth)?,
35+
subaccount: None,
36+
};
37+
ParsedNnsAccount::Icrc1(account)
3838
};
3939
match account_id {
4040
ParsedNnsAccount::Original(id) => {
41-
let args = Encode!(&AccountBalanceArgs {
42-
account: id.to_hex()
41+
let args = Encode!(&BinaryAccountBalanceArgs {
42+
account: id.to_address()
4343
})?;
4444
submit_unsigned_ingress(
4545
ledger_canister_id(),
4646
ROLE_NNS_LEDGER,
47-
"account_balance_dfx",
47+
"account_balance",
4848
args,
4949
opts.sending_opts,
5050
fetch_root_key,

src/commands/neuron_manage.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use candid::{CandidType, Encode, Principal};
99
use clap::{Parser, ValueEnum};
1010
use ic_base_types::PrincipalId;
1111
use ic_nns_common::pb::v1::{NeuronId, ProposalId};
12+
use ic_nns_governance::pb::v1::manage_neuron::NeuronIdOrSubaccount;
1213
use ic_nns_governance::pb::v1::{
1314
manage_neuron::{
1415
configure::Operation, disburse::Amount, AddHotKey, ChangeAutoStakeMaturity, Command,
@@ -142,60 +143,61 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
142143
}
143144
let mut msgs = Vec::new();
144145

145-
let id = Some(NeuronId {
146+
let id = NeuronId {
146147
id: parse_neuron_id(opts.neuron_id)?,
147-
});
148+
};
149+
let id = Some(NeuronIdOrSubaccount::NeuronId(id));
148150
if opts.add_hot_key.is_some() {
149151
let args = Encode!(&ManageNeuron {
150-
id,
152+
id: None,
151153
command: Some(Command::Configure(Configure {
152154
operation: Some(Operation::AddHotKey(AddHotKey {
153155
new_hot_key: opts.add_hot_key.map(PrincipalId)
154156
}))
155157
})),
156-
neuron_id_or_subaccount: None,
158+
neuron_id_or_subaccount: id.clone(),
157159
})?;
158160
msgs.push(args);
159161
};
160162

161163
if opts.remove_hot_key.is_some() {
162164
let args = Encode!(&ManageNeuron {
163-
id,
165+
id: None,
164166
command: Some(Command::Configure(Configure {
165167
operation: Some(Operation::RemoveHotKey(RemoveHotKey {
166168
hot_key_to_remove: opts.remove_hot_key.map(PrincipalId)
167169
}))
168170
})),
169-
neuron_id_or_subaccount: None,
171+
neuron_id_or_subaccount: id.clone(),
170172
})?;
171173
msgs.push(args);
172174
};
173175

174176
if opts.stop_dissolving {
175177
let args = Encode!(&ManageNeuron {
176-
id,
178+
id: None,
177179
command: Some(Command::Configure(Configure {
178180
operation: Some(Operation::StopDissolving(StopDissolving {}))
179181
})),
180-
neuron_id_or_subaccount: None,
182+
neuron_id_or_subaccount: id.clone(),
181183
})?;
182184
msgs.push(args);
183185
}
184186

185187
if opts.start_dissolving {
186188
let args = Encode!(&ManageNeuron {
187-
id,
189+
id: None,
188190
command: Some(Command::Configure(Configure {
189191
operation: Some(Operation::StartDissolving(StartDissolving {}))
190192
})),
191-
neuron_id_or_subaccount: None,
193+
neuron_id_or_subaccount: id.clone(),
192194
})?;
193195
msgs.push(args);
194196
}
195197

196198
if let Some(additional_dissolve_delay_seconds) = opts.additional_dissolve_delay_seconds {
197199
let args = Encode!(&ManageNeuron {
198-
id,
200+
id: None,
199201
command: Some(Command::Configure(Configure {
200202
operation: Some(Operation::IncreaseDissolveDelay(IncreaseDissolveDelay {
201203
additional_dissolve_delay_seconds: match additional_dissolve_delay_seconds
@@ -235,66 +237,66 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
235237
}
236238
}))
237239
})),
238-
neuron_id_or_subaccount: None,
240+
neuron_id_or_subaccount: id.clone(),
239241
})?;
240242
msgs.push(args);
241243
};
242244

243245
if opts.disburse || opts.disburse_amount.is_some() || opts.disburse_to.is_some() {
244246
let args = Encode!(&ManageNeuron {
245-
id,
247+
id: None,
246248
command: Some(Command::Disburse(Disburse {
247249
to_account: opts.disburse_to.map(|to| to.into_identifier().into()),
248250
amount: opts.disburse_amount.map(|amount| Amount {
249251
e8s: amount.get_e8s()
250252
}),
251253
})),
252-
neuron_id_or_subaccount: None,
254+
neuron_id_or_subaccount: id.clone(),
253255
})?;
254256
msgs.push(args);
255257
};
256258

257259
if opts.spawn {
258260
let args = Encode!(&ManageNeuron {
259-
id,
261+
id: None,
260262
command: Some(Command::Spawn(Default::default())),
261-
neuron_id_or_subaccount: None,
263+
neuron_id_or_subaccount: id.clone(),
262264
})?;
263265
msgs.push(args);
264266
};
265267

266268
if let Some(amount) = opts.split {
267269
let args = Encode!(&ManageNeuron {
268-
id,
270+
id: None,
269271
command: Some(Command::Split(Split {
270272
amount_e8s: amount * 100_000_000
271273
})),
272-
neuron_id_or_subaccount: None,
274+
neuron_id_or_subaccount: id.clone(),
273275
})?;
274276
msgs.push(args);
275277
};
276278

277279
if opts.clear_manage_neuron_followees {
278280
let args = Encode!(&ManageNeuron {
279-
id,
281+
id: None,
280282
command: Some(Command::Follow(Follow {
281283
topic: 1, // Topic::NeuronManagement as i32,
282284
followees: Vec::new()
283285
})),
284-
neuron_id_or_subaccount: None,
286+
neuron_id_or_subaccount: id.clone(),
285287
})?;
286288
msgs.push(args);
287289
}
288290

289291
if let Some(neuron_id) = opts.merge_from_neuron {
290292
let args = Encode!(&ManageNeuron {
291-
id,
293+
id: None,
292294
command: Some(Command::Merge(Merge {
293295
source_neuron_id: Some(NeuronId {
294296
id: parse_neuron_id(neuron_id)?
295297
}),
296298
})),
297-
neuron_id_or_subaccount: None,
299+
neuron_id_or_subaccount: id.clone(),
298300
})?;
299301
msgs.push(args);
300302
};
@@ -308,46 +310,46 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
308310
bail!("Percentage to merge must be a number from 1 to 100");
309311
}
310312
let args = Encode!(&ManageNeuron {
311-
id,
313+
id: None,
312314
command: Some(Command::StakeMaturity(StakeMaturity {
313315
percentage_to_stake: Some(percentage),
314316
})),
315-
neuron_id_or_subaccount: None,
317+
neuron_id_or_subaccount: id.clone(),
316318
})?;
317319
msgs.push(args);
318320
}
319321

320322
if opts.join_community_fund {
321323
let args = Encode!(&ManageNeuron {
322-
id,
324+
id: None,
323325
command: Some(Command::Configure(Configure {
324326
operation: Some(Operation::JoinCommunityFund(JoinCommunityFund {}))
325327
})),
326-
neuron_id_or_subaccount: None,
328+
neuron_id_or_subaccount: id.clone(),
327329
})?;
328330
msgs.push(args);
329331
};
330332

331333
if opts.leave_community_fund {
332334
let args = Encode!(&ManageNeuron {
333-
id,
335+
id: None,
334336
command: Some(Command::Configure(Configure {
335337
operation: Some(Operation::LeaveCommunityFund(LeaveCommunityFund {}))
336338
})),
337-
neuron_id_or_subaccount: None,
339+
neuron_id_or_subaccount: id.clone(),
338340
})?;
339341
msgs.push(args);
340342
}
341343

342344
if let Some(proposals) = opts.register_vote {
343345
for proposal in proposals {
344346
let args = Encode!(&ManageNeuron {
345-
id,
347+
id: None,
346348
command: Some(Command::RegisterVote(RegisterVote {
347349
vote: if opts.reject { 2 } else { 1 },
348350
proposal: Some(ProposalId { id: proposal }),
349351
})),
350-
neuron_id_or_subaccount: None,
352+
neuron_id_or_subaccount: id.clone(),
351353
})?;
352354
msgs.push(args);
353355
}
@@ -356,28 +358,28 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
356358
if let (Some(topic), Some(neuron_ids)) = (opts.follow_topic, opts.follow_neurons) {
357359
let followees = neuron_ids.into_iter().map(|x| NeuronId { id: x }).collect();
358360
let args = Encode!(&ManageNeuron {
359-
id,
361+
id: None,
360362
command: Some(Command::Follow(Follow {
361363
topic, // Topic::NeuronManagement as i32,
362364
followees,
363365
})),
364-
neuron_id_or_subaccount: None,
366+
neuron_id_or_subaccount: id.clone(),
365367
})?;
366368
msgs.push(args);
367369
}
368370

369371
if let Some(enable) = opts.auto_stake_maturity {
370372
let requested_setting_for_auto_stake_maturity = matches!(enable, EnableState::Enabled);
371373
let args = Encode!(&ManageNeuron {
372-
id,
374+
id: None,
373375
command: Some(Command::Configure(Configure {
374376
operation: Some(Operation::ChangeAutoStakeMaturity(
375377
ChangeAutoStakeMaturity {
376378
requested_setting_for_auto_stake_maturity,
377379
}
378380
))
379381
})),
380-
neuron_id_or_subaccount: None,
382+
neuron_id_or_subaccount: id.clone(),
381383
})?;
382384
msgs.push(args);
383385
}

src/commands/neuron_stake.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
use crate::{
2-
commands::{
3-
send::Memo,
4-
transfer::{self, parse_tokens},
5-
},
2+
commands::transfer::{self, parse_tokens},
63
lib::{
7-
governance_canister_id,
4+
get_principal, governance_canister_id,
85
signing::{sign_ingress_with_request_status_query, IngressWithRequestId},
96
AnyhowResult, AuthInfo, ParsedNnsAccount, ParsedSubaccount, ROLE_NNS_GOVERNANCE,
107
},
118
};
129
use anyhow::{anyhow, ensure};
13-
use candid::{CandidType, Encode, Principal};
10+
use candid::{Encode, Principal};
1411
use clap::Parser;
1512
use ic_nns_constants::GOVERNANCE_CANISTER_ID;
13+
use ic_nns_governance::pb::v1::{
14+
manage_neuron::{
15+
claim_or_refresh::{By, MemoAndController},
16+
ClaimOrRefresh, Command,
17+
},
18+
ManageNeuron,
19+
};
1620
use icp_ledger::{AccountIdentifier, Subaccount, Tokens};
1721
use sha2::{Digest, Sha256};
1822

19-
#[derive(CandidType)]
20-
pub struct ClaimOrRefreshNeuronFromAccount {
21-
pub memo: Memo,
22-
pub controller: Option<Principal>,
23-
}
24-
2523
/// Signs topping up of a neuron (new or existing).
2624
#[derive(Parser)]
2725
pub struct StakeOpts {
@@ -85,17 +83,22 @@ pub fn exec(auth: &AuthInfo, opts: StakeOpts) -> AnyhowResult<Vec<IngressWithReq
8583
} else {
8684
Vec::new()
8785
};
88-
let args = Encode!(&ClaimOrRefreshNeuronFromAccount {
89-
memo: Memo(nonce),
90-
controller: Some(controller),
91-
})?;
92-
86+
let args = ManageNeuron {
87+
neuron_id_or_subaccount: None,
88+
id: None,
89+
command: Some(Command::ClaimOrRefresh(ClaimOrRefresh {
90+
by: Some(By::MemoAndController(MemoAndController {
91+
controller: Some(get_principal(auth)?.into()),
92+
memo: nonce,
93+
})),
94+
})),
95+
};
9396
messages.push(sign_ingress_with_request_status_query(
94-
auth,
97+
&AuthInfo::NoAuth,
9598
governance_canister_id(),
9699
ROLE_NNS_GOVERNANCE,
97-
"claim_or_refresh_neuron_from_account",
98-
args,
100+
"manage_neuron",
101+
Encode!(&args)?,
99102
)?);
100103

101104
Ok(messages)

0 commit comments

Comments
 (0)