Changeset View
Changeset View
Standalone View
Standalone View
src/index/txindex.h
// Copyright (c) 2017-2018 The Bitcoin Core developers | // Copyright (c) 2017-2018 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_INDEX_TXINDEX_H | #ifndef BITCOIN_INDEX_TXINDEX_H | ||||
#define BITCOIN_INDEX_TXINDEX_H | #define BITCOIN_INDEX_TXINDEX_H | ||||
#include <index/base.h> | #include <index/base.h> | ||||
#include <txdb.h> | |||||
/** | /** | ||||
* TxIndex is used to look up transactions included in the blockchain by hash. | * TxIndex is used to look up transactions included in the blockchain by hash. | ||||
* The index is written to a LevelDB database and records the filesystem | * The index is written to a LevelDB database and records the filesystem | ||||
* location of each transaction by transaction hash. | * location of each transaction by transaction hash. | ||||
*/ | */ | ||||
class TxIndex final : public BaseIndex { | class TxIndex final : public BaseIndex { | ||||
protected: | |||||
class DB; | |||||
private: | private: | ||||
const std::unique_ptr<TxIndexDB> m_db; | const std::unique_ptr<DB> m_db; | ||||
protected: | protected: | ||||
/// Override base class init to migrate from old database. | /// Override base class init to migrate from old database. | ||||
bool Init() override; | bool Init() override; | ||||
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override; | bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override; | ||||
BaseIndexDB &GetDB() const override; | BaseIndex::DB &GetDB() const override; | ||||
const char *GetName() const override { return "txindex"; } | const char *GetName() const override { return "txindex"; } | ||||
public: | public: | ||||
/// Constructs the index, which becomes available to be queried. | /// Constructs the index, which becomes available to be queried. | ||||
explicit TxIndex(std::unique_ptr<TxIndexDB> db); | explicit TxIndex(size_t n_cache_size, bool f_memory = false, | ||||
bool f_wipe = false); | |||||
// Destructor is declared because this class contains a unique_ptr to an | |||||
// incomplete type. | |||||
virtual ~TxIndex() override; | |||||
/// Look up a transaction by hash. | /// Look up a transaction by hash. | ||||
/// | /// | ||||
/// @param[in] tx_hash The hash of the transaction to be returned. | /// @param[in] tx_hash The hash of the transaction to be returned. | ||||
/// @param[out] block_hash The hash of the block the transaction is found | /// @param[out] block_hash The hash of the block the transaction is found | ||||
/// in. | /// in. | ||||
/// @param[out] tx The transaction itself. | /// @param[out] tx The transaction itself. | ||||
/// @return true if transaction is found, false otherwise | /// @return true if transaction is found, false otherwise | ||||
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, | bool FindTx(const uint256 &tx_hash, uint256 &block_hash, | ||||
CTransactionRef &tx) const; | CTransactionRef &tx) const; | ||||
}; | }; | ||||
/// The global transaction index, used in GetTransaction. May be null. | /// The global transaction index, used in GetTransaction. May be null. | ||||
extern std::unique_ptr<TxIndex> g_txindex; | extern std::unique_ptr<TxIndex> g_txindex; | ||||
#endif // BITCOIN_INDEX_TXINDEX_H | #endif // BITCOIN_INDEX_TXINDEX_H |