Skip to content

Commit

Permalink
Remove usage of deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Jul 9, 2024
1 parent 2e0a7b0 commit b4fdc01
Show file tree
Hide file tree
Showing 49 changed files with 279 additions and 216 deletions.
26 changes: 13 additions & 13 deletions src/commands/account_balance.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use crate::{
commands::{send::submit_unsigned_ingress, SendingOpts},
lib::{
get_account_id, ledger_canister_id, AnyhowResult, AuthInfo, ParsedNnsAccount,
ROLE_ICRC1_LEDGER, ROLE_NNS_LEDGER,
ledger_canister_id, AnyhowResult, AuthInfo, ParsedNnsAccount, ROLE_ICRC1_LEDGER,
ROLE_NNS_LEDGER,
},
AUTH_FLAGS,
};
use candid::{CandidType, Encode};
use candid::Encode;
use clap::Parser;
use icp_ledger::BinaryAccountBalanceArgs;
use icrc_ledger_types::icrc1::account::Account;

use super::get_principal;

#[derive(CandidType)]
pub struct AccountBalanceArgs {
pub account: String,
}

/// Queries a ledger account balance.
#[derive(Parser)]
pub struct AccountBalanceOpts {
Expand All @@ -33,18 +30,21 @@ pub async fn exec(auth: &AuthInfo, opts: AccountBalanceOpts, fetch_root_key: boo
let account_id = if let Some(id) = opts.account_id {
id
} else {
let id = get_account_id(get_principal(auth)?, None)?;
ParsedNnsAccount::Original(id)
let account = Account {
owner: get_principal(auth)?,
subaccount: None,
};
ParsedNnsAccount::Icrc1(account)
};
match account_id {
ParsedNnsAccount::Original(id) => {
let args = Encode!(&AccountBalanceArgs {
account: id.to_hex()
let args = Encode!(&BinaryAccountBalanceArgs {
account: id.to_address()
})?;
submit_unsigned_ingress(
ledger_canister_id(),
ROLE_NNS_LEDGER,
"account_balance_dfx",
"account_balance",
args,
opts.sending_opts,
fetch_root_key,
Expand Down
70 changes: 36 additions & 34 deletions src/commands/neuron_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use candid::{CandidType, Encode, Principal};
use clap::{Parser, ValueEnum};
use ic_base_types::PrincipalId;
use ic_nns_common::pb::v1::{NeuronId, ProposalId};
use ic_nns_governance::pb::v1::manage_neuron::NeuronIdOrSubaccount;
use ic_nns_governance::pb::v1::{
manage_neuron::{
configure::Operation, disburse::Amount, AddHotKey, ChangeAutoStakeMaturity, Command,
Expand Down Expand Up @@ -142,60 +143,61 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
}
let mut msgs = Vec::new();

let id = Some(NeuronId {
let id = NeuronId {
id: parse_neuron_id(opts.neuron_id)?,
});
};
let id = Some(NeuronIdOrSubaccount::NeuronId(id));
if opts.add_hot_key.is_some() {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::AddHotKey(AddHotKey {
new_hot_key: opts.add_hot_key.map(PrincipalId)
}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.remove_hot_key.is_some() {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::RemoveHotKey(RemoveHotKey {
hot_key_to_remove: opts.remove_hot_key.map(PrincipalId)
}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.stop_dissolving {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::StopDissolving(StopDissolving {}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if opts.start_dissolving {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::StartDissolving(StartDissolving {}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if let Some(additional_dissolve_delay_seconds) = opts.additional_dissolve_delay_seconds {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::IncreaseDissolveDelay(IncreaseDissolveDelay {
additional_dissolve_delay_seconds: match additional_dissolve_delay_seconds
Expand Down Expand Up @@ -235,66 +237,66 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
}
}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.disburse || opts.disburse_amount.is_some() || opts.disburse_to.is_some() {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Disburse(Disburse {
to_account: opts.disburse_to.map(|to| to.into_identifier().into()),
amount: opts.disburse_amount.map(|amount| Amount {
e8s: amount.get_e8s()
}),
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.spawn {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Spawn(Default::default())),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if let Some(amount) = opts.split {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Split(Split {
amount_e8s: amount * 100_000_000
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.clear_manage_neuron_followees {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Follow(Follow {
topic: 1, // Topic::NeuronManagement as i32,
followees: Vec::new()
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if let Some(neuron_id) = opts.merge_from_neuron {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Merge(Merge {
source_neuron_id: Some(NeuronId {
id: parse_neuron_id(neuron_id)?
}),
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};
Expand All @@ -308,46 +310,46 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
bail!("Percentage to merge must be a number from 1 to 100");
}
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::StakeMaturity(StakeMaturity {
percentage_to_stake: Some(percentage),
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if opts.join_community_fund {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::JoinCommunityFund(JoinCommunityFund {}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
};

if opts.leave_community_fund {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::LeaveCommunityFund(LeaveCommunityFund {}))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if let Some(proposals) = opts.register_vote {
for proposal in proposals {
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::RegisterVote(RegisterVote {
vote: if opts.reject { 2 } else { 1 },
proposal: Some(ProposalId { id: proposal }),
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}
Expand All @@ -356,28 +358,28 @@ Cannot use --ledger with these flags. This version of quill only supports the fo
if let (Some(topic), Some(neuron_ids)) = (opts.follow_topic, opts.follow_neurons) {
let followees = neuron_ids.into_iter().map(|x| NeuronId { id: x }).collect();
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Follow(Follow {
topic, // Topic::NeuronManagement as i32,
followees,
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}

if let Some(enable) = opts.auto_stake_maturity {
let requested_setting_for_auto_stake_maturity = matches!(enable, EnableState::Enabled);
let args = Encode!(&ManageNeuron {
id,
id: None,
command: Some(Command::Configure(Configure {
operation: Some(Operation::ChangeAutoStakeMaturity(
ChangeAutoStakeMaturity {
requested_setting_for_auto_stake_maturity,
}
))
})),
neuron_id_or_subaccount: None,
neuron_id_or_subaccount: id.clone(),
})?;
msgs.push(args);
}
Expand Down
43 changes: 23 additions & 20 deletions src/commands/neuron_stake.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
use crate::{
commands::{
send::Memo,
transfer::{self, parse_tokens},
},
commands::transfer::{self, parse_tokens},
lib::{
governance_canister_id,
get_principal, governance_canister_id,
signing::{sign_ingress_with_request_status_query, IngressWithRequestId},
AnyhowResult, AuthInfo, ParsedNnsAccount, ParsedSubaccount, ROLE_NNS_GOVERNANCE,
},
};
use anyhow::{anyhow, ensure};
use candid::{CandidType, Encode, Principal};
use candid::{Encode, Principal};
use clap::Parser;
use ic_nns_constants::GOVERNANCE_CANISTER_ID;
use ic_nns_governance::pb::v1::{
manage_neuron::{
claim_or_refresh::{By, MemoAndController},
ClaimOrRefresh, Command,
},
ManageNeuron,
};
use icp_ledger::{AccountIdentifier, Subaccount, Tokens};
use sha2::{Digest, Sha256};

#[derive(CandidType)]
pub struct ClaimOrRefreshNeuronFromAccount {
pub memo: Memo,
pub controller: Option<Principal>,
}

/// Signs topping up of a neuron (new or existing).
#[derive(Parser)]
pub struct StakeOpts {
Expand Down Expand Up @@ -85,17 +83,22 @@ pub fn exec(auth: &AuthInfo, opts: StakeOpts) -> AnyhowResult<Vec<IngressWithReq
} else {
Vec::new()
};
let args = Encode!(&ClaimOrRefreshNeuronFromAccount {
memo: Memo(nonce),
controller: Some(controller),
})?;

let args = ManageNeuron {
neuron_id_or_subaccount: None,
id: None,
command: Some(Command::ClaimOrRefresh(ClaimOrRefresh {
by: Some(By::MemoAndController(MemoAndController {
controller: Some(get_principal(auth)?.into()),
memo: nonce,
})),
})),
};
messages.push(sign_ingress_with_request_status_query(
auth,
&AuthInfo::NoAuth,
governance_canister_id(),
ROLE_NNS_GOVERNANCE,
"claim_or_refresh_neuron_from_account",
args,
"manage_neuron",
Encode!(&args)?,
)?);

Ok(messages)
Expand Down
Loading

0 comments on commit b4fdc01

Please sign in to comment.