diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-08-02 11:54:20 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2023-03-06 09:45:40 -0300 |
commit | bd91ed1cb2cc804f824d1b204513ac2afb7d5e28 (patch) | |
tree | 9956b147f73c622e5f895337fb27c1c3a0098613 /src/wallet/coinselection.cpp | |
parent | 55962001da4f8467e52da502b05f5c0a85128fb0 (diff) | |
download | bitcoin-bd91ed1cb2cc804f824d1b204513ac2afb7d5e28.tar.xz |
wallet: unify outputs grouping process
The 'GroupOutputs()' function performs the same
calculations for only-positive and mixed groups,
the only difference is that when we look for
only-positive groups, we discard negative utxos.
So, instead of wasting resources calling GroupOutputs()
for positive-only first, then call it again to include
the negative ones in the result, we can execute
GroupOutputs() only once, including in the response
both group types (positive-only and mixed).
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r-- | src/wallet/coinselection.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index f99beabc70..3fd0280b8b 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -372,6 +372,28 @@ CAmount OutputGroup::GetSelectionAmount() const return m_subtract_fee_outputs ? m_value : effective_value; } +void OutputGroupTypeMap::Push(const OutputGroup& group, OutputType type, bool insert_positive, bool insert_mixed) +{ + if (group.m_outputs.empty()) return; + + Groups& groups = groups_by_type[type]; + if (insert_positive && group.GetSelectionAmount() > 0) { + groups.positive_group.emplace_back(group); + all_groups.positive_group.emplace_back(group); + } + if (insert_mixed) { + groups.mixed_group.emplace_back(group); + all_groups.mixed_group.emplace_back(group); + } +} + +std::optional<Groups> OutputGroupTypeMap::Find(OutputType type) +{ + auto it_by_type = groups_by_type.find(type); + if (it_by_type == groups_by_type.end()) return std::nullopt; + return it_by_type->second; +} + CAmount GetSelectionWaste(const std::set<std::shared_ptr<COutput>>& inputs, CAmount change_cost, CAmount target, bool use_effective_value) { // This function should not be called with empty inputs as that would mean the selection failed |