Skip to content

Commit f930aef

Browse files
committed
wallet: bugfix, 'CoinsResult::Erase' is erasing only one output of the set
The loop break shouldn't have being there.
1 parent 38d06e1 commit f930aef

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/wallet/spend.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ void CoinsResult::Clear() {
102102
coins.clear();
103103
}
104104

105-
void CoinsResult::Erase(std::set<COutPoint>& preset_coins)
105+
void CoinsResult::Erase(const std::unordered_set<COutPoint, SaltedOutpointHasher>& coins_to_remove)
106106
{
107-
for (auto& it : coins) {
108-
auto& vec = it.second;
109-
auto i = std::find_if(vec.begin(), vec.end(), [&](const COutput &c) { return preset_coins.count(c.outpoint);});
110-
if (i != vec.end()) {
111-
vec.erase(i);
112-
break;
113-
}
107+
for (auto& [type, vec] : coins) {
108+
auto remove_it = std::remove_if(vec.begin(), vec.end(), [&](const COutput& coin) {
109+
return coins_to_remove.count(coin.outpoint) == 1;
110+
});
111+
vec.erase(remove_it, vec.end());
114112
}
115113
}
116114

src/wallet/spend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct CoinsResult {
4747
* i.e., methods can work with individual OutputType vectors or on the entire object */
4848
size_t Size() const;
4949
void Clear();
50-
void Erase(std::set<COutPoint>& preset_coins);
50+
void Erase(const std::unordered_set<COutPoint, SaltedOutpointHasher>& coins_to_remove);
5151
void Shuffle(FastRandomContext& rng_fast);
5252
void Add(OutputType type, const COutput& out);
5353

0 commit comments

Comments
 (0)