Skip to content

Commit 99034b2

Browse files
committed
wallet: APS, don't create empty groups
By moving the "positive-only" flag out of the lambda function.
1 parent 805f399 commit 99034b2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/wallet/spend.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,9 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet,
444444
// to the last OutputGroup in the vector for the scriptPubKey. When the last OutputGroup has
445445
// OUTPUT_GROUP_MAX_ENTRIES COutputs, a new OutputGroup is added to the end of the vector.
446446
typedef std::map<std::pair<CScript, OutputType>, std::vector<OutputGroup>> ScriptPubKeyToOutgroup;
447-
const auto& group_outputs = [](
447+
const auto& insert_output = [&](
448448
const std::shared_ptr<COutput>& output, OutputType type, size_t ancestors, size_t descendants,
449-
ScriptPubKeyToOutgroup& groups_map, const CoinSelectionParams& coin_sel_params,
450-
bool positive_only) {
449+
ScriptPubKeyToOutgroup& groups_map) {
451450
std::vector<OutputGroup>& groups = groups_map[std::make_pair(output->txout.scriptPubKey,type)];
452451

453452
if (groups.size() == 0) {
@@ -467,10 +466,7 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet,
467466
group = &groups.back();
468467
}
469468

470-
// Filter for positive only before adding the output to group
471-
if (!positive_only || output->GetEffectiveValue() > 0) {
472-
group->Insert(output, ancestors, descendants);
473-
}
469+
group->Insert(output, ancestors, descendants);
474470
};
475471

476472
ScriptPubKeyToOutgroup spk_to_groups_map;
@@ -484,9 +480,13 @@ FilteredOutputGroups GroupOutputs(const CWallet& wallet,
484480
wallet.chain().getTransactionAncestry(output.outpoint.hash, ancestors, descendants);
485481

486482
const auto& shared_output = std::make_shared<COutput>(output);
487-
group_outputs(shared_output, type, ancestors, descendants, spk_to_groups_map, coin_sel_params, /*positive_only=*/ false);
488-
group_outputs(shared_output, type, ancestors, descendants, spk_to_positive_groups_map,
489-
coin_sel_params, /*positive_only=*/ true);
483+
// Filter for positive only before adding the output
484+
if (output.GetEffectiveValue() > 0) {
485+
insert_output(shared_output, type, ancestors, descendants, spk_to_positive_groups_map);
486+
}
487+
488+
// 'All' groups
489+
insert_output(shared_output, type, ancestors, descendants, spk_to_groups_map);
490490
}
491491
}
492492

0 commit comments

Comments
 (0)