Bitcoin Core 31.99.0
P2P Digital Currency
txindex.h
Go to the documentation of this file.
1// Copyright (c) 2017-present 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>
10#include <uint256.h>
11
12#include <cstddef>
13#include <memory>
14#include <optional>
15
16namespace interfaces {
17class Chain;
18}
19namespace txindex_tests {
20class TxIndexTest;
21}
22
23inline constexpr bool DEFAULT_TXINDEX{false};
24
29};
30
36class TxIndex final : public BaseIndex
37{
38protected:
39 class DB;
40
41private:
43 const std::unique_ptr<DB> m_db;
44
45 bool AllowPrune() const override { return false; }
46
48 std::optional<TxIndexResult> FindLegacyTx(const Txid& tx_hash) const;
49
50protected:
51 bool CustomAppend(const interfaces::BlockInfo& block) override;
52
53 BaseIndex::DB& GetDB() const override;
54
55public:
57 explicit TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
58
59 // Destructor is declared because this class contains a unique_ptr to an incomplete type.
60 virtual ~TxIndex() override;
61
66 std::optional<TxIndexResult> FindTx(const Txid& tx_hash) const;
67};
68
70extern std::unique_ptr<TxIndex> g_txindex;
71
72#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:65
Base class for indices of blockchain data.
Definition: base.h:55
Access to the txindex database (indexes/txindex/)
Definition: txindex.cpp:58
TxIndex is used to look up transactions included in the blockchain by hash.
Definition: txindex.h:37
BaseIndex::DB & GetDB() const override
Definition: txindex.cpp:157
std::optional< TxIndexResult > FindTx(const Txid &tx_hash) const
Look up a transaction by hash.
Definition: txindex.cpp:159
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
Definition: txindex.cpp:147
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:135
virtual ~TxIndex() override
bool AllowPrune() const override
Definition: txindex.h:45
const std::unique_ptr< DB > m_db
Definition: txindex.h:43
std::optional< TxIndexResult > FindLegacyTx(const Txid &tx_hash) const
Look up a transaction among the legacy (full-txid) entries.
Definition: txindex.cpp:220
friend class txindex_tests::TxIndexTest
Definition: txindex.h:42
256-bit opaque blob.
Definition: uint256.h:196
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
A found transaction and the hash of the block that contains it.
Definition: txindex.h:26
CTransactionRef tx
Definition: txindex.h:28
uint256 block_hash
Definition: txindex.h:27
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:19
constexpr bool DEFAULT_TXINDEX
Definition: txindex.h:23
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:41