Skip to content

Commit

Permalink
added --send-all option
Browse files Browse the repository at this point in the history
* added `--send-all` option to `send` command, allowing users to send their entire mature balance minus an optional priority fee
* retains feature parity between Go and Rust implementations (the Go node has `--send-all`)
  • Loading branch information
x100111010 committed Oct 26, 2024
1 parent 667ffb3 commit 07fd91b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cli/src/modules/guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ the selected account to an account named 'pete' (starts with a 'p' letter).

`send <address> <amount>` - Sends funds to a destination address.

`send <address> --send-all` - Sends all available funds to a destination address.

`estimate <amount>` - Provides a fee and UTXO consumption estimate for a transaction of a given amount.

`sweep` - Sweeps account UTXOs to reduce the UTXO size.
Expand Down
17 changes: 15 additions & 2 deletions cli/src/modules/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ impl Send {
let account = ctx.wallet().account()?;

if argv.len() < 2 {
tprintln!(ctx, "usage: send <address> <amount> <priority fee>");
tprintln!(ctx, "usage: send <address> <amount|--send-all> <priority fee>");
return Ok(());
}

let address = Address::try_from(argv.first().unwrap().as_str())?;
let amount_sompi = try_parse_required_nonzero_kaspa_as_sompi_u64(argv.get(1))?;
let priority_fee_sompi = try_parse_optional_kaspa_as_sompi_i64(argv.get(2))?.unwrap_or(0);
// handle --send-all
let amount_sompi = if argv.get(1).unwrap() == "--send-all" {
// get mature balance from account
let balance = account.balance().ok_or_else(|| Error::Custom("Failed to retrieve account balance".into()))?;
let mature_balance_sompi = balance.mature;

// subtract priority fee from mature balance
mature_balance_sompi
.checked_sub(priority_fee_sompi.try_into().unwrap_or(0))
.ok_or_else(|| Error::Custom("Insufficient funds to cover the priority fee.".into()))?
} else {
// parse amount if not using --send-all
try_parse_required_nonzero_kaspa_as_sompi_u64(argv.get(1))?
};
let outputs = PaymentOutputs::from((address.clone(), amount_sompi));
let abortable = Abortable::default();
let (wallet_secret, payment_secret) = ctx.ask_wallet_secret(Some(&account)).await?;
Expand Down

0 comments on commit 07fd91b

Please sign in to comment.