Skip to content

Commit

Permalink
[RES-40] Implement update-node-provider command (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiegley authored Dec 17, 2021
1 parent ba9ba40 commit 4805f09
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions candid/governance.did
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> (
Expand All @@ -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;
}
6 changes: 6 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod public;
mod request_status;
mod send;
mod transfer;
mod update_node_provider;

pub use public::get_ids;

Expand All @@ -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 {
Expand All @@ -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 }),
}
}
Expand Down
44 changes: 44 additions & 0 deletions src/commands/update_node_provider.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
}
#[derive(CandidType)]
pub struct UpdateNodeProvider {
pub reward_account: Option<AccountIdentifier>,
}

/// 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<Vec<Ingress>> {
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,
)?])
}
1 change: 1 addition & 0 deletions tests/commands/update-node-provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${CARGO_TARGET_DIR:-../target}/debug/quill update-node-provider --reward-account ec0e2456fb9ff6c80f1d475b301d9b2ab873612f96e7fd74e7c0c0b2d58e6693 | ${CARGO_TARGET_DIR:-../target}/debug/quill send --dry-run -
13 changes: 13 additions & 0 deletions tests/outputs/update-node-provider.txt
Original file line number Diff line number Diff line change
@@ -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";
};
},
)

0 comments on commit 4805f09

Please sign in to comment.