Bitcoin Core 28.99.0
P2P Digital Currency
txindex.h
Go to the documentation of this file.
1// Copyright (c) 2017-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_INDEX_TXINDEX_H
6#define BITCOIN_INDEX_TXINDEX_H
7
8#include <index/base.h>
9
10static constexpr bool DEFAULT_TXINDEX{false};
11
17class TxIndex final : public BaseIndex
18{
19protected:
20 class DB;
21
22private:
23 const std::unique_ptr<DB> m_db;
24
25 bool AllowPrune() const override { return false; }
26
27protected:
28 bool CustomAppend(const interfaces::BlockInfo& block) override;
29
30 BaseIndex::DB& GetDB() const override;
31
32public:
34 explicit TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
35
36 // Destructor is declared because this class contains a unique_ptr to an incomplete type.
37 virtual ~TxIndex() override;
38
45 bool FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const;
46};
47
49extern std::unique_ptr<TxIndex> g_txindex;
50
51#endif // BITCOIN_INDEX_TXINDEX_H
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:53
Base class for indices of blockchain data.
Definition: base.h:43
Access to the txindex database (indexes/txindex/)
Definition: txindex.cpp:21
TxIndex is used to look up transactions included in the blockchain by hash.
Definition: txindex.h:18
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
Definition: txindex.cpp:75
BaseIndex::DB & GetDB() const override
Definition: txindex.cpp:73
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
Definition: txindex.cpp:57
TxIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
Definition: txindex.cpp:51
virtual ~TxIndex() override
bool AllowPrune() const override
Definition: txindex.h:25
const std::unique_ptr< DB > m_db
Definition: txindex.h:23
256-bit opaque blob.
Definition: uint256.h:190
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:78
static constexpr bool DEFAULT_TXINDEX
Definition: txindex.h:10
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:16