Bitcoin Core  21.99.0
P2P Digital Currency
txindex.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2018 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 <chain.h>
9 #include <index/base.h>
10 #include <txdb.h>
11 
17 class TxIndex final : public BaseIndex
18 {
19 protected:
20  class DB;
21 
22 private:
23  const std::unique_ptr<DB> m_db;
24 
25 protected:
27  bool Init() override;
28 
29  bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override;
30 
31  BaseIndex::DB& GetDB() const override;
32 
33  const char* GetName() const override { return "txindex"; }
34 
35 public:
37  explicit TxIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
38 
39  // Destructor is declared because this class contains a unique_ptr to an incomplete type.
40  virtual ~TxIndex() override;
41 
48  bool FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const;
49 };
50 
52 extern std::unique_ptr<TxIndex> g_txindex;
53 
54 #endif // BITCOIN_INDEX_TXINDEX_H
TxIndex::DB
Access to the txindex database (indexes/txindex/)
Definition: txindex.cpp:22
TxIndex::Init
bool Init() override
Override base class init to migrate from old database.
Definition: txindex.cpp:200
TxIndex::WriteBlock
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Definition: txindex.cpp:214
TxIndex::m_db
const std::unique_ptr< DB > m_db
Definition: txindex.h:20
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
base.h
BaseIndex
Base class for indices of blockchain data.
Definition: base.h:27
TxIndex::~TxIndex
virtual ~TxIndex() override
Definition: txindex.cpp:198
uint256
256-bit opaque blob.
Definition: uint256.h:124
TxIndex::GetName
const char * GetName() const override
Get the name of the index for display in logs.
Definition: txindex.h:33
TxIndex::GetDB
BaseIndex::DB & GetDB() const override
Definition: txindex.cpp:229
CBlock
Definition: block.h:62
TxIndex::FindTx
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
Definition: txindex.cpp:231
TxIndex
TxIndex is used to look up transactions included in the blockchain by hash.
Definition: txindex.h:17
BaseIndex::DB
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:37
g_txindex
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:17
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
TxIndex::TxIndex
TxIndex(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:194
txdb.h