aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coinselection.h
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-11-16 14:24:08 -0500
committerAndrew Chow <achow101-github@achow101.com>2021-12-05 13:39:41 -0500
commit9d1d86da04d5d4768975338841285e90b01130b8 (patch)
tree84a0313cb6ea9ca5f5dc6bf173d08f5e57917a6f /src/wallet/coinselection.h
parent94d851d28cb909a8f1f8ab795f1d9fc74bebfc7f (diff)
downloadbitcoin-9d1d86da04d5d4768975338841285e90b01130b8.tar.xz
Introduce SelectionResult struct
Introduces a SelectionResult struct which contains the set of selected inputs and the total transaction fee for the transaction. This will be used by the various SelectCoins* functions. Additionally helpers are provided to compute the total input value and result comparisons.
Diffstat (limited to 'src/wallet/coinselection.h')
-rw-r--r--src/wallet/coinselection.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h
index e7d467660f..056b1bce54 100644
--- a/src/wallet/coinselection.h
+++ b/src/wallet/coinselection.h
@@ -197,6 +197,41 @@ struct OutputGroup
*/
[[nodiscard]] CAmount GetSelectionWaste(const std::set<CInputCoin>& inputs, CAmount change_cost, CAmount target, bool use_effective_value = true);
+struct SelectionResult
+{
+ /** Set of inputs selected by the algorithm to use in the transaction */
+ std::set<CInputCoin> m_selected_inputs;
+ /** The target the algorithm selected for. Note that this may not be equal to the recipient amount as it can include non-input fees */
+ const CAmount m_target;
+ /** Whether the input values for calculations should be the effective value (true) or normal value (false) */
+ bool m_use_effective{false};
+ /** The computed waste */
+ std::optional<CAmount> m_waste;
+
+ explicit SelectionResult(const CAmount target)
+ : m_target(target) {}
+
+ SelectionResult() = delete;
+
+ /** Get the sum of the input values */
+ [[nodiscard]] CAmount GetSelectedValue() const;
+
+ void Clear();
+
+ void AddInput(const OutputGroup& group);
+
+ /** Calculates and stores the waste for this selection via GetSelectionWaste */
+ void ComputeAndSetWaste(CAmount change_cost);
+ [[nodiscard]] CAmount GetWaste() const;
+
+ /** Get m_selected_inputs */
+ const std::set<CInputCoin>& GetInputSet() const;
+ /** Get the vector of CInputCoins that will be used to fill in a CTransaction's vin */
+ std::vector<CInputCoin> GetShuffledInputVector() const;
+
+ bool operator<(SelectionResult other) const;
+};
+
bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const CAmount& cost_of_change, std::set<CInputCoin>& out_set, CAmount& value_ret);
/** Select coins by Single Random Draw. OutputGroups are selected randomly from the eligible