6 #ifndef BITCOIN_COINS_H 7 #define BITCOIN_COINS_H 21 #include <unordered_map> 59 template<
typename Stream>
67 template<
typename Stream>
130 typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher>
CCoinsMap;
139 virtual bool GetKey(
COutPoint &key)
const = 0;
140 virtual bool GetValue(
Coin &coin)
const = 0;
141 virtual unsigned int GetValueSize()
const = 0;
143 virtual bool Valid()
const = 0;
144 virtual void Next() = 0;
160 virtual bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const;
163 virtual bool HaveCoin(
const COutPoint &outpoint)
const;
166 virtual uint256 GetBestBlock()
const;
172 virtual std::vector<uint256> GetHeadBlocks()
const;
176 virtual bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock);
197 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
198 bool HaveCoin(
const COutPoint &outpoint)
const override;
199 uint256 GetBestBlock()
const override;
200 std::vector<uint256> GetHeadBlocks()
const override;
202 bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock)
override;
204 size_t EstimateSize()
const override;
231 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
232 bool HaveCoin(
const COutPoint &outpoint)
const override;
233 uint256 GetBestBlock()
const override;
234 void SetBestBlock(
const uint256 &hashBlock);
235 bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock)
override;
237 throw std::logic_error(
"CCoinsViewCache cursor iteration not supported.");
245 bool HaveCoinInCache(
const COutPoint &outpoint)
const;
263 void AddCoin(
const COutPoint& outpoint,
Coin&& coin,
bool possible_overwrite);
270 bool SpendCoin(
const COutPoint &outpoint,
Coin* moveto =
nullptr);
286 unsigned int GetCacheSize()
const;
299 void ReallocateCache();
306 CCoinsMap::iterator FetchCoin(
const COutPoint &outpoint)
const;
336 m_err_callbacks.emplace_back(std::move(f));
339 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
347 #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.
void AddReadErrCallback(std::function< void()> f)
CTxOut out
unspent transaction output
unsigned int fCoinBase
whether containing transaction was a coinbase
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.
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
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
uint256 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)
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
virtual ~CCoinsViewCursor()
size_t DynamicMemoryUsage() const
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.