txdb.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.
  5. #ifndef BITCOIN_TXDB_H
  6. #define BITCOIN_TXDB_H
  7. #include "coins.h"
  8. #include "leveldbwrapper.h"
  9. #include <map>
  10. #include <string>
  11. #include <utility>
  12. #include <vector>
  13. class CBlockFileInfo;
  14. class CBlockIndex;
  15. struct CDiskTxPos;
  16. class uint256;
  17. //! -dbcache default (MiB)
  18. static const int64_t nDefaultDbCache = 100;
  19. //! max. -dbcache in (MiB)
  20. static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
  21. //! min. -dbcache in (MiB)
  22. static const int64_t nMinDbCache = 4;
  23. /** CCoinsView backed by the LevelDB coin database (chainstate/) */
  24. class CCoinsViewDB : public CCoinsView
  25. {
  26. protected:
  27. CLevelDBWrapper db;
  28. public:
  29. CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
  30. bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
  31. bool GetNullifier(const uint256 &nf) const;
  32. bool GetCoins(const uint256 &txid, CCoins &coins) const;
  33. bool HaveCoins(const uint256 &txid) const;
  34. uint256 GetBestBlock() const;
  35. uint256 GetBestAnchor() const;
  36. bool BatchWrite(CCoinsMap &mapCoins,
  37. const uint256 &hashBlock,
  38. const uint256 &hashAnchor,
  39. CAnchorsMap &mapAnchors,
  40. CNullifiersMap &mapNullifiers);
  41. bool GetStats(CCoinsStats &stats) const;
  42. };
  43. /** Access to the block database (blocks/index/) */
  44. class CBlockTreeDB : public CLevelDBWrapper
  45. {
  46. public:
  47. CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
  48. private:
  49. CBlockTreeDB(const CBlockTreeDB&);
  50. void operator=(const CBlockTreeDB&);
  51. public:
  52. bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
  53. bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
  54. bool ReadLastBlockFile(int &nFile);
  55. bool WriteReindexing(bool fReindex);
  56. bool ReadReindexing(bool &fReindex);
  57. bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
  58. bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
  59. bool WriteFlag(const std::string &name, bool fValue);
  60. bool ReadFlag(const std::string &name, bool &fValue);
  61. bool LoadBlockIndexGuts();
  62. };
  63. #endif // BITCOIN_TXDB_H