mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
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:
@@ -163,7 +163,7 @@ FUZZ_TARGET(coins_view, .init = initialize_coins_view)
|
||||
const bool exists_using_have_coin = coins_view_cache.HaveCoin(random_out_point);
|
||||
const bool exists_using_have_coin_in_cache = coins_view_cache.HaveCoinInCache(random_out_point);
|
||||
Coin coin_using_get_coin;
|
||||
const bool exists_using_get_coin = coins_view_cache.GetCoin(random_out_point, coin_using_get_coin);
|
||||
const bool exists_using_get_coin = coins_view_cache.GetCoin(random_out_point, coin_using_get_coin).has_value();
|
||||
if (exists_using_get_coin) {
|
||||
assert(coin_using_get_coin == coin_using_access_coin);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user