mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
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.
This commit is contained in:
parent
5baedc3351
commit
f41712a734
1 changed files with 7 additions and 9 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue