From 4805f093ae16f5d46da50ad48c7758f2353797e1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 17 Dec 2021 09:28:08 -0800 Subject: [PATCH] [RES-40] Implement update-node-provider command (#87) --- candid/governance.did | 2 ++ src/commands/mod.rs | 6 ++++ src/commands/update_node_provider.rs | 44 ++++++++++++++++++++++++++ tests/commands/update-node-provider.sh | 1 + tests/outputs/update-node-provider.txt | 13 ++++++++ 5 files changed, 66 insertions(+) create mode 100644 src/commands/update_node_provider.rs create mode 100644 tests/commands/update-node-provider.sh create mode 100644 tests/outputs/update-node-provider.txt diff --git a/candid/governance.did b/candid/governance.did index 7e1c5a33..c5fa7cca 100644 --- a/candid/governance.did +++ b/candid/governance.did @@ -262,6 +262,7 @@ type Tally = record { total : nat64; timestamp_seconds : nat64; }; +type UpdateNodeProvider = record { reward_account : opt AccountIdentifier }; service : (Governance) -> { claim_gtc_neurons : (principal, vec NeuronId) -> (Result); claim_or_refresh_neuron_from_account : (ClaimOrRefreshNeuronFromAccount) -> ( @@ -276,4 +277,5 @@ service : (Governance) -> { list_proposals : (ListProposalInfo) -> (ListProposalInfoResponse) query; manage_neuron : (ManageNeuron) -> (ManageNeuronResponse); transfer_gtc_neuron : (NeuronId, NeuronId) -> (Result); + update_node_provider : (UpdateNodeProvider) -> (Result) query; } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 6916a378..3ace6158 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -16,6 +16,7 @@ mod public; mod request_status; mod send; mod transfer; +mod update_node_provider; pub use public::get_ids; @@ -35,6 +36,8 @@ pub enum Command { GetProposalInfo(get_proposal_info::GetProposalInfoOpts), /// Queries a ledger account balance AccountBalance(account_balance::AccountBalanceOpts), + /// Update node provider details + UpdateNodeProvider(update_node_provider::UpdateNodeProviderOpts), } pub fn exec(auth: &AuthInfo, cmd: Command) -> AnyhowResult { @@ -55,6 +58,9 @@ pub fn exec(auth: &AuthInfo, cmd: Command) -> AnyhowResult { Command::AccountBalance(opts) => { runtime.block_on(async { account_balance::exec(opts).await }) } + Command::UpdateNodeProvider(opts) => { + update_node_provider::exec(auth, opts).and_then(|out| print(&out)) + } Command::Send(opts) => runtime.block_on(async { send::exec(opts).await }), } } diff --git a/src/commands/update_node_provider.rs b/src/commands/update_node_provider.rs new file mode 100644 index 00000000..55d77d2c --- /dev/null +++ b/src/commands/update_node_provider.rs @@ -0,0 +1,44 @@ +use crate::{ + lib::signing::{sign_ingress, Ingress}, + lib::{governance_canister_id, AnyhowResult, AuthInfo}, +}; +use candid::{CandidType, Encode}; +use clap::Parser; + +#[derive(CandidType)] +pub struct AccountIdentifier { + hash: Vec, +} +#[derive(CandidType)] +pub struct UpdateNodeProvider { + pub reward_account: Option, +} + +/// Signs a neuron configuration change. +#[derive(Parser)] +pub struct UpdateNodeProviderOpts { + /// The account identifier of the reward account. + #[clap(long)] + reward_account: String, +} + +pub fn exec(auth: &AuthInfo, opts: UpdateNodeProviderOpts) -> AnyhowResult> { + let reward_account = ledger_canister::AccountIdentifier::from_hex(&opts.reward_account) + .map_err(|e| { + anyhow::Error::msg(format!( + "Account {} is not valid address, {}", + &opts.reward_account, e, + )) + })?; + let args = Encode!(&UpdateNodeProvider { + reward_account: Some(AccountIdentifier { + hash: reward_account.hash.to_vec() + }) + })?; + Ok(vec![sign_ingress( + auth, + governance_canister_id(), + "update_node_provider", + args, + )?]) +} diff --git a/tests/commands/update-node-provider.sh b/tests/commands/update-node-provider.sh new file mode 100644 index 00000000..d21f5d31 --- /dev/null +++ b/tests/commands/update-node-provider.sh @@ -0,0 +1 @@ +${CARGO_TARGET_DIR:-../target}/debug/quill update-node-provider --reward-account ec0e2456fb9ff6c80f1d475b301d9b2ab873612f96e7fd74e7c0c0b2d58e6693 | ${CARGO_TARGET_DIR:-../target}/debug/quill send --dry-run - diff --git a/tests/outputs/update-node-provider.txt b/tests/outputs/update-node-provider.txt new file mode 100644 index 00000000..ec5293b9 --- /dev/null +++ b/tests/outputs/update-node-provider.txt @@ -0,0 +1,13 @@ +Sending message with + + Call type: query + Sender: 2vxsx-fae + Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai + Method name: update_node_provider + Arguments: ( + record { + reward_account = opt record { + hash = blob "\fb\9f\f6\c8\0f\1dG[0\1d\9b*\b8sa/\96\e7\fdt\e7\c0\c0\b2\d5\8ef\93"; + }; + }, +)