LCOV - code coverage report
Current view: top level - src/index - txindex.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 2 100.0 %
Date: 2026-06-25 07:23:43 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2017-2021 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             : static constexpr bool DEFAULT_TXINDEX{true};
      11             : 
      12             : /**
      13             :  * TxIndex is used to look up transactions included in the blockchain by hash.
      14             :  * The index is written to a LevelDB database and records the filesystem
      15             :  * location of each transaction by transaction hash.
      16             :  */
      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      255474 :     bool AllowPrune() const override { return false; }
      26             : 
      27             : protected:
      28             :     bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override;
      29             : 
      30             :     BaseIndex::DB& GetDB() const override;
      31             : 
      32        7739 :     const char* GetName() const override { return "txindex"; }
      33             : 
      34             : public:
      35             :     /// Constructs the index, which becomes available to be queried.
      36             :     explicit TxIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
      37             : 
      38             :     // Destructor is declared because this class contains a unique_ptr to an incomplete type.
      39             :     virtual ~TxIndex() override;
      40             : 
      41             :     /// Look up a transaction by hash.
      42             :     ///
      43             :     /// @param[in]   tx_hash  The hash of the transaction to be returned.
      44             :     /// @param[out]  block_hash  The hash of the block the transaction is found in.
      45             :     /// @param[out]  tx  The transaction itself.
      46             :     /// @return  true if transaction is found, false otherwise
      47             :     bool FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const;
      48             :     bool HasTx(const uint256& tx_hash) const;
      49             : };
      50             : 
      51             : /// The global transaction index, used in GetTransaction. May be null.
      52             : extern std::unique_ptr<TxIndex> g_txindex;
      53             : 
      54             : #endif // BITCOIN_INDEX_TXINDEX_H

Generated by: LCOV version 1.16