diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-10-04 11:04:48 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-10-26 15:54:31 -0300 |
commit | f41712a734dc119f8a5e053a9cfa1f0411b5e8f1 (patch) | |
tree | 04cb3de84d041c1a83c30b622302a644f399cd77 /src | |
parent | 5baedc33519661af9d19efcefd23dca8998d2547 (diff) | |
download | bitcoin-f41712a734dc119f8a5e053a9cfa1f0411b5e8f1.tar.xz |
wallet: simplify preset inputs selection target check
we are already computing the preset inputs total amount inside `PreSelectedInputs::Insert`,
which internally decides whether to use the effective value or the raw output value based on
the 'subtract_fee_outputs' flag.
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/spend.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 84c96b041f..f17a53348b 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -572,23 +572,21 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a const CAmount& nTargetValue, const CCoinControl& coin_control, const CoinSelectionParams& coin_selection_params) { + // Deduct preset inputs amount from the search target + CAmount selection_target = nTargetValue - pre_set_inputs.total_amount; + // If automatic coin selection was disabled, we just want to return the preset inputs result if (!coin_control.m_allow_other_inputs) { + // 'selection_target' is computed on `PreSelectedInputs::Insert` which decides whether to use the effective value + // or the raw output value based on the 'subtract_fee_outputs' flag. + if (selection_target > 0) return std::nullopt; SelectionResult result(nTargetValue, SelectionAlgorithm::MANUAL); result.AddInputs(pre_set_inputs.coins, coin_selection_params.m_subtract_fee_outputs); - - if (!coin_selection_params.m_subtract_fee_outputs && result.GetSelectedEffectiveValue() < nTargetValue) { - return std::nullopt; - } else if (result.GetSelectedValue() < nTargetValue) { - return std::nullopt; - } - result.ComputeAndSetWaste(coin_selection_params.min_viable_change, coin_selection_params.m_cost_of_change, coin_selection_params.m_change_fee); return result; } - // Decrease the selection target before start the automatic coin selection - CAmount selection_target = nTargetValue - pre_set_inputs.total_amount; + // Start wallet Coin Selection procedure auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_control, coin_selection_params); if (!op_selection_result) return op_selection_result; |