20 return std::vector<BlockHash>();
69 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
77 CCoinsMap::iterator ret =
79 .emplace(std::piecewise_construct, std::forward_as_tuple(outpoint),
80 std::forward_as_tuple(std::move(tmp)))
82 if (ret->second.coin.IsSpent()) {
92 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
96 coin = it->second.coin;
101 bool possible_overwrite) {
106 CCoinsMap::iterator it;
108 std::tie(it, inserted) =
110 std::forward_as_tuple(outpoint), std::tuple<>());
115 if (!possible_overwrite) {
116 if (!it->second.coin.IsSpent()) {
117 throw std::logic_error(
"Attempted to overwrite an unspent coin "
118 "(when possible_overwrite is false)");
135 it->second.coin = std::move(coin);
148 std::piecewise_construct, std::forward_as_tuple(std::move(outpoint)),
153 bool check_for_overwrite) {
156 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
159 check_for_overwrite ? cache.
HaveCoin(outpoint) : fCoinbase;
169 CCoinsMap::iterator it =
FetchCoin(outpoint);
175 it->second.coin.GetHeight(),
176 it->second.coin.GetTxOut().nValue.ToString().c_str(),
177 it->second.coin.IsCoinBase());
179 *moveout = std::move(it->second.coin);
185 it->second.coin.Clear();
193 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
197 return it->second.coin;
201 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
202 return it !=
cacheCoins.end() && !it->second.coin.IsSpent();
206 CCoinsMap::const_iterator it =
cacheCoins.find(outpoint);
207 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
223 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();
224 it = mapCoins.erase(it)) {
229 CCoinsMap::iterator itUs =
cacheCoins.find(it->first);
234 it->second.coin.IsSpent())) {
238 entry.
coin = std::move(it->second.coin);
251 !itUs->second.coin.IsSpent()) {
256 throw std::logic_error(
"FRESH flag misapplied to coin that "
257 "exists in parent cache");
261 it->second.coin.IsSpent()) {
269 itUs->second.coin = std::move(it->second.coin);
291 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
292 if (it !=
cacheCoins.end() && it->second.flags == 0) {
295 it->second.coin.GetHeight(),
296 it->second.coin.GetTxOut().nValue.ToString().c_str(),
297 it->second.coin.IsCoinBase());
311 for (
size_t i = 0; i < tx.
vin.size(); i++) {
346 }
catch (
const std::runtime_error &e) {
350 LogPrintf(
"Error reading from database: %s\n", e.what());
CCoinsView backed by another CCoinsView.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
BlockHash GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
void SetBackend(CCoinsView &viewIn)
std::vector< BlockHash > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
CCoinsViewBacked(CCoinsView *viewIn)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
void AddCoin(const COutPoint &outpoint, Coin coin, bool possible_overwrite)
Add a coin.
BlockHash GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
CCoinsViewCache(CCoinsView *baseIn)
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
void SetBestBlock(const BlockHash &hashBlock)
BlockHash hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
bool Flush()
Push the modifications applied to this cache to its base.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
void EmplaceCoinInternalDANGER(COutPoint &&outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
void ReallocateCache()
Force a reallocation of the cache map.
Cursor for iterating over CoinsView state.
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Abstract view on the open txout dataset.
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
virtual std::vector< BlockHash > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
virtual bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual BlockHash GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
An outpoint - a combination of a transaction hash and an index n into its vout.
const TxId & GetTxId() const
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An output of a transaction.
uint32_t GetHeight() const
size_t DynamicMemoryUsage() const
const uint8_t * data() const
static const size_t MAX_OUTPUTS_PER_TX
static const Coin coinEmpty
const Coin & AccessByTxid(const CCoinsViewCache &view, const TxId &txid)
Utility function to find any unspent output with a given txid.
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
static const uint64_t MAX_TX_SIZE
The maximum allowed size for a transaction, in bytes.
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
size_t GetSerializeSize(const T &t, int nVersion=0)
std::string ToString() const
A BlockHash is a unqiue identifier for a block.
A Coin in one level of the coins database caching hierarchy.
@ FRESH
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache.
@ DIRTY
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache.
A TxId is the identifier of a transaction.
#define TRACE5(context, event, a, b, c, d, e)
static const int PROTOCOL_VERSION
network protocol versioning