|
|
@ -276,17 +276,17 @@ class CCoinsView |
|
|
|
{ |
|
|
|
{ |
|
|
|
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); |
|
|
|
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const; |
|
|
|
|
|
|
|
|
|
|
|
// Modify the CCoins for a given txid
|
|
|
|
// Modify the CCoins for a given txid
|
|
|
|
virtual bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
virtual bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
|
|
|
|
|
|
|
|
// Just check whether we have data for a given txid.
|
|
|
|
// Just check whether we have data for a given txid.
|
|
|
|
// This may (but cannot always) return true for fully spent transactions
|
|
|
|
// This may (but cannot always) return true for fully spent transactions
|
|
|
|
virtual bool HaveCoins(const uint256 &txid); |
|
|
|
virtual bool HaveCoins(const uint256 &txid) const; |
|
|
|
|
|
|
|
|
|
|
|
// Retrieve the block hash whose state this CCoinsView currently represents
|
|
|
|
// Retrieve the block hash whose state this CCoinsView currently represents
|
|
|
|
virtual uint256 GetBestBlock(); |
|
|
|
virtual uint256 GetBestBlock() const; |
|
|
|
|
|
|
|
|
|
|
|
// Modify the currently active block hash
|
|
|
|
// Modify the currently active block hash
|
|
|
|
virtual bool SetBestBlock(const uint256 &hashBlock); |
|
|
|
virtual bool SetBestBlock(const uint256 &hashBlock); |
|
|
@ -296,7 +296,7 @@ public: |
|
|
|
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
|
|
|
|
|
|
|
|
// Calculate statistics about the unspent transaction output set
|
|
|
|
// Calculate statistics about the unspent transaction output set
|
|
|
|
virtual bool GetStats(CCoinsStats &stats); |
|
|
|
virtual bool GetStats(CCoinsStats &stats) const; |
|
|
|
|
|
|
|
|
|
|
|
// As we use CCoinsViews polymorphically, have a virtual destructor
|
|
|
|
// As we use CCoinsViews polymorphically, have a virtual destructor
|
|
|
|
virtual ~CCoinsView() {} |
|
|
|
virtual ~CCoinsView() {} |
|
|
@ -311,14 +311,14 @@ protected: |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
CCoinsViewBacked(CCoinsView &viewIn); |
|
|
|
CCoinsViewBacked(CCoinsView &viewIn); |
|
|
|
bool GetCoins(const uint256 &txid, CCoins &coins); |
|
|
|
bool GetCoins(const uint256 &txid, CCoins &coins) const; |
|
|
|
bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
bool HaveCoins(const uint256 &txid); |
|
|
|
bool HaveCoins(const uint256 &txid) const; |
|
|
|
uint256 GetBestBlock(); |
|
|
|
uint256 GetBestBlock() const; |
|
|
|
bool SetBestBlock(const uint256 &hashBlock); |
|
|
|
bool SetBestBlock(const uint256 &hashBlock); |
|
|
|
void SetBackend(CCoinsView &viewIn); |
|
|
|
void SetBackend(CCoinsView &viewIn); |
|
|
|
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
bool GetStats(CCoinsStats &stats); |
|
|
|
bool GetStats(CCoinsStats &stats) const; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -326,17 +326,20 @@ public: |
|
|
|
class CCoinsViewCache : public CCoinsViewBacked |
|
|
|
class CCoinsViewCache : public CCoinsViewBacked |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
uint256 hashBlock; |
|
|
|
|
|
|
|
CCoinsMap cacheCoins; |
|
|
|
/* Make mutable so that we can "fill the cache" even from Get-methods
|
|
|
|
|
|
|
|
declared as "const". */ |
|
|
|
|
|
|
|
mutable uint256 hashBlock; |
|
|
|
|
|
|
|
mutable CCoinsMap cacheCoins; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false); |
|
|
|
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false); |
|
|
|
|
|
|
|
|
|
|
|
// Standard CCoinsView methods
|
|
|
|
// Standard CCoinsView methods
|
|
|
|
bool GetCoins(const uint256 &txid, CCoins &coins); |
|
|
|
bool GetCoins(const uint256 &txid, CCoins &coins) const; |
|
|
|
bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
bool SetCoins(const uint256 &txid, const CCoins &coins); |
|
|
|
bool HaveCoins(const uint256 &txid); |
|
|
|
bool HaveCoins(const uint256 &txid) const; |
|
|
|
uint256 GetBestBlock(); |
|
|
|
uint256 GetBestBlock() const; |
|
|
|
bool SetBestBlock(const uint256 &hashBlock); |
|
|
|
bool SetBestBlock(const uint256 &hashBlock); |
|
|
|
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); |
|
|
|
|
|
|
|
|
|
|
@ -344,6 +347,7 @@ public: |
|
|
|
// Many methods explicitly require a CCoinsViewCache because of this method, to reduce
|
|
|
|
// Many methods explicitly require a CCoinsViewCache because of this method, to reduce
|
|
|
|
// copying.
|
|
|
|
// copying.
|
|
|
|
CCoins &GetCoins(const uint256 &txid); |
|
|
|
CCoins &GetCoins(const uint256 &txid); |
|
|
|
|
|
|
|
const CCoins &GetCoins(const uint256 &txid) const; |
|
|
|
|
|
|
|
|
|
|
|
// Push the modifications applied to this cache to its base.
|
|
|
|
// Push the modifications applied to this cache to its base.
|
|
|
|
// Failure to call this method before destruction will cause the changes to be forgotten.
|
|
|
|
// Failure to call this method before destruction will cause the changes to be forgotten.
|
|
|
@ -351,7 +355,7 @@ public: |
|
|
|
bool Flush(); |
|
|
|
bool Flush(); |
|
|
|
|
|
|
|
|
|
|
|
// Calculate the size of the cache (in number of transactions)
|
|
|
|
// Calculate the size of the cache (in number of transactions)
|
|
|
|
unsigned int GetCacheSize(); |
|
|
|
unsigned int GetCacheSize() const; |
|
|
|
|
|
|
|
|
|
|
|
/** Amount of bitcoins coming in to a transaction
|
|
|
|
/** Amount of bitcoins coming in to a transaction
|
|
|
|
Note that lightweight clients may not know anything besides the hash of previous transactions, |
|
|
|
Note that lightweight clients may not know anything besides the hash of previous transactions, |
|
|
@ -360,18 +364,19 @@ public: |
|
|
|
@param[in] tx transaction for which we are checking input total |
|
|
|
@param[in] tx transaction for which we are checking input total |
|
|
|
@return Sum of value of all inputs (scriptSigs) |
|
|
|
@return Sum of value of all inputs (scriptSigs) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int64_t GetValueIn(const CTransaction& tx); |
|
|
|
int64_t GetValueIn(const CTransaction& tx) const; |
|
|
|
|
|
|
|
|
|
|
|
// Check whether all prevouts of the transaction are present in the UTXO set represented by this view
|
|
|
|
// Check whether all prevouts of the transaction are present in the UTXO set represented by this view
|
|
|
|
bool HaveInputs(const CTransaction& tx); |
|
|
|
bool HaveInputs(const CTransaction& tx) const; |
|
|
|
|
|
|
|
|
|
|
|
// Return priority of tx at height nHeight
|
|
|
|
// Return priority of tx at height nHeight
|
|
|
|
double GetPriority(const CTransaction &tx, int nHeight); |
|
|
|
double GetPriority(const CTransaction &tx, int nHeight) const; |
|
|
|
|
|
|
|
|
|
|
|
const CTxOut &GetOutputFor(const CTxIn& input); |
|
|
|
const CTxOut &GetOutputFor(const CTxIn& input) const; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
CCoinsMap::iterator FetchCoins(const uint256 &txid); |
|
|
|
CCoinsMap::iterator FetchCoins(const uint256 &txid); |
|
|
|
|
|
|
|
CCoinsMap::const_iterator FetchCoins(const uint256 &txid) const; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|