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

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2015 The Bitcoin Core developers
       3             : // Copyright (c) 2016 BitPay Inc.
       4             : // Copyright (c) 2023-2026 The Dash Core developers
       5             : // Distributed under the MIT software license, see the accompanying
       6             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       7             : 
       8             : #ifndef BITCOIN_INDEX_SPENTINDEX_TYPES_H
       9             : #define BITCOIN_INDEX_SPENTINDEX_TYPES_H
      10             : 
      11             : #include <consensus/amount.h>
      12             : #include <index/addressindex_types.h>
      13             : #include <serialize.h>
      14             : #include <uint256.h>
      15             : 
      16             : #include <map>
      17             : #include <tuple>
      18             : 
      19             : struct CSpentIndexKey {
      20             : public:
      21             :     uint256 m_tx_hash;
      22          20 :     uint32_t m_tx_index{0};
      23             : 
      24             : public:
      25          60 :     CSpentIndexKey() { SetNull(); }
      26             : 
      27         212 :     CSpentIndexKey(uint256 txout_hash, uint32_t txout_index) :
      28         106 :         m_tx_hash{txout_hash},
      29         212 :         m_tx_index{txout_index} {};
      30             : 
      31          20 :     void SetNull()
      32             :     {
      33          20 :         m_tx_hash.SetNull();
      34          20 :         m_tx_index = 0;
      35          20 :     }
      36             : 
      37             : public:
      38         210 :     SERIALIZE_METHODS(CSpentIndexKey, obj) { READWRITE(obj.m_tx_hash, obj.m_tx_index); }
      39             : };
      40             : 
      41             : struct CSpentIndexValue {
      42             : public:
      43             :     uint256 m_tx_hash;
      44          60 :     uint32_t m_tx_index{0};
      45          60 :     int32_t m_block_height{0};
      46          60 :     CAmount m_amount{0};
      47          60 :     AddressType m_address_type{AddressType::UNKNOWN};
      48             :     uint160 m_address_bytes;
      49             : 
      50             : public:
      51         180 :     CSpentIndexValue() { SetNull(); }
      52             : 
      53          84 :     CSpentIndexValue(uint256 txin_hash, uint32_t txin_index, int32_t block_height, CAmount amount,
      54             :                      AddressType address_type, uint160 address_bytes) :
      55          42 :         m_tx_hash{txin_hash},
      56          42 :         m_tx_index{txin_index},
      57          42 :         m_block_height{block_height},
      58          42 :         m_amount{amount},
      59          42 :         m_address_type{address_type},
      60          84 :         m_address_bytes{address_bytes} {};
      61             : 
      62          60 :     void SetNull()
      63             :     {
      64          60 :         m_tx_hash.SetNull();
      65          60 :         m_tx_index = 0;
      66          60 :         m_block_height = 0;
      67          60 :         m_amount = 0;
      68          60 :         m_address_type = AddressType::UNKNOWN;
      69          60 :         m_address_bytes.SetNull();
      70          60 :     }
      71             : 
      72          24 :     bool IsNull() const { return m_tx_hash.IsNull(); }
      73             : 
      74             : public:
      75         108 :     SERIALIZE_METHODS(CSpentIndexValue, obj)
      76             :     {
      77          36 :         READWRITE(obj.m_tx_hash, obj.m_tx_index, obj.m_block_height, obj.m_amount, obj.m_address_type, obj.m_address_bytes);
      78          36 :     }
      79             : };
      80             : 
      81             : struct CSpentIndexKeyCompare {
      82          93 :     bool operator()(const CSpentIndexKey& a, const CSpentIndexKey& b) const
      83             :     {
      84         279 :         auto to_tuple = [](const CSpentIndexKey& obj) { return std::tie(obj.m_tx_hash, obj.m_tx_index); };
      85          93 :         return to_tuple(a) < to_tuple(b);
      86             :     }
      87             : };
      88             : 
      89             : using CSpentIndexEntry = std::pair<CSpentIndexKey, CSpentIndexValue>;
      90             : 
      91             : #endif // BITCOIN_INDEX_SPENTINDEX_TYPES_H

Generated by: LCOV version 1.16