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:
1 file changed
+7
-9
@@ -572,23 +572,21 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
|
|||||||
const CAmount& nTargetValue, const CCoinControl& coin_control,
|
const CAmount& nTargetValue, const CCoinControl& coin_control,
|
||||||
const CoinSelectionParams& coin_selection_params)
|
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 automatic coin selection was disabled, we just want to return the preset inputs result
|
||||||
if (!coin_control.m_allow_other_inputs) {
|
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);
|
SelectionResult result(nTargetValue, SelectionAlgorithm::MANUAL);
|
||||||
result.AddInputs(pre_set_inputs.coins, coin_selection_params.m_subtract_fee_outputs);
|
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);
|
result.ComputeAndSetWaste(coin_selection_params.min_viable_change, coin_selection_params.m_cost_of_change, coin_selection_params.m_change_fee);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease the selection target before start the automatic coin selection
|
// Start wallet Coin Selection procedure
|
||||||
CAmount selection_target = nTargetValue - pre_set_inputs.total_amount;
|
|
||||||
auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_control, coin_selection_params);
|
auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_control, coin_selection_params);
|
||||||
if (!op_selection_result) return op_selection_result;
|
if (!op_selection_result) return op_selection_result;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user