Bitcoin ABC  0.29.6
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 <index/base.h>
9 
10 #include <memory>
11 
12 struct BlockHash;
13 struct TxId;
14 
15 static constexpr bool DEFAULT_TXINDEX{false};
16 
22 class TxIndex final : public BaseIndex {
23 protected:
24  class DB;
25 
26 private:
27  const std::unique_ptr<DB> m_db;
28 
29  bool AllowPrune() const override { return false; }
30 
31 protected:
32  bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override;
33 
34  BaseIndex::DB &GetDB() const override;
35 
36  const char *GetName() const override { return "txindex"; }
37 
38 public:
40  explicit TxIndex(size_t n_cache_size, bool f_memory = false,
41  bool f_wipe = false);
42 
43  // Destructor is declared because this class contains a unique_ptr to an
44  // incomplete type.
45  virtual ~TxIndex() override;
46 
54  bool FindTx(const TxId &txid, BlockHash &block_hash,
55  CTransactionRef &tx) const;
56 };
57 
59 extern std::unique_ptr<TxIndex> g_txindex;
60 
61 #endif // BITCOIN_INDEX_TXINDEX_H
The database stores a block locator of the chain the database is synced to so that the TxIndex can ef...
Definition: base.h:36
Base class for indices of blockchain data.
Definition: base.h:27
Definition: block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
Access to the txindex database (indexes/txindex/)
Definition: txindex.cpp:19
TxIndex is used to look up transactions included in the blockchain by ID.
Definition: txindex.h:22
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:49
bool FindTx(const TxId &txid, BlockHash &block_hash, CTransactionRef &tx) const
Look up a transaction by identifier.
Definition: txindex.cpp:75
BaseIndex::DB & GetDB() const override
Definition: txindex.cpp:71
virtual ~TxIndex() override
Definition: txindex.cpp:52
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Definition: txindex.cpp:54
bool AllowPrune() const override
Definition: txindex.h:29
const std::unique_ptr< DB > m_db
Definition: txindex.h:24
const char * GetName() const override
Get the name of the index for display in logs.
Definition: txindex.h:36
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
A TxId is the identifier of a transaction.
Definition: txid.h:14
static constexpr bool DEFAULT_TXINDEX
Definition: txindex.h:15
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:16