Changeset View
Changeset View
Standalone View
Standalone View
src/coins.cpp
// Copyright (c) 2012-2016 The Bitcoin Core developers | // Copyright (c) 2012-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <consensus/consensus.h> | #include <consensus/consensus.h> | ||||
#include <memusage.h> | #include <memusage.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <version.h> | #include <version.h> | ||||
#include <cassert> | #include <cassert> | ||||
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { | bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { | ||||
return false; | return false; | ||||
} | } | ||||
uint256 CCoinsView::GetBestBlock() const { | BlockHash CCoinsView::GetBestBlock() const { | ||||
return uint256(); | return BlockHash(); | ||||
} | } | ||||
std::vector<uint256> CCoinsView::GetHeadBlocks() const { | std::vector<BlockHash> CCoinsView::GetHeadBlocks() const { | ||||
return std::vector<uint256>(); | return std::vector<BlockHash>(); | ||||
} | } | ||||
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { | bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) { | ||||
return false; | return false; | ||||
} | } | ||||
CCoinsViewCursor *CCoinsView::Cursor() const { | CCoinsViewCursor *CCoinsView::Cursor() const { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const { | bool CCoinsView::HaveCoin(const COutPoint &outpoint) const { | ||||
Coin coin; | Coin coin; | ||||
return GetCoin(outpoint, coin); | return GetCoin(outpoint, coin); | ||||
} | } | ||||
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) {} | CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) {} | ||||
bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { | bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { | ||||
return base->GetCoin(outpoint, coin); | return base->GetCoin(outpoint, coin); | ||||
} | } | ||||
bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { | bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { | ||||
return base->HaveCoin(outpoint); | return base->HaveCoin(outpoint); | ||||
} | } | ||||
uint256 CCoinsViewBacked::GetBestBlock() const { | BlockHash CCoinsViewBacked::GetBestBlock() const { | ||||
return base->GetBestBlock(); | return base->GetBestBlock(); | ||||
} | } | ||||
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { | std::vector<BlockHash> CCoinsViewBacked::GetHeadBlocks() const { | ||||
return base->GetHeadBlocks(); | return base->GetHeadBlocks(); | ||||
} | } | ||||
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { | void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { | ||||
base = &viewIn; | base = &viewIn; | ||||
} | } | ||||
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, | bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, | ||||
const uint256 &hashBlock) { | const BlockHash &hashBlock) { | ||||
return base->BatchWrite(mapCoins, hashBlock); | return base->BatchWrite(mapCoins, hashBlock); | ||||
} | } | ||||
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { | CCoinsViewCursor *CCoinsViewBacked::Cursor() const { | ||||
return base->Cursor(); | return base->Cursor(); | ||||
} | } | ||||
size_t CCoinsViewBacked::EstimateSize() const { | size_t CCoinsViewBacked::EstimateSize() const { | ||||
return base->EstimateSize(); | return base->EstimateSize(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const { | ||||
return it != cacheCoins.end() && !it->second.coin.IsSpent(); | return it != cacheCoins.end() && !it->second.coin.IsSpent(); | ||||
} | } | ||||
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const { | bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const { | ||||
CCoinsMap::const_iterator it = cacheCoins.find(outpoint); | CCoinsMap::const_iterator it = cacheCoins.find(outpoint); | ||||
return (it != cacheCoins.end() && !it->second.coin.IsSpent()); | return (it != cacheCoins.end() && !it->second.coin.IsSpent()); | ||||
} | } | ||||
uint256 CCoinsViewCache::GetBestBlock() const { | BlockHash CCoinsViewCache::GetBestBlock() const { | ||||
if (hashBlock.IsNull()) { | if (hashBlock.IsNull()) { | ||||
hashBlock = base->GetBestBlock(); | hashBlock = base->GetBestBlock(); | ||||
} | } | ||||
return hashBlock; | return hashBlock; | ||||
} | } | ||||
void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) { | void CCoinsViewCache::SetBestBlock(const BlockHash &hashBlockIn) { | ||||
hashBlock = hashBlockIn; | hashBlock = hashBlockIn; | ||||
} | } | ||||
bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, | bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, | ||||
const uint256 &hashBlockIn) { | const BlockHash &hashBlockIn) { | ||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); | ||||
it = mapCoins.erase(it)) { | it = mapCoins.erase(it)) { | ||||
// Ignore non-dirty entries (optimization). | // Ignore non-dirty entries (optimization). | ||||
if (!(it->second.flags & CCoinsCacheEntry::DIRTY)) { | if (!(it->second.flags & CCoinsCacheEntry::DIRTY)) { | ||||
continue; | continue; | ||||
} | } | ||||
CCoinsMap::iterator itUs = cacheCoins.find(it->first); | CCoinsMap::iterator itUs = cacheCoins.find(it->first); | ||||
if (itUs == cacheCoins.end()) { | if (itUs == cacheCoins.end()) { | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |