6 #ifndef BITCOIN_COINS_H 7 #define BITCOIN_COINS_H 18 #include <unordered_map> 37 Coin() : nHeightAndIsCoinBase(0) {}
41 : out(
std::move(outIn)),
42 nHeightAndIsCoinBase((nHeightIn << 1) | IsCoinbase) {}
44 uint32_t
GetHeight()
const {
return nHeightAndIsCoinBase >> 1; }
45 bool IsCoinBase()
const {
return nHeightAndIsCoinBase & 0x01; }
53 nHeightAndIsCoinBase = 0;
56 template <
typename Stream>
void Serialize(Stream &s)
const {
75 const uint64_t k0,
k1;
148 : coin(
std::move(coinIn)), flags(0) {}
151 typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher>
160 virtual bool GetKey(
COutPoint &key)
const = 0;
161 virtual bool GetValue(
Coin &coin)
const = 0;
162 virtual unsigned int GetValueSize()
const = 0;
164 virtual bool Valid()
const = 0;
165 virtual void Next() = 0;
182 virtual bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const;
185 virtual bool HaveCoin(
const COutPoint &outpoint)
const;
195 virtual std::vector<BlockHash> GetHeadBlocks()
const;
218 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
219 bool HaveCoin(
const COutPoint &outpoint)
const override;
221 std::vector<BlockHash> GetHeadBlocks()
const override;
225 size_t EstimateSize()
const override;
253 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
254 bool HaveCoin(
const COutPoint &outpoint)
const override;
256 void SetBestBlock(
const BlockHash &hashBlock);
259 throw std::logic_error(
260 "CCoinsViewCache cursor iteration not supported.");
268 bool HaveCoinInCache(
const COutPoint &outpoint)
const;
286 void AddCoin(
const COutPoint &outpoint,
Coin coin,
bool possible_overwrite);
293 bool SpendCoin(
const COutPoint &outpoint,
Coin *moveto =
nullptr);
310 unsigned int GetCacheSize()
const;
334 CCoinsMap::iterator FetchCoin(
const COutPoint &outpoint)
const;
366 m_err_callbacks.emplace_back(std::move(f));
369 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
378 #endif // BITCOIN_COINS_H
A Coin in one level of the coins database caching hierarchy.
uint32_t nHeightAndIsCoinBase
Whether containing transaction was a coinbase and height at which the transaction was included into a...
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)
CTxOut out
Unspent transaction output.
Coin(CTxOut outIn, uint32_t nHeightIn, bool IsCoinbase)
Constructor from a CTxOut and height/coinbase information.
CCoinsViewCursor(const BlockHash &hashBlockIn)
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
void Serialize(Stream &s) const
CCoinsViewErrorCatcher(CCoinsView *view)
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
Abstract view on the open txout dataset.
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
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)
CCoinsCacheEntry(Coin coinIn)
BlockHash hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
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.
void Unserialize(Stream &s)
const BlockHash & GetBestBlock() const
Get best block at the time this cursor was created.
A BlockHash is a unqiue identifier for a block.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
A TxId is the identifier of a transaction.
uint32_t GetHeight() const
virtual ~CCoinsViewCursor()
size_t DynamicMemoryUsage() const
const CTxOut & GetTxOut() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
size_t operator()(const COutPoint &outpoint) const noexcept
This must return size_t.
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate...
const Coin & AccessByTxid(const CCoinsViewCache &cache, const TxId &txid)
Utility function to find any unspent output with a given txid.
Cursor for iterating over CoinsView state.