6 #ifndef BITCOIN_COINS_H 7 #define BITCOIN_COINS_H 21 #include <unordered_map> 59 template<
typename Stream>
67 template<
typename Stream>
89 const uint64_t k0,
k1;
157 typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher>
CCoinsMap;
166 virtual bool GetKey(
COutPoint &key)
const = 0;
167 virtual bool GetValue(
Coin &coin)
const = 0;
168 virtual unsigned int GetValueSize()
const = 0;
170 virtual bool Valid()
const = 0;
171 virtual void Next() = 0;
187 virtual bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const;
190 virtual bool HaveCoin(
const COutPoint &outpoint)
const;
193 virtual uint256 GetBestBlock()
const;
199 virtual std::vector<uint256> GetHeadBlocks()
const;
203 virtual bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock);
224 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
225 bool HaveCoin(
const COutPoint &outpoint)
const override;
226 uint256 GetBestBlock()
const override;
227 std::vector<uint256> GetHeadBlocks()
const override;
229 bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock)
override;
231 size_t EstimateSize()
const override;
258 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
259 bool HaveCoin(
const COutPoint &outpoint)
const override;
260 uint256 GetBestBlock()
const override;
261 void SetBestBlock(
const uint256 &hashBlock);
262 bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock)
override;
264 throw std::logic_error(
"CCoinsViewCache cursor iteration not supported.");
272 bool HaveCoinInCache(
const COutPoint &outpoint)
const;
290 void AddCoin(
const COutPoint& outpoint,
Coin&& coin,
bool possible_overwrite);
297 bool SpendCoin(
const COutPoint &outpoint,
Coin* moveto =
nullptr);
313 unsigned int GetCacheSize()
const;
326 void ReallocateCache();
333 CCoinsMap::iterator FetchCoin(
const COutPoint &outpoint)
const;
363 m_err_callbacks.emplace_back(std::move(f));
366 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
374 #endif // BITCOIN_COINS_H
A Coin in one level of the coins database caching hierarchy.
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.
size_t operator()(const COutPoint &id) const noexcept
This must return size_t.
void AddReadErrCallback(std::function< void()> f)
CTxOut out
unspent transaction output
unsigned int fCoinBase
whether containing transaction was a coinbase
CCoinsViewErrorCatcher(CCoinsView *view)
void Serialize(Stream &s) const
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
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_)
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
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)
size_t DynamicMemoryUsage() const
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
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.
void Unserialize(Stream &s)
virtual ~CCoinsViewCursor()
CCoinsViewCursor(const uint256 &hashBlockIn)
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.
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)
Coin(CTxOut &&outIn, int nHeightIn, bool fCoinBaseIn)
construct a Coin from a CTxOut and height/coinbase information.
Cursor for iterating over CoinsView state.