Skip to content

feat: --send-all option #584

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions cli/src/modules/guide.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Before you start, you must configure the default network setting. There are currently
3 networks available. `mainnet`, `testnet-10` and `testnet-11`. If you wish to experiment,
you should select `testnet-11` by entering `network testnet-11`
Before you start, you must configure the default network setting. There are currently
3 networks available: `mainnet`, `testnet-10`, and `testnet-11`. If you wish to experiment,
you should select `testnet-11` by entering `network testnet-11`.

The `server` command configures the target server. You can connect to any Rusty Kaspa
The `server` command configures the target server. You can connect to any Rusty Kaspa
node that has wRPC enabled with `--rpclisten-borsh=0.0.0.0`. If the server setting
is set to 'public' the node will connect to the public node infrastructure.
is set to 'public', the node will connect to the public node infrastructure.

Both network and server values are stored in the application settings and are
used when running a local node or connecting to a remote node.
Expand All @@ -13,43 +13,44 @@ used when running a local node or connecting to a remote node.

`wallet create [<name>]` Use this command to create a local wallet. The <name> argument
is optional (the default wallet name is "kaspa") and allows you to create multiple
named wallets. Only one wallet can be opened at a time. Keep in mind that a wallet can have multiple
accounts, as such you only need one wallet, unless, for example, you want to separate wallets for
named wallets. Only one wallet can be opened at a time. Keep in mind that a wallet can have multiple
accounts, as such you only need one wallet unless, for example, you want to separate wallets for
personal and business needs (but you can also create isolated accounts within a wallet).

Make sure to record your mnemonic, even if working with a testnet, not to lose your
Make sure to record your mnemonic, even if working with a testnet, so as not to lose your
testnet KAS.

`open <name>` - opens the wallet (the wallet is open automatically after creation).
`open <name>` - Opens the wallet (the wallet is open automatically after creation).

`list` - Lists all wallet accounts and their balances.

`select <account-name>` - Selects an active account. The <account-name> can be the first few letters of the name or id of the account.
`select <account-name>` - Selects an active account. The <account-name> can be the first few letters of the name or ID of the account.

`account create bip32 [<name>]` - Allows you to create additional HD wallet accounts linked to the default private key of your wallet.

`address` - shows your selected account address
`address` - Shows your selected account address.

Before you transact: `mute` option (enabled by default) toggles mute on/off. Mute enables terminal
output of internal framework events. Rust and JavaScript/TypeScript applications integrating with this platform
output of internal framework events. Rust and JavaScript/TypeScript applications integrating with this platform
are meant to update their state by monitoring event notifications. Mute allows you to see these events in
the terminal. When mute is off, all events are displayed in the terminal. When mute is on, you can use 'track'
command to enable specific event notification.
the terminal. When mute is off, all events are displayed in the terminal. When mute is on, you can use the 'track'
command to enable specific event notifications.

`transfer <account-name> <amount>` - Transfers from the active to a different account. For example 'transfer p 1' will transfer 1 KAS from
the selected account to an account named 'pete' (starts with a 'p' letter)
`transfer <account-name> <amount>` - Transfers from the active to a different account. For example, 'transfer p 1' will transfer 1 KAS from
the selected account to an account named 'pete' (starts with a 'p' letter).

`send <address> <amount>` - Send funds to a destination address .
`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.

`history list` - Shows previous account transactions.

`history details` - Show previous account transactions with extended information.
`history details` - Shows previous account transactions with extended information.

`monitor` - A test screen environment that periodically updates account balances.

`rpc` - Allows you to execute RPC methods against the node (not all methods are currently available)

`rpc` - Allows you to execute RPC methods against the node (not all methods are currently available).
37 changes: 33 additions & 4 deletions cli/src/modules/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,44 @@ 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 abortable = Abortable::default();

// get priority fee first.
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()))?;

// estimate fee
let fee_sompi = account
.clone()
.estimate(
PaymentDestination::PaymentOutputs(PaymentOutputs::from((address.clone(), balance.mature))),
Fees::ReceiverPays(0),
None,
&abortable,
)
.await?;

// subtract estimated and priority fee
balance
.mature
.checked_sub(fee_sompi.aggregated_fees)
.ok_or_else(|| Error::Custom("Insufficient funds to cover the transaction fee.".into()))?
.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?;

// let ctx_ = ctx.clone();
Expand All @@ -40,7 +69,7 @@ impl Send {

tprintln!(ctx, "Send - {summary}");
tprintln!(ctx, "\nSending {} KAS to {address}, tx ids:", sompi_to_kaspa_string(amount_sompi));
// tprintln!(ctx, "{}\n", ids.into_iter().map(|a| a.to_string()).collect::<Vec<_>>().join("\n"));
tprintln!(ctx, "\n{}\n", _ids.into_iter().map(|a| a.to_string()).collect::<Vec<_>>().join("\n"));

Ok(())
}
Expand Down
Loading