Changeset View
Changeset View
Standalone View
Standalone View
src/coins.h
Show First 20 Lines • Show All 341 Lines • ▼ Show 20 Lines | public: | ||||
const uint256 &GetBestBlock() const { return hashBlock; } | const uint256 &GetBestBlock() const { return hashBlock; } | ||||
private: | private: | ||||
uint256 hashBlock; | uint256 hashBlock; | ||||
}; | }; | ||||
/** Abstract view on the open txout dataset. */ | /** Abstract view on the open txout dataset. */ | ||||
class CCoinsView { | class CCoinsView { | ||||
protected: | |||||
//! Just check whether we have data for a given txid. | |||||
//! This may (but cannot always) return true for fully spent transactions | |||||
virtual bool HaveCoins(const uint256 &txid) const; | |||||
public: | public: | ||||
//! Retrieve the CCoins (unspent transaction outputs) for a given txid | //! Retrieve the CCoins (unspent transaction outputs) for a given txid | ||||
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const; | virtual bool GetCoins(const uint256 &txid, CCoins &coins) const; | ||||
//! Just check whether we have data for a given txid. | //! Transitional function to move from HaveCoins to HaveCoin. | ||||
//! This may (but cannot always) return true for fully spent transactions | bool HaveCoins_DONOTUSE(const uint256 &txid) const { | ||||
virtual bool HaveCoins(const uint256 &txid) const; | return HaveCoins(txid); | ||||
} | |||||
//! Just check whether we have data for a given outpoint. | |||||
//! This may (but cannot always) return true for spent outputs. | |||||
bool HaveCoin(const COutPoint &outpoint) const { | |||||
CCoins coins; | |||||
if (!GetCoins(outpoint.hash, coins)) { | |||||
return false; | |||||
} | |||||
return coins.IsAvailable(outpoint.n); | |||||
} | |||||
//! Retrieve the block hash whose state this CCoinsView currently represents | //! Retrieve the block hash whose state this CCoinsView currently represents | ||||
virtual uint256 GetBestBlock() const; | virtual uint256 GetBestBlock() const; | ||||
//! Do a bulk modification (multiple CCoins changes + BestBlock change). | //! Do a bulk modification (multiple CCoins changes + BestBlock change). | ||||
//! The passed mapCoins can be modified. | //! The passed mapCoins can be modified. | ||||
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | ||||
//! Get a cursor to iterate over the whole state | //! Get a cursor to iterate over the whole state | ||||
virtual CCoinsViewCursor *Cursor() const; | virtual CCoinsViewCursor *Cursor() const; | ||||
//! As we use CCoinsViews polymorphically, have a virtual destructor | //! As we use CCoinsViews polymorphically, have a virtual destructor | ||||
virtual ~CCoinsView() {} | virtual ~CCoinsView() {} | ||||
}; | }; | ||||
/** CCoinsView backed by another CCoinsView */ | /** CCoinsView backed by another CCoinsView */ | ||||
class CCoinsViewBacked : public CCoinsView { | class CCoinsViewBacked : public CCoinsView { | ||||
protected: | protected: | ||||
CCoinsView *base; | CCoinsView *base; | ||||
bool HaveCoins(const uint256 &txid) const; | |||||
public: | public: | ||||
CCoinsViewBacked(CCoinsView *viewIn); | CCoinsViewBacked(CCoinsView *viewIn); | ||||
bool GetCoins(const uint256 &txid, CCoins &coins) const; | bool GetCoins(const uint256 &txid, CCoins &coins) const; | ||||
bool HaveCoins(const uint256 &txid) const; | |||||
uint256 GetBestBlock() const; | uint256 GetBestBlock() const; | ||||
void SetBackend(CCoinsView &viewIn); | void SetBackend(CCoinsView &viewIn); | ||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | ||||
CCoinsViewCursor *Cursor() const; | CCoinsViewCursor *Cursor() const; | ||||
}; | }; | ||||
class CCoinsViewCache; | class CCoinsViewCache; | ||||
Show All 31 Lines | protected: | ||||
* declared as "const". | * declared as "const". | ||||
*/ | */ | ||||
mutable uint256 hashBlock; | mutable uint256 hashBlock; | ||||
mutable CCoinsMap cacheCoins; | mutable CCoinsMap cacheCoins; | ||||
/* Cached dynamic memory usage for the inner CCoins objects. */ | /* Cached dynamic memory usage for the inner CCoins objects. */ | ||||
mutable size_t cachedCoinsUsage; | mutable size_t cachedCoinsUsage; | ||||
bool HaveCoins(const uint256 &txid) const; | |||||
public: | public: | ||||
CCoinsViewCache(CCoinsView *baseIn); | CCoinsViewCache(CCoinsView *baseIn); | ||||
~CCoinsViewCache(); | ~CCoinsViewCache(); | ||||
// Standard CCoinsView methods | // Standard CCoinsView methods | ||||
bool GetCoins(const uint256 &txid, CCoins &coins) const; | bool GetCoins(const uint256 &txid, CCoins &coins) const; | ||||
bool HaveCoins(const uint256 &txid) const; | |||||
uint256 GetBestBlock() const; | uint256 GetBestBlock() const; | ||||
void SetBestBlock(const uint256 &hashBlock); | void SetBestBlock(const uint256 &hashBlock); | ||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); | ||||
/** | /** | ||||
* Check if we have the given tx already loaded in this cache. | * Check if we have the given utxo already loaded in this cache. | ||||
* The semantics are the same as HaveCoins(), but no calls to | * The semantics are the same as HaveCoin(), but no calls to the backing | ||||
* the backing CCoinsView are made. | * CCoinsView are made. | ||||
*/ | */ | ||||
bool HaveCoinsInCache(const uint256 &txid) const; | bool HaveCoinInCache(const COutPoint &outpoint) const; | ||||
/** | /** | ||||
* Return a pointer to CCoins in the cache, or nullptr if not found. This is | * Return a pointer to CCoins in the cache, or nullptr if not found. This is | ||||
* more efficient than GetCoins. Modifications to other cache entries are | * more efficient than GetCoins. Modifications to other cache entries are | ||||
* allowed while accessing the returned pointer. | * allowed while accessing the returned pointer. | ||||
*/ | */ | ||||
const CCoins *AccessCoins(const uint256 &txid) const; | const CCoins *AccessCoins(const uint256 &txid) const; | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |