You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

txdb.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2013 The Bitcoin developers
  3. // Distributed under the MIT/X11 software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef BITCOIN_TXDB_LEVELDB_H
  6. #define BITCOIN_TXDB_LEVELDB_H
  7. #include "leveldbwrapper.h"
  8. #include "main.h"
  9. #include <map>
  10. #include <string>
  11. #include <utility>
  12. #include <vector>
  13. class CCoins;
  14. class uint256;
  15. // -dbcache default (MiB)
  16. static const int64_t nDefaultDbCache = 100;
  17. // max. -dbcache in (MiB)
  18. static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024;
  19. // min. -dbcache in (MiB)
  20. static const int64_t nMinDbCache = 4;
  21. /** CCoinsView backed by the LevelDB coin database (chainstate/) */
  22. class CCoinsViewDB : public CCoinsView
  23. {
  24. protected:
  25. CLevelDBWrapper db;
  26. public:
  27. CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
  28. bool GetCoins(const uint256 &txid, CCoins &coins) const;
  29. bool SetCoins(const uint256 &txid, const CCoins &coins);
  30. bool HaveCoins(const uint256 &txid) const;
  31. uint256 GetBestBlock() const;
  32. bool SetBestBlock(const uint256 &hashBlock);
  33. bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
  34. bool GetStats(CCoinsStats &stats) const;
  35. };
  36. /** Access to the block database (blocks/index/) */
  37. class CBlockTreeDB : public CLevelDBWrapper
  38. {
  39. public:
  40. CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
  41. private:
  42. CBlockTreeDB(const CBlockTreeDB&);
  43. void operator=(const CBlockTreeDB&);
  44. public:
  45. bool WriteBlockIndex(const CDiskBlockIndex& blockindex);
  46. bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
  47. bool WriteBlockFileInfo(int nFile, const CBlockFileInfo &fileinfo);
  48. bool ReadLastBlockFile(int &nFile);
  49. bool WriteLastBlockFile(int nFile);
  50. bool WriteReindexing(bool fReindex);
  51. bool ReadReindexing(bool &fReindex);
  52. bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
  53. bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
  54. bool WriteFlag(const std::string &name, bool fValue);
  55. bool ReadFlag(const std::string &name, bool &fValue);
  56. bool LoadBlockIndexGuts();
  57. };
  58. #endif // BITCOIN_TXDB_LEVELDB_H