aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h134
1 files changed, 1 insertions, 133 deletions
diff --git a/src/main.h b/src/main.h
index b8db357aed..48e83d98f4 100644
--- a/src/main.h
+++ b/src/main.h
@@ -12,6 +12,7 @@
#include "bignum.h"
#include "chainparams.h"
+#include "coins.h"
#include "core.h"
#include "net.h"
#include "script.h"
@@ -48,8 +49,6 @@ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
-/** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */
-static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF;
/** No amount larger than this (in satoshi) is valid */
static const int64_t MAX_MONEY = 21000000 * COIN;
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
@@ -101,8 +100,6 @@ class CCoinsDB;
class CBlockTreeDB;
struct CDiskBlockPos;
class CTxUndo;
-class CCoinsView;
-class CCoinsViewCache;
class CScriptCheck;
class CValidationState;
class CWalletInterface;
@@ -1030,135 +1027,6 @@ public:
extern CChain chainActive;
-
-
-
-
-
-struct CCoinsStats
-{
- int nHeight;
- uint256 hashBlock;
- uint64_t nTransactions;
- uint64_t nTransactionOutputs;
- uint64_t nSerializedSize;
- uint256 hashSerialized;
- int64_t nTotalAmount;
-
- CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
-};
-
-/** Abstract view on the open txout dataset. */
-class CCoinsView
-{
-public:
- // Retrieve the CCoins (unspent transaction outputs) for a given txid
- virtual bool GetCoins(const uint256 &txid, CCoins &coins);
-
- // 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);
-
- // Retrieve the block hash whose state this CCoinsView currently represents
- virtual uint256 GetBestBlock();
-
- // Modify the currently active block hash
- virtual bool SetBestBlock(const uint256 &hashBlock);
-
- // Do a bulk modification (multiple SetCoins + one SetBestBlock)
- virtual bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
-
- // Calculate statistics about the unspent transaction output set
- virtual bool GetStats(CCoinsStats &stats);
-
- // As we use CCoinsViews polymorphically, have a virtual destructor
- virtual ~CCoinsView() {}
-};
-
-/** CCoinsView backed by another CCoinsView */
-class CCoinsViewBacked : public CCoinsView
-{
-protected:
- CCoinsView *base;
-
-public:
- CCoinsViewBacked(CCoinsView &viewIn);
- bool GetCoins(const uint256 &txid, CCoins &coins);
- bool SetCoins(const uint256 &txid, const CCoins &coins);
- bool HaveCoins(const uint256 &txid);
- uint256 GetBestBlock();
- bool SetBestBlock(const uint256 &hashBlock);
- void SetBackend(CCoinsView &viewIn);
- bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
- bool GetStats(CCoinsStats &stats);
-};
-
-/** CCoinsView that adds a memory cache for transactions to another CCoinsView */
-class CCoinsViewCache : public CCoinsViewBacked
-{
-protected:
- uint256 hashBlock;
- std::map<uint256,CCoins> cacheCoins;
-
-public:
- CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
-
- // Standard CCoinsView methods
- bool GetCoins(const uint256 &txid, CCoins &coins);
- bool SetCoins(const uint256 &txid, const CCoins &coins);
- bool HaveCoins(const uint256 &txid);
- uint256 GetBestBlock();
- bool SetBestBlock(const uint256 &hashBlock);
- bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
-
- // Return a modifiable reference to a CCoins. Check HaveCoins first.
- // Many methods explicitly require a CCoinsViewCache because of this method, to reduce
- // copying.
- CCoins &GetCoins(const uint256 &txid);
-
- // Push the modifications applied to this cache to its base.
- // Failure to call this method before destruction will cause the changes to be forgotten.
- bool Flush();
-
- // Calculate the size of the cache (in number of transactions)
- unsigned int GetCacheSize();
-
- /** Amount of bitcoins coming in to a transaction
- Note that lightweight clients may not know anything besides the hash of previous transactions,
- so may not be able to calculate this.
-
- @param[in] tx transaction for which we are checking input total
- @return Sum of value of all inputs (scriptSigs)
- @see CTransaction::FetchInputs
- */
- int64_t GetValueIn(const CTransaction& tx);
-
-
- // Check whether all prevouts of the transaction are present in the UTXO set represented by this view
- bool HaveInputs(const CTransaction& tx);
-
- const CTxOut &GetOutputFor(const CTxIn& input);
-
-private:
- std::map<uint256,CCoins>::iterator FetchCoins(const uint256 &txid);
-};
-
-/** CCoinsView that brings transactions from a memorypool into view.
- It does not check for spendings by memory pool transactions. */
-class CCoinsViewMemPool : public CCoinsViewBacked
-{
-protected:
- CTxMemPool &mempool;
-
-public:
- CCoinsViewMemPool(CCoinsView &baseIn, CTxMemPool &mempoolIn);
- bool GetCoins(const uint256 &txid, CCoins &coins);
- bool HaveCoins(const uint256 &txid);
-};
-
/** Global variable that points to the active CCoinsView (protected by cs_main) */
extern CCoinsViewCache *pcoinsTip;