mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 17:02:00 +02:00
wallet: add assert to SelectionResult::Merge for safety
This commit is contained in:
parent
c4e3b7d6a1
commit
3282fad599
@ -452,12 +452,16 @@ void SelectionResult::AddInputs(const std::set<COutput>& inputs, bool subtract_f
|
|||||||
|
|
||||||
void SelectionResult::Merge(const SelectionResult& other)
|
void SelectionResult::Merge(const SelectionResult& other)
|
||||||
{
|
{
|
||||||
|
// Obtain the expected selected inputs count after the merge (for now, duplicates are not allowed)
|
||||||
|
const size_t expected_count = m_selected_inputs.size() + other.m_selected_inputs.size();
|
||||||
|
|
||||||
m_target += other.m_target;
|
m_target += other.m_target;
|
||||||
m_use_effective |= other.m_use_effective;
|
m_use_effective |= other.m_use_effective;
|
||||||
if (m_algo == SelectionAlgorithm::MANUAL) {
|
if (m_algo == SelectionAlgorithm::MANUAL) {
|
||||||
m_algo = other.m_algo;
|
m_algo = other.m_algo;
|
||||||
}
|
}
|
||||||
util::insert(m_selected_inputs, other.m_selected_inputs);
|
util::insert(m_selected_inputs, other.m_selected_inputs);
|
||||||
|
assert(m_selected_inputs.size() == expected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::set<COutput>& SelectionResult::GetInputSet() const
|
const std::set<COutput>& SelectionResult::GetInputSet() const
|
||||||
|
@ -316,6 +316,12 @@ public:
|
|||||||
void ComputeAndSetWaste(const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee);
|
void ComputeAndSetWaste(const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee);
|
||||||
[[nodiscard]] CAmount GetWaste() const;
|
[[nodiscard]] CAmount GetWaste() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines the @param[in] other selection result into 'this' selection result.
|
||||||
|
*
|
||||||
|
* Important note:
|
||||||
|
* There must be no shared 'COutput' among the two selection results being combined.
|
||||||
|
*/
|
||||||
void Merge(const SelectionResult& other);
|
void Merge(const SelectionResult& other);
|
||||||
|
|
||||||
/** Get m_selected_inputs */
|
/** Get m_selected_inputs */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user