Changeset View
Changeset View
Standalone View
Standalone View
src/test/coins_tests.cpp
Show All 29 Lines | return a.IsCoinBase() == b.IsCoinBase() && a.GetHeight() == b.GetHeight() && | ||||
a.GetTxOut() == b.GetTxOut(); | a.GetTxOut() == b.GetTxOut(); | ||||
} | } | ||||
class CCoinsViewTest : public CCoinsView { | class CCoinsViewTest : public CCoinsView { | ||||
uint256 hashBestBlock_; | uint256 hashBestBlock_; | ||||
std::map<COutPoint, Coin> map_; | std::map<COutPoint, Coin> map_; | ||||
public: | public: | ||||
bool GetCoin(const COutPoint &outpoint, Coin &coin) const { | bool GetCoin(const COutPoint &outpoint, Coin &coin) const override { | ||||
std::map<COutPoint, Coin>::const_iterator it = map_.find(outpoint); | std::map<COutPoint, Coin>::const_iterator it = map_.find(outpoint); | ||||
if (it == map_.end()) { | if (it == map_.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
coin = it->second; | coin = it->second; | ||||
if (coin.IsSpent() && insecure_rand() % 2 == 0) { | if (coin.IsSpent() && insecure_rand() % 2 == 0) { | ||||
// Randomly return false in case of an empty entry. | // Randomly return false in case of an empty entry. | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool HaveCoin(const COutPoint &outpoint) const { | bool HaveCoin(const COutPoint &outpoint) const override { | ||||
Coin coin; | Coin coin; | ||||
return GetCoin(outpoint, coin); | return GetCoin(outpoint, coin); | ||||
} | } | ||||
uint256 GetBestBlock() const { return hashBestBlock_; } | uint256 GetBestBlock() const override { return hashBestBlock_; } | ||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { | bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override { | ||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | ||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) { | if (it->second.flags & CCoinsCacheEntry::DIRTY) { | ||||
// Same optimization used in CCoinsViewDB is to only write dirty | // Same optimization used in CCoinsViewDB is to only write dirty | ||||
// entries. | // entries. | ||||
map_[it->first] = it->second.coin; | map_[it->first] = it->second.coin; | ||||
if (it->second.coin.IsSpent() && insecure_rand() % 3 == 0) { | if (it->second.coin.IsSpent() && insecure_rand() % 3 == 0) { | ||||
// Randomly delete empty entries on write. | // Randomly delete empty entries on write. | ||||
map_.erase(it->first); | map_.erase(it->first); | ||||
▲ Show 20 Lines • Show All 832 Lines • Show Last 20 Lines |