Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: second round of ledger commands #205

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Next Next commit
Update neuron-stake to use the ICRC-1 endpoint
adamspofford-dfinity committed Nov 6, 2023
commit 44674a0802b46ca7f5eeeb36d25c7e15a214da96
13 changes: 8 additions & 5 deletions src/commands/neuron_stake.rs
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@ use crate::{
use anyhow::{anyhow, ensure};
use candid::{CandidType, Encode, Principal};
use clap::Parser;
use ic_nns_constants::GOVERNANCE_CANISTER_ID;
use icp_ledger::{AccountIdentifier, Subaccount, Tokens};
use icp_ledger::Tokens;
use icrc_ledger_types::icrc1::account::{Account, Subaccount};

#[derive(CandidType)]
pub struct ClaimOrRefreshNeuronFromAccount {
@@ -69,12 +69,15 @@ pub fn exec(auth: &AuthInfo, opts: StakeOpts) -> AnyhowResult<Vec<IngressWithReq
_ => return Err(anyhow!("Either a nonce or a name should be specified")),
};
let gov_subaccount = get_neuron_subaccount(&controller, nonce);
let account = AccountIdentifier::new(GOVERNANCE_CANISTER_ID.get(), Some(gov_subaccount));
let account = Account {
owner: governance_canister_id(),
subaccount: Some(gov_subaccount),
};
let mut messages = if !opts.already_transferred {
transfer::exec(
auth,
transfer::TransferOpts {
to: ParsedNnsAccount::Original(account),
to: ParsedNnsAccount::Icrc1(account),
amount: opts.amount.unwrap(),
fee: opts.fee,
memo: Some(nonce),
@@ -109,7 +112,7 @@ fn get_neuron_subaccount(controller: &Principal, nonce: u64) -> Subaccount {
data.update(b"neuron-stake");
data.update(controller.as_slice());
data.update(&nonce.to_be_bytes());
Subaccount(data.finish())
data.finish()
}

fn convert_name_to_nonce(name: &str) -> u64 {
17 changes: 9 additions & 8 deletions tests/output/default/neuron_stake/with_name.txt
Original file line number Diff line number Diff line change
@@ -3,17 +3,18 @@ Sending message with
Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: ryjl3-tyaaa-aaaaa-aaaba-cai
Method name: send_dfx
Method name: icrc1_transfer
Arguments: (
record {
to = "9bc4e24ff90c6898938d5fb339e779cea4edad4de592e591b22429289851b563";
fee = record { e8s = 10_000 : nat64 };
memo = 7_888_422_419_985_231_726 : nat64;
from_subaccount = null;
created_at_time = opt record {
timestamp_nanos = 1_669_073_904_187_044_208 : nat64;
to = record {
owner = principal "rrkah-fqaaa-aaaaa-aaaaq-cai";
subaccount = opt blob "\e1\ba\ec\1a\91u\f3\ec\fb\c1\87\e5J\eb|\96\01)0S\b9\95\98\0e\ad\b2\ee\19\c3\96\88\bf";
};
amount = record { e8s = 1_200_000_000 : nat64 };
fee = opt (10_000 : nat);
memo = opt blob "myNeuron";
from_subaccount = null;
created_at_time = opt (1_669_073_904_187_044_208 : nat64);
amount = 1_200_000_000 : nat;
},
)
Sending message with
17 changes: 9 additions & 8 deletions tests/output/default/neuron_stake/with_nonce.txt
Original file line number Diff line number Diff line change
@@ -3,17 +3,18 @@ Sending message with
Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: ryjl3-tyaaa-aaaaa-aaaba-cai
Method name: send_dfx
Method name: icrc1_transfer
Arguments: (
record {
to = "a0ea9002c2bc3d442050f4431f3732c91dbec13eff79f414b15255d60c4a324c";
fee = record { e8s = 10_000 : nat64 };
memo = 777 : nat64;
from_subaccount = opt blob "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01";
created_at_time = opt record {
timestamp_nanos = 1_669_073_904_187_044_208 : nat64;
to = record {
owner = principal "rrkah-fqaaa-aaaaa-aaaaq-cai";
subaccount = opt blob "r\8a\c1;\10I\a3\ac\af\fe\13\f1;\c7\1e\fd\9b4\97e\80\d4\0d\f2y\b2s n\f14$";
};
amount = record { e8s = 1_200_000_000 : nat64 };
fee = opt (10_000 : nat);
memo = opt blob "\00\00\00\00\00\00\03\09";
from_subaccount = opt blob "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01";
created_at_time = opt (1_669_073_904_187_044_208 : nat64);
amount = 1_200_000_000 : nat;
},
)
Sending message with