1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
10 #include "leveldbwrapper.h"
20 struct CAddressUnspentKey;
21 struct CAddressUnspentValue;
22 struct CAddressIndexKey;
23 struct CAddressIndexIteratorKey;
24 struct CAddressIndexIteratorHeightKey;
25 struct CTimestampIndexKey;
26 struct CTimestampIndexIteratorKey;
27 struct CTimestampBlockIndexKey;
28 struct CTimestampBlockIndexValue;
29 struct CSpentIndexKey;
30 struct CSpentIndexValue;
33 //! -dbcache default (MiB)
34 static const int64_t nDefaultDbCache = 450;
35 //! max. -dbcache (MiB)
36 static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
37 //! min. -dbcache in (MiB)
38 static const int64_t nMinDbCache = 4;
40 /** CCoinsView backed by the LevelDB coin database (chainstate/) */
41 class CCoinsViewDB : public CCoinsView
45 CCoinsViewDB(std::string dbName, size_t nCacheSize, bool fMemory = false, bool fWipe = false);
47 CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
49 bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
50 bool GetNullifier(const uint256 &nf) const;
51 bool GetCoins(const uint256 &txid, CCoins &coins) const;
52 bool HaveCoins(const uint256 &txid) const;
53 uint256 GetBestBlock() const;
54 uint256 GetBestAnchor() const;
55 bool BatchWrite(CCoinsMap &mapCoins,
56 const uint256 &hashBlock,
57 const uint256 &hashAnchor,
58 CAnchorsMap &mapAnchors,
59 CNullifiersMap &mapNullifiers);
60 bool GetStats(CCoinsStats &stats) const;
63 /** Access to the block database (blocks/index/) */
64 class CBlockTreeDB : public CLevelDBWrapper
67 CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool compression = true, int maxOpenFiles = 1000);
69 CBlockTreeDB(const CBlockTreeDB&);
70 void operator=(const CBlockTreeDB&);
72 bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
73 bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
74 bool ReadLastBlockFile(int &nFile);
75 bool WriteReindexing(bool fReindex);
76 bool ReadReindexing(bool &fReindex);
77 bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
78 bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
79 bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
80 bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect);
81 bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect);
82 bool ReadAddressUnspentIndex(uint160 addressHash, int type,
83 std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &vect);
84 bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
85 bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
86 bool ReadAddressIndex(uint160 addressHash, int type,
87 std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
88 int start = 0, int end = 0);
89 bool WriteTimestampIndex(const CTimestampIndexKey ×tampIndex);
90 bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector<std::pair<uint256, unsigned int> > &vect);
91 bool WriteTimestampBlockIndex(const CTimestampBlockIndexKey &blockhashIndex, const CTimestampBlockIndexValue &logicalts);
92 bool ReadTimestampBlockIndex(const uint256 &hash, unsigned int &logicalTS);
93 bool WriteFlag(const std::string &name, bool fValue);
94 bool ReadFlag(const std::string &name, bool &fValue);
95 bool LoadBlockIndexGuts();
96 bool blockOnchainActive(const uint256 &hash);
99 #endif // BITCOIN_TXDB_H