refactor: Return optional of Coin in GetCoin

Leaving the parameter as well for now.

Co-authored-by: TheCharlatan <seb.kung@gmail.com>
This commit is contained in:
Lőrinc
2024-09-08 21:57:18 +02:00
parent e31bfb26c2
commit 46dfbf169b
9 changed files with 41 additions and 38 deletions

View File

@@ -146,14 +146,14 @@ class CoinsViewBottom final : public CCoinsView
std::map<COutPoint, Coin> m_data;
public:
bool GetCoin(const COutPoint& outpoint, Coin& coin) const final
std::optional<Coin> GetCoin(const COutPoint& outpoint, Coin& coin) const final
{
auto it = m_data.find(outpoint);
if (it == m_data.end()) {
return false;
return std::nullopt;
} else {
coin = it->second;
return true; // TODO GetCoin shouldn't return spent coins
return coin; // TODO GetCoin shouldn't return spent coins
}
}
@@ -461,7 +461,7 @@ FUZZ_TARGET(coinscache_sim)
// Compare the bottom coinsview (not a CCoinsViewCache) with sim_cache[0].
for (uint32_t outpointidx = 0; outpointidx < NUM_OUTPOINTS; ++outpointidx) {
Coin realcoin;
bool real = bottom.GetCoin(data.outpoints[outpointidx], realcoin);
auto real = bottom.GetCoin(data.outpoints[outpointidx], realcoin);
auto sim = lookup(outpointidx, 0);
if (!sim.has_value()) {
assert(!real || realcoin.IsSpent());