mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +02:00
Implement fee inclusive transactions (#657)
* Add amount_includes_fee option in TX building * Add --amount_includes_fee CLI option * Implement send 'max' amount Co-authored-by: cliik <cliik@example.com>
This commit is contained in:
@@ -322,6 +322,8 @@ where
|
||||
#[derive(Clone)]
|
||||
pub struct SendArgs {
|
||||
pub amount: u64,
|
||||
pub amount_includes_fee: bool,
|
||||
pub use_max_amount: bool,
|
||||
pub minimum_confirmations: u64,
|
||||
pub selection_strategy: String,
|
||||
pub estimate_selection_strategies: bool,
|
||||
@@ -353,6 +355,15 @@ where
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let mut slate = Slate::blank(2, false);
|
||||
let mut amount = args.amount;
|
||||
if args.use_max_amount {
|
||||
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
|
||||
let (_, wallet_info) =
|
||||
api.retrieve_summary_info(m, true, args.minimum_confirmations)?;
|
||||
amount = wallet_info.amount_currently_spendable;
|
||||
Ok(())
|
||||
})?;
|
||||
};
|
||||
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
|
||||
if args.estimate_selection_strategies {
|
||||
let strategies = vec!["smallest", "all"]
|
||||
@@ -360,7 +371,8 @@ where
|
||||
.map(|strategy| {
|
||||
let init_args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: args.amount,
|
||||
amount: amount,
|
||||
amount_includes_fee: Some(args.amount_includes_fee),
|
||||
minimum_confirmations: args.minimum_confirmations,
|
||||
max_outputs: args.max_outputs as u32,
|
||||
num_change_outputs: args.change_outputs as u32,
|
||||
@@ -372,12 +384,13 @@ where
|
||||
Ok((strategy, slate.amount, slate.fee_fields))
|
||||
})
|
||||
.collect::<Result<Vec<_>, grin_wallet_libwallet::Error>>()?;
|
||||
display::estimate(args.amount, strategies, dark_scheme);
|
||||
display::estimate(amount, strategies, dark_scheme);
|
||||
return Ok(());
|
||||
} else {
|
||||
let init_args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: args.amount,
|
||||
amount: amount,
|
||||
amount_includes_fee: Some(args.amount_includes_fee),
|
||||
minimum_confirmations: args.minimum_confirmations,
|
||||
max_outputs: args.max_outputs as u32,
|
||||
num_change_outputs: args.change_outputs as u32,
|
||||
@@ -394,7 +407,7 @@ where
|
||||
Ok(s) => {
|
||||
info!(
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(args.amount, false),
|
||||
core::amount_to_hr_string(amount, false),
|
||||
args.dest,
|
||||
args.selection_strategy,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user