mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
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).
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <outputtype.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <random.h>
|
||||
@@ -249,6 +250,21 @@ struct Groups {
|
||||
std::vector<OutputGroup> mixed_group;
|
||||
};
|
||||
|
||||
/** Stores several 'Groups' whose were mapped by output type. */
|
||||
struct OutputGroupTypeMap
|
||||
{
|
||||
// Maps output type to output groups.
|
||||
std::map<OutputType, Groups> groups_by_type;
|
||||
// All inserted groups, no type distinction.
|
||||
Groups all_groups;
|
||||
|
||||
// Based on the insert flag; appends group to the 'mixed_group' and, if value > 0, to the 'positive_group'.
|
||||
// This affects both; the groups filtered by type and the overall groups container.
|
||||
void Push(const OutputGroup& group, OutputType type, bool insert_positive, bool insert_mixed);
|
||||
// Retrieves 'Groups' filtered by type
|
||||
std::optional<Groups> Find(OutputType type);
|
||||
};
|
||||
|
||||
/** Compute the waste for this result given the cost of change
|
||||
* and the opportunity cost of spending these inputs now vs in the future.
|
||||
* If change exists, waste = change_cost + inputs * (effective_feerate - long_term_feerate)
|
||||
|
||||
Reference in New Issue
Block a user