Skip to content

Commit

Permalink
Add --from-subaccount to transfer/stake (#166)
Browse files Browse the repository at this point in the history
This was present for ckBTC and SNS, but not for base NNS commands.
  • Loading branch information
adamspofford-dfinity authored Mar 1, 2023
1 parent da63aef commit a432d35
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
13 changes: 7 additions & 6 deletions docs/cli-reference/quill-neuron-stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ quill neuron-stake [option]

## Options

| Option | Description |
|---------------------|----------------------------------------------------|
| `--amount <AMOUNT>` | ICPs to be staked on the newly created neuron. |
| `--fee <FEE>` | Transaction fee, default is 10000 e8s. |
| `--name <NAME>` | The name of the neuron (up to 8 ASCII characters). |
| `--nonce <NONCE>` | The nonce of the neuron. |
| Option | Description |
|----------------------------------|----------------------------------------------------|
| `--amount <AMOUNT>` | ICPs to be staked on the newly created neuron. |
| `--fee <FEE>` | Transaction fee, default is 10000 e8s. |
| `--from-subaccount <SUBACCOUNT>` | The subaccount to transfer from. |
| `--name <NAME>` | The name of the neuron (up to 8 ASCII characters). |
| `--nonce <NONCE>` | The nonce of the neuron. |

## Examples

Expand Down
11 changes: 6 additions & 5 deletions docs/cli-reference/quill-transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ quill transfer [option] --amount <AMOUNT> <TO>

## Options

| Option | Description |
|---------------------|-----------------------------------------------------------------------|
| `--amount <AMOUNT>` | Amount of ICPs to transfer (with up to 8 decimal digits after comma). |
| `--fee <FEE>` | Transaction fee, default is 10000 e8s. |
| `--memo <MEMO>` | Reference number, default is 0. |
| Option | Description |
|----------------------------------|-----------------------------------------------------------------------|
| `--amount <AMOUNT>` | Amount of ICPs to transfer (with up to 8 decimal digits after comma). |
| `--fee <FEE>` | Transaction fee, default is 10000 e8s. |
| `--from-subaccount <SUBACCOUNT>` | The subaccount to transfer from. |
| `--memo <MEMO>` | Reference number, default is 0. |

## Examples

Expand Down
7 changes: 6 additions & 1 deletion src/commands/neuron_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
lib::{
governance_canister_id,
signing::{sign_ingress_with_request_status_query, IngressWithRequestId},
AnyhowResult, AuthInfo, ROLE_NNS_GOVERNANCE,
AnyhowResult, AuthInfo, ParsedSubaccount, ROLE_NNS_GOVERNANCE,
},
};
use anyhow::anyhow;
Expand Down Expand Up @@ -39,6 +39,10 @@ pub struct StakeOpts {
/// Transaction fee, default is 0.0001 ICP.
#[clap(long, value_parser = parse_tokens)]
fee: Option<Tokens>,

/// The subaccount to transfer from.
#[clap(long)]
from_subaccount: Option<ParsedSubaccount>,
}

pub fn exec(auth: &AuthInfo, opts: StakeOpts) -> AnyhowResult<Vec<IngressWithRequestId>> {
Expand All @@ -58,6 +62,7 @@ pub fn exec(auth: &AuthInfo, opts: StakeOpts) -> AnyhowResult<Vec<IngressWithReq
amount,
fee: opts.fee,
memo: Some(nonce),
from_subaccount: opts.from_subaccount,
},
)?,
_ => Vec::new(),
Expand Down
8 changes: 6 additions & 2 deletions src/commands/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::commands::send::{Memo, SendArgs};
use crate::lib::ROLE_NNS_LEDGER;
use crate::lib::{
ledger_canister_id,
signing::{sign_ingress_with_request_status_query, IngressWithRequestId},
AnyhowResult, AuthInfo,
};
use crate::lib::{ParsedSubaccount, ROLE_NNS_LEDGER};
use anyhow::{anyhow, bail, Context};
use candid::Encode;
use clap::Parser;
Expand All @@ -27,6 +27,10 @@ pub struct TransferOpts {
/// Transaction fee, default is 0.0001 ICP.
#[clap(long, value_parser = parse_tokens)]
pub fee: Option<Tokens>,

/// The subaccount to transfer from.
#[clap(long)]
pub from_subaccount: Option<ParsedSubaccount>,
}

pub fn exec(auth: &AuthInfo, opts: TransferOpts) -> AnyhowResult<Vec<IngressWithRequestId>> {
Expand All @@ -39,7 +43,7 @@ pub fn exec(auth: &AuthInfo, opts: TransferOpts) -> AnyhowResult<Vec<IngressWith
memo,
amount,
fee,
from_subaccount: None,
from_subaccount: opts.from_subaccount.map(|x| x.0),
to,
created_at_time: None,
})?;
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/neuron-stake-nonce.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"$QUILL" neuron-stake --amount 12 --nonce 777 --pem-file - | "$QUILL" send --dry-run -
"$QUILL" neuron-stake --amount 12 --from-subaccount 01 --nonce 777 --pem-file - | "$QUILL" send --dry-run -
2 changes: 1 addition & 1 deletion tests/commands/transfer-e8s-2.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"$QUILL" transfer 345f723e9e619934daac6ae0f4be13a7b0ba57d6a608e511a00fd0ded5866752 --amount 0.0000000999999 --pem-file - | "$QUILL" send --dry-run -
"$QUILL" transfer 345f723e9e619934daac6ae0f4be13a7b0ba57d6a608e511a00fd0ded5866752 --from-subaccount 01 --amount 0.0000000999999 --pem-file - | "$QUILL" send --dry-run -
2 changes: 1 addition & 1 deletion tests/outputs/neuron-stake-nonce.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Sending message with
to = "a0ea9002c2bc3d442050f4431f3732c91dbec13eff79f414b15255d60c4a324c";
fee = record { e8s = 10_000 : nat64 };
memo = 777 : nat64;
from_subaccount = null;
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 = null;
amount = record { e8s = 1_200_000_000 : nat64 };
},
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/transfer-e8s-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Sending message with
to = "345f723e9e619934daac6ae0f4be13a7b0ba57d6a608e511a00fd0ded5866752";
fee = record { e8s = 10_000 : nat64 };
memo = 0 : nat64;
from_subaccount = null;
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 = null;
amount = record { e8s = 9 : nat64 };
},
Expand Down

0 comments on commit a432d35

Please sign in to comment.