6 #ifndef BITCOIN_COINS_H
7 #define BITCOIN_COINS_H
21 #include <unordered_map>
59 template<
typename Stream>
67 template<
typename Stream>
157 typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher>
CCoinsMap;
170 virtual bool Valid()
const = 0;
171 virtual void Next() = 0;
264 throw std::logic_error(
"CCoinsViewCache cursor iteration not supported.");
374 #endif // BITCOIN_COINS_H
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsViewCache(CCoinsView *baseIn)
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
A Coin in one level of the coins database caching hierarchy.
bool Flush()
Push the modifications applied to this cache to its base.
void SetBackend(CCoinsView &viewIn)
virtual unsigned int GetValueSize() const =0
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
void AddReadErrCallback(std::function< void()> f)
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
CTxOut out
unspent transaction output
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
unsigned int fCoinBase
whether containing transaction was a coinbase
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
void ReallocateCache()
Force a reallocation of the cache map.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache...
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
CCoinsViewErrorCatcher(CCoinsView *view)
void Serialize(Stream &s) const
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
void SetBestBlock(const uint256 &hashBlock)
virtual bool GetValue(Coin &coin) const =0
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual bool Valid() const =0
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Abstract view on the open txout dataset.
const Coin & AccessByTxid(const CCoinsViewCache &cache, const uint256 &txid)
Utility function to find any unspent output with a given txid.
CCoinsCacheEntry(Coin &&coin_)
size_t operator()(const COutPoint &id) const noexcept
This must return size_t.
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256 &val, uint32_t extra)
CCoinsViewBacked(CCoinsView *viewIn)
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
virtual bool GetKey(COutPoint &key) const =0
size_t DynamicMemoryUsage() const
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
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)
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check=false)
Utility function to add all of a transaction's outputs to a cache.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
void Unserialize(Stream &s)
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache...
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
virtual ~CCoinsViewCursor()
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
CCoinsViewCursor(const uint256 &hashBlockIn)
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
const uint256 & GetBestBlock() const
Get best block at the time this cursor was created.
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate...
Coin(const CTxOut &outIn, int nHeightIn, bool fCoinBaseIn)
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Coin(CTxOut &&outIn, int nHeightIn, bool fCoinBaseIn)
construct a Coin from a CTxOut and height/coinbase information.
Cursor for iterating over CoinsView state.