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:
furszy 2022-10-04 11:04:48 -03:00
parent 5baedc3351
commit f41712a734
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623

View file

@ -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;