aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-09-27 23:22:34 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-12-05 13:40:48 -0500
commit51a9c00b4de707e0a6a1a68ca6f8e38d86c72d94 (patch)
tree435e69873661a7022289d2957b6f8dcedf071602 /src/wallet
parent0ef6184575e77b17f5ec6d7ca086900aca79f6d7 (diff)
Return SelectionResult from SelectCoinsSRD
Changes SelectCoinsSRD to return a SelectionResult.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/coinselection.cpp10
-rw-r--r--src/wallet/coinselection.h4
-rw-r--r--src/wallet/spend.cpp7
3 files changed, 9 insertions, 12 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index 97918429e0..a85547f5b2 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -166,10 +166,9 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
return result;
}
-std::optional<std::pair<std::set<CInputCoin>, CAmount>> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value)
+std::optional<SelectionResult> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value)
{
- std::set<CInputCoin> out_set;
- CAmount value_ret = 0;
+ SelectionResult result(target_value);
std::vector<size_t> indexes;
indexes.resize(utxo_pool.size());
@@ -181,10 +180,9 @@ std::optional<std::pair<std::set<CInputCoin>, CAmount>> SelectCoinsSRD(const std
const OutputGroup& group = utxo_pool.at(i);
Assume(group.GetSelectionAmount() > 0);
selected_eff_value += group.GetSelectionAmount();
- value_ret += group.m_value;
- util::insert(out_set, group.m_outputs);
+ result.AddInput(group);
if (selected_eff_value >= target_value) {
- return std::make_pair(out_set, value_ret);
+ return result;
}
}
return std::nullopt;
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h
index 23bdff73c2..aa5ec822ec 100644
--- a/src/wallet/coinselection.h
+++ b/src/wallet/coinselection.h
@@ -241,9 +241,9 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
*
* @param[in] utxo_pool The positive effective value OutputGroups eligible for selection
* @param[in] target_value The target value to select for
- * @returns If successful, a pair of set of outputs and total selected value, otherwise, std::nullopt
+ * @returns If successful, a SelectionResult, otherwise, std::nullopt
*/
-std::optional<std::pair<std::set<CInputCoin>, CAmount>> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value);
+std::optional<SelectionResult> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value);
// Original coin selection algorithm as a fallback
std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue);
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index e953c83c10..ef8885e738 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -402,10 +402,9 @@ bool AttemptSelection(const CWallet& wallet, const CAmount& nTargetValue, const
// We include the minimum final change for SRD as we do want to avoid making really small change.
// KnapsackSolver does not need this because it includes MIN_CHANGE internally.
const CAmount srd_target = nTargetValue + coin_selection_params.m_change_fee + MIN_FINAL_CHANGE;
- auto srd_result = SelectCoinsSRD(positive_groups, srd_target);
- if (srd_result != std::nullopt) {
- const auto waste = GetSelectionWaste(srd_result->first, coin_selection_params.m_cost_of_change, srd_target, !coin_selection_params.m_subtract_fee_outputs);
- results.emplace_back(std::make_tuple(waste, std::move(srd_result->first), srd_result->second));
+ if (auto srd_result{SelectCoinsSRD(positive_groups, srd_target)}) {
+ srd_result->ComputeAndSetWaste(coin_selection_params.m_cost_of_change);
+ results.emplace_back(std::make_tuple(srd_result->GetWaste(), srd_result->GetInputSet(), srd_result->GetSelectedValue()));
}
if (results.size() == 0) {