aboutsummaryrefslogtreecommitdiff
path: root/src/coins.h
diff options
context:
space:
mode:
authorDaniel Kraft <d@domob.eu>2014-07-19 16:42:48 +0200
committerDaniel Kraft <d@domob.eu>2014-08-26 11:29:18 +0200
commita3dc587a62f5d12aea1ff8139198bf0441535c5f (patch)
tree4759437af72c07a075c6819bb5c2435d7350f0d8 /src/coins.h
parentffb4c210bc0b78bd8cbccdb7ccb80dde918a01b0 (diff)
Make appropriate getter-routines "const" in CCoinsView.
Mark the "Get"/"Have" routines in CCoinsView and subclasses as "const".
Diffstat (limited to 'src/coins.h')
-rw-r--r--src/coins.h41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/coins.h b/src/coins.h
index 2b657299e3..08913531d8 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -276,17 +276,17 @@ class CCoinsView
{
public:
// 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
virtual bool SetCoins(const uint256 &txid, const CCoins &coins);
// 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);
+ virtual bool HaveCoins(const uint256 &txid) const;
// Retrieve the block hash whose state this CCoinsView currently represents
- virtual uint256 GetBestBlock();
+ virtual uint256 GetBestBlock() const;
// Modify the currently active block hash
virtual bool SetBestBlock(const uint256 &hashBlock);
@@ -296,7 +296,7 @@ public:
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
// 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
virtual ~CCoinsView() {}
@@ -311,14 +311,14 @@ protected:
public:
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 HaveCoins(const uint256 &txid);
- uint256 GetBestBlock();
+ bool HaveCoins(const uint256 &txid) const;
+ uint256 GetBestBlock() const;
bool SetBestBlock(const uint256 &hashBlock);
void SetBackend(CCoinsView &viewIn);
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
{
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:
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
// 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 HaveCoins(const uint256 &txid);
- uint256 GetBestBlock();
+ bool HaveCoins(const uint256 &txid) const;
+ uint256 GetBestBlock() const;
bool SetBestBlock(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
// copying.
CCoins &GetCoins(const uint256 &txid);
+ const CCoins &GetCoins(const uint256 &txid) const;
// Push the modifications applied to this cache to its base.
// Failure to call this method before destruction will cause the changes to be forgotten.
@@ -351,7 +355,7 @@ public:
bool Flush();
// 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
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
@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
- bool HaveInputs(const CTransaction& tx);
+ bool HaveInputs(const CTransaction& tx) const;
// 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:
CCoinsMap::iterator FetchCoins(const uint256 &txid);
+ CCoinsMap::const_iterator FetchCoins(const uint256 &txid) const;
};
#endif