aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coinselection.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-11-16 14:31:45 -0500
committerAndrew Chow <achow101-github@achow101.com>2021-12-05 13:39:51 -0500
commit60d2ca72e3f4c56433c63b929a88e7a2def06399 (patch)
tree80ff962de3f9f1e99ee14d6261b38aaf218dcaa6 /src/wallet/coinselection.cpp
parenta339add471717623915cd1a846ade4dab2c89deb (diff)
downloadbitcoin-60d2ca72e3f4c56433c63b929a88e7a2def06399.tar.xz
Return SelectionResult from SelectCoinsBnB
Removes coins_out and value_ret has SelectCoinsBnB return a std::optional<SelectionResult>
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r--src/wallet/coinselection.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index bfe3074944..4d90eefbfe 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -56,17 +56,14 @@ struct {
* bound of the range.
* @param const CAmount& cost_of_change This is the cost of creating and spending a change output.
* This plus selection_target is the upper bound of the range.
- * @param std::set<CInputCoin>& out_set -> This is an output parameter for the set of CInputCoins
- * that have been selected.
- * @param CAmount& value_ret -> This is an output parameter for the total value of the CInputCoins
- * that were selected.
+ * @returns The result of this coin selection algorithm, or std::nullopt
*/
static const size_t TOTAL_TRIES = 100000;
-bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const CAmount& cost_of_change, std::set<CInputCoin>& out_set, CAmount& value_ret)
+std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const CAmount& cost_of_change)
{
- out_set.clear();
+ SelectionResult result(selection_target);
CAmount curr_value = 0;
std::vector<bool> curr_selection; // select the utxo at this index
@@ -80,7 +77,7 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selectio
curr_available_value += utxo.GetSelectionAmount();
}
if (curr_available_value < selection_target) {
- return false;
+ return std::nullopt;
}
// Sort the utxo_pool
@@ -156,19 +153,17 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selectio
// Check for solution
if (best_selection.empty()) {
- return false;
+ return std::nullopt;
}
// Set output set
- value_ret = 0;
for (size_t i = 0; i < best_selection.size(); ++i) {
if (best_selection.at(i)) {
- util::insert(out_set, utxo_pool.at(i).m_outputs);
- value_ret += utxo_pool.at(i).m_value;
+ result.AddInput(utxo_pool.at(i));
}
}
- return true;
+ return result;
}
std::optional<std::pair<std::set<CInputCoin>, CAmount>> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value)
@@ -421,6 +416,7 @@ void SelectionResult::Clear()
void SelectionResult::AddInput(const OutputGroup& group)
{
util::insert(m_selected_inputs, group.m_outputs);
+ m_use_effective = !group.m_subtract_fee_outputs;
}
const std::set<CInputCoin>& SelectionResult::GetInputSet() const