Back to home page

Bitcoin sources

 
 

    


0001 // Copyright (c) 2009-2010 Satoshi Nakamoto
0002 // Copyright (c) 2009-2014 The Bitcoin developers
0003 // Distributed under the MIT software license, see the accompanying
0004 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
0005 
0006 #ifndef BITCOIN_TXDB_H
0007 #define BITCOIN_TXDB_H
0008 
0009 #include "leveldbwrapper.h"
0010 #include "main.h"
0011 
0012 #include <map>
0013 #include <string>
0014 #include <utility>
0015 #include <vector>
0016 
0017 class CCoins;
0018 class uint256;
0019 
0020 //! -dbcache default (MiB)
0021 static const int64_t nDefaultDbCache = 100;
0022 //! max. -dbcache in (MiB)
0023 static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024;
0024 //! min. -dbcache in (MiB)
0025 static const int64_t nMinDbCache = 4;
0026 
0027 /** CCoinsView backed by the LevelDB coin database (chainstate/) */
0028 class CCoinsViewDB : public CCoinsView
0029 {
0030 protected:
0031     CLevelDBWrapper db;
0032 public:
0033     CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
0034 
0035     bool GetCoins(const uint256 &txid, CCoins &coins) const;
0036     bool HaveCoins(const uint256 &txid) const;
0037     uint256 GetBestBlock() const;
0038     bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
0039     bool GetStats(CCoinsStats &stats) const;
0040 };
0041 
0042 /** Access to the block database (blocks/index/) */
0043 class CBlockTreeDB : public CLevelDBWrapper
0044 {
0045 public:
0046     CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
0047 private:
0048     CBlockTreeDB(const CBlockTreeDB&);
0049     void operator=(const CBlockTreeDB&);
0050 public:
0051     bool WriteBlockIndex(const CDiskBlockIndex& blockindex);
0052     bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
0053     bool WriteBlockFileInfo(int nFile, const CBlockFileInfo &fileinfo);
0054     bool ReadLastBlockFile(int &nFile);
0055     bool WriteLastBlockFile(int nFile);
0056     bool WriteReindexing(bool fReindex);
0057     bool ReadReindexing(bool &fReindex);
0058     bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
0059     bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
0060     bool WriteFlag(const std::string &name, bool fValue);
0061     bool ReadFlag(const std::string &name, bool &fValue);
0062     bool LoadBlockIndexGuts();
0063 };
0064 
0065 #endif // BITCOIN_TXDB_H