Skip to content

Commit f41712a

Browse files
committed
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.
1 parent 5baedc3 commit f41712a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/wallet/spend.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,23 +572,21 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
572572
const CAmount& nTargetValue, const CCoinControl& coin_control,
573573
const CoinSelectionParams& coin_selection_params)
574574
{
575+
// Deduct preset inputs amount from the search target
576+
CAmount selection_target = nTargetValue - pre_set_inputs.total_amount;
577+
575578
// If automatic coin selection was disabled, we just want to return the preset inputs result
576579
if (!coin_control.m_allow_other_inputs) {
580+
// 'selection_target' is computed on `PreSelectedInputs::Insert` which decides whether to use the effective value
581+
// or the raw output value based on the 'subtract_fee_outputs' flag.
582+
if (selection_target > 0) return std::nullopt;
577583
SelectionResult result(nTargetValue, SelectionAlgorithm::MANUAL);
578584
result.AddInputs(pre_set_inputs.coins, coin_selection_params.m_subtract_fee_outputs);
579-
580-
if (!coin_selection_params.m_subtract_fee_outputs && result.GetSelectedEffectiveValue() < nTargetValue) {
581-
return std::nullopt;
582-
} else if (result.GetSelectedValue() < nTargetValue) {
583-
return std::nullopt;
584-
}
585-
586585
result.ComputeAndSetWaste(coin_selection_params.min_viable_change, coin_selection_params.m_cost_of_change, coin_selection_params.m_change_fee);
587586
return result;
588587
}
589588

590-
// Decrease the selection target before start the automatic coin selection
591-
CAmount selection_target = nTargetValue - pre_set_inputs.total_amount;
589+
// Start wallet Coin Selection procedure
592590
auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_control, coin_selection_params);
593591
if (!op_selection_result) return op_selection_result;
594592

0 commit comments

Comments
 (0)