Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_TXDB_H | #ifndef BITCOIN_TXDB_H | ||||
#define BITCOIN_TXDB_H | #define BITCOIN_TXDB_H | ||||
#include <blockfileinfo.h> | #include <blockfileinfo.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <dbwrapper.h> | #include <dbwrapper.h> | ||||
#include <diskblockpos.h> | #include <diskblockpos.h> | ||||
#include <primitives/block.h> | |||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
#include <utility> | #include <utility> | ||||
#include <vector> | #include <vector> | ||||
class CBlockIndex; | class CBlockIndex; | ||||
class CCoinsViewDBCursor; | class CCoinsViewDBCursor; | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/** Access to the block database (blocks/index/) */ | /** Access to the block database (blocks/index/) */ | ||||
class CBlockTreeDB : public CDBWrapper { | class CBlockTreeDB : public CDBWrapper { | ||||
public: | public: | ||||
explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, | explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, | ||||
bool fWipe = false); | bool fWipe = false); | ||||
private: | |||||
CBlockTreeDB(const CBlockTreeDB &); | |||||
void operator=(const CBlockTreeDB &); | |||||
public: | |||||
bool WriteBatchSync( | bool WriteBatchSync( | ||||
const std::vector<std::pair<int, const CBlockFileInfo *>> &fileInfo, | const std::vector<std::pair<int, const CBlockFileInfo *>> &fileInfo, | ||||
int nLastFile, const std::vector<const CBlockIndex *> &blockinfo); | int nLastFile, const std::vector<const CBlockIndex *> &blockinfo); | ||||
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info); | bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info); | ||||
bool ReadLastBlockFile(int &nFile); | bool ReadLastBlockFile(int &nFile); | ||||
bool WriteReindexing(bool fReindexing); | bool WriteReindexing(bool fReindexing); | ||||
bool ReadReindexing(bool &fReindexing); | bool ReadReindexing(bool &fReindexing); | ||||
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos); | bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos); | ||||
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos>> &vect); | bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos>> &vect); | ||||
bool WriteFlag(const std::string &name, bool fValue); | bool WriteFlag(const std::string &name, bool fValue); | ||||
bool ReadFlag(const std::string &name, bool &fValue); | bool ReadFlag(const std::string &name, bool &fValue); | ||||
bool LoadBlockIndexGuts( | bool LoadBlockIndexGuts( | ||||
const Config &config, | const Config &config, | ||||
std::function<CBlockIndex *(const uint256 &)> insertBlockIndex); | std::function<CBlockIndex *(const uint256 &)> insertBlockIndex); | ||||
}; | }; | ||||
/** | |||||
* Access to the txindex database (indexes/txindex/) | |||||
* | |||||
* The database stores a block locator of the chain the database is synced to | |||||
* so that the TxIndex can efficiently determine the point it last stopped at. | |||||
* A locator is used instead of a simple hash of the chain tip because blocks | |||||
* and block index entries may not be flushed to disk until after this database | |||||
* is updated. | |||||
*/ | |||||
class TxIndexDB : public CDBWrapper { | |||||
public: | |||||
explicit TxIndexDB(size_t n_cache_size, bool f_memory = false, | |||||
bool f_wipe = false); | |||||
/// Read the disk location of the transaction data with the given hash. | |||||
/// Returns false if the transaction hash is not indexed. | |||||
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const; | |||||
/// Write a batch of transaction positions to the DB. | |||||
bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>> &v_pos); | |||||
/// Read block locator of the chain that the txindex is in sync with. | |||||
bool ReadBestBlock(CBlockLocator &locator) const; | |||||
/// Write block locator of the chain that the txindex is in sync with. | |||||
bool WriteBestBlock(const CBlockLocator &locator); | |||||
}; | |||||
#endif // BITCOIN_TXDB_H | #endif // BITCOIN_TXDB_H |