Dash Core  0.12.2.1
P2P Digital Currency
txdb.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 
6 #ifndef BITCOIN_TXDB_H
7 #define BITCOIN_TXDB_H
8 
9 #include "coins.h"
10 #include "dbwrapper.h"
11 
12 #include <map>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 class CBlockFileInfo;
18 class CBlockIndex;
19 struct CDiskTxPos;
20 struct CAddressUnspentKey;
22 struct CAddressIndexKey;
25 struct CTimestampIndexKey;
27 struct CSpentIndexKey;
28 struct CSpentIndexValue;
29 class uint256;
30 
32 static const int64_t nDefaultDbCache = 100;
34 static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
36 static const int64_t nMinDbCache = 4;
37 
39 class CCoinsViewDB : public CCoinsView
40 {
41 protected:
43 public:
44  CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
45 
46  bool GetCoins(const uint256 &txid, CCoins &coins) const;
47  bool HaveCoins(const uint256 &txid) const;
48  uint256 GetBestBlock() const;
49  bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
50  bool GetStats(CCoinsStats &stats) const;
51 };
52 
54 class CBlockTreeDB : public CDBWrapper
55 {
56 public:
57  CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
58 private:
59  CBlockTreeDB(const CBlockTreeDB&);
60  void operator=(const CBlockTreeDB&);
61 public:
62  bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
63  bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
64  bool ReadLastBlockFile(int &nFile);
65  bool WriteReindexing(bool fReindex);
66  bool ReadReindexing(bool &fReindex);
67  bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
68  bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
70  bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect);
71  bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect);
72  bool ReadAddressUnspentIndex(uint160 addressHash, int type,
73  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &vect);
74  bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
75  bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
76  bool ReadAddressIndex(uint160 addressHash, int type,
77  std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
78  int start = 0, int end = 0);
79  bool WriteTimestampIndex(const CTimestampIndexKey &timestampIndex);
80  bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &vect);
81  bool WriteFlag(const std::string &name, bool fValue);
82  bool ReadFlag(const std::string &name, bool &fValue);
83  bool LoadBlockIndexGuts();
84 };
85 
86 #endif // BITCOIN_TXDB_H
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo)
Definition: txdb.cpp:81
bool HaveCoins(const uint256 &txid) const
Definition: txdb.cpp:44
Definition: coins.h:73
CBlockTreeDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: txdb.cpp:78
bool ReadAddressUnspentIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &vect)
Definition: txdb.cpp:198
bool fReindex
Definition: validation.cpp:71
CDBWrapper db
Definition: txdb.h:42
sph_u32 high
Definition: keccak.c:370
bool ReadAddressIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start=0, int end=0)
Definition: txdb.cpp:238
bool WriteTxIndex(const std::vector< std::pair< uint256, CDiskTxPos > > &list)
Definition: txdb.cpp:163
boost::unordered_map< uint256, CCoinsCacheEntry, CCoinsKeyHasher > CCoinsMap
Definition: coins.h:298
static const int64_t nMinDbCache
min. -dbcache in (MiB)
Definition: txdb.h:36
bool WriteFlag(const std::string &name, bool fValue)
Definition: txdb.cpp:298
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: txdb.cpp:48
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: txdb.cpp:40
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Definition: txdb.cpp:55
const char * name
Definition: rest.cpp:37
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
Definition: txdb.cpp:170
void operator=(const CBlockTreeDB &)
static const int64_t nDefaultDbCache
-dbcache default (MiB)
Definition: txdb.h:32
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos)
Definition: txdb.cpp:159
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo *> > &fileInfo, int nLastFile, const std::vector< const CBlockIndex *> &blockinfo)
Definition: txdb.cpp:147
CCoinsViewDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: txdb.cpp:36
bool WriteTimestampIndex(const CTimestampIndexKey &timestampIndex)
Definition: txdb.cpp:272
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
Definition: txdb.cpp:101
bool UpdateAddressUnspentIndex(const std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &vect)
Definition: txdb.cpp:186
bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &vect)
Definition: txdb.cpp:278
bool EraseAddressIndex(const std::vector< std::pair< CAddressIndexKey, CAmount > > &vect)
Definition: txdb.cpp:231
bool LoadBlockIndexGuts()
Definition: txdb.cpp:310
static const int64_t nMaxDbCache
max. -dbcache in (MiB)
Definition: txdb.h:34
sph_u32 low
Definition: keccak.c:370
bool ReadReindexing(bool &fReindex)
Definition: txdb.cpp:92
bool ReadLastBlockFile(int &nFile)
Definition: txdb.cpp:97
bool ReadFlag(const std::string &name, bool &fValue)
Definition: txdb.cpp:302
bool WriteAddressIndex(const std::vector< std::pair< CAddressIndexKey, CAmount > > &vect)
Definition: txdb.cpp:224
bool WriteReindexing(bool fReindex)
Definition: txdb.cpp:85
bool UpdateSpentIndex(const std::vector< std::pair< CSpentIndexKey, CSpentIndexValue > > &vect)
Definition: txdb.cpp:174