/Users/eugenesiegel/btc/bitcoin/src/primitives/transaction_identifier.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | // Copyright (c) 2023-present The Bitcoin Core developers | 
| 2 |  | // Distributed under the MIT software license, see the accompanying | 
| 3 |  | // file COPYING or https://opensource.org/license/mit. | 
| 4 |  |  | 
| 5 |  | #ifndef BITCOIN_PRIMITIVES_TRANSACTION_IDENTIFIER_H | 
| 6 |  | #define BITCOIN_PRIMITIVES_TRANSACTION_IDENTIFIER_H | 
| 7 |  |  | 
| 8 |  | #include <attributes.h> | 
| 9 |  | #include <uint256.h> | 
| 10 |  | #include <util/types.h> | 
| 11 |  |  | 
| 12 |  | #include <compare> | 
| 13 |  | #include <concepts> | 
| 14 |  | #include <tuple> | 
| 15 |  | #include <variant> | 
| 16 |  |  | 
| 17 |  | /** transaction_identifier represents the two canonical transaction identifier | 
| 18 |  |  * types (txid, wtxid).*/ | 
| 19 |  | template <bool has_witness> | 
| 20 |  | class transaction_identifier | 
| 21 |  | { | 
| 22 |  |     uint256 m_wrapped; | 
| 23 |  |  | 
| 24 |  |     // Note: Use FromUint256 externally instead. | 
| 25 | 38.7M |     transaction_identifier(const uint256& wrapped) : m_wrapped{wrapped} {}_ZN22transaction_identifierILb0EEC2ERK7uint256| Line | Count | Source |  | 25 | 17.5M |     transaction_identifier(const uint256& wrapped) : m_wrapped{wrapped} {} | 
_ZN22transaction_identifierILb1EEC2ERK7uint256| Line | Count | Source |  | 25 | 21.1M |     transaction_identifier(const uint256& wrapped) : m_wrapped{wrapped} {} | 
 | 
| 26 |  |  | 
| 27 | 743M |     constexpr int Compare(const transaction_identifier<has_witness>& other) const { return m_wrapped.Compare(other.m_wrapped); }_ZNK22transaction_identifierILb0EE7CompareERKS0_| Line | Count | Source |  | 27 | 733M |     constexpr int Compare(const transaction_identifier<has_witness>& other) const { return m_wrapped.Compare(other.m_wrapped); } | 
_ZNK22transaction_identifierILb1EE7CompareERKS0_| Line | Count | Source |  | 27 | 9.30M |     constexpr int Compare(const transaction_identifier<has_witness>& other) const { return m_wrapped.Compare(other.m_wrapped); } | 
 | 
| 28 |  |     template <typename Other> | 
| 29 |  |     constexpr int Compare(const Other& other) const | 
| 30 |  |     { | 
| 31 |  |         static_assert(ALWAYS_FALSE<Other>, "Forbidden comparison type"); | 
| 32 |  |         return 0; | 
| 33 |  |     } | 
| 34 |  |  | 
| 35 |  | public: | 
| 36 | 29.8M |     transaction_identifier() : m_wrapped{} {}_ZN22transaction_identifierILb0EEC2Ev| Line | Count | Source |  | 36 | 27.0M |     transaction_identifier() : m_wrapped{} {} | 
_ZN22transaction_identifierILb1EEC2Ev| Line | Count | Source |  | 36 | 2.83M |     transaction_identifier() : m_wrapped{} {} | 
 | 
| 37 |  |  | 
| 38 |  |     template <typename Other> | 
| 39 | 210M |     bool operator==(const Other& other) const { return Compare(other) == 0; }_ZNK22transaction_identifierILb0EEeqIS0_EEbRKT_| Line | Count | Source |  | 39 | 205M |     bool operator==(const Other& other) const { return Compare(other) == 0; } | 
_ZNK22transaction_identifierILb1EEeqIS0_EEbRKT_| Line | Count | Source |  | 39 | 4.28M |     bool operator==(const Other& other) const { return Compare(other) == 0; } | 
 | 
| 40 |  |     template <typename Other> | 
| 41 | 1.36k |     bool operator!=(const Other& other) const { return Compare(other) != 0; }_ZNK22transaction_identifierILb0EEneIS0_EEbRKT_| Line | Count | Source |  | 41 | 104 |     bool operator!=(const Other& other) const { return Compare(other) != 0; } | 
_ZNK22transaction_identifierILb1EEneIS0_EEbRKT_| Line | Count | Source |  | 41 | 1.25k |     bool operator!=(const Other& other) const { return Compare(other) != 0; } | 
 | 
| 42 |  |     template <typename Other> | 
| 43 | 532M |     bool operator<(const Other& other) const { return Compare(other) < 0; }_ZNK22transaction_identifierILb0EEltIS0_EEbRKT_| Line | Count | Source |  | 43 | 527M |     bool operator<(const Other& other) const { return Compare(other) < 0; } | 
_ZNK22transaction_identifierILb1EEltIS0_EEbRKT_| Line | Count | Source |  | 43 | 5.02M |     bool operator<(const Other& other) const { return Compare(other) < 0; } | 
 | 
| 44 |  |  | 
| 45 | 263M |     const uint256& ToUint256() const LIFETIMEBOUND { return m_wrapped; }_ZNK22transaction_identifierILb0EE9ToUint256Ev| Line | Count | Source |  | 45 | 227M |     const uint256& ToUint256() const LIFETIMEBOUND { return m_wrapped; } | 
_ZNK22transaction_identifierILb1EE9ToUint256Ev| Line | Count | Source |  | 45 | 35.9M |     const uint256& ToUint256() const LIFETIMEBOUND { return m_wrapped; } | 
 | 
| 46 | 38.7M |     static transaction_identifier FromUint256(const uint256& id) { return {id}; }_ZN22transaction_identifierILb0EE11FromUint256ERK7uint256| Line | Count | Source |  | 46 | 17.5M |     static transaction_identifier FromUint256(const uint256& id) { return {id}; } | 
_ZN22transaction_identifierILb1EE11FromUint256ERK7uint256| Line | Count | Source |  | 46 | 21.1M |     static transaction_identifier FromUint256(const uint256& id) { return {id}; } | 
 | 
| 47 |  |  | 
| 48 |  |     /** Wrapped `uint256` methods. */ | 
| 49 | 59.4M |     constexpr bool IsNull() const { return m_wrapped.IsNull(); } | 
| 50 | 2.00M |     constexpr void SetNull() { m_wrapped.SetNull(); } | 
| 51 |  |     static std::optional<transaction_identifier> FromHex(std::string_view hex) | 
| 52 | 0 |     { | 
| 53 | 0 |         auto u{uint256::FromHex(hex)}; | 
| 54 | 0 |         if (!u) return std::nullopt; | 
| 55 | 0 |         return FromUint256(*u); | 
| 56 | 0 |     } Unexecuted instantiation: _ZN22transaction_identifierILb0EE7FromHexENSt3__117basic_string_viewIcNS1_11char_traitsIcEEEEUnexecuted instantiation: _ZN22transaction_identifierILb1EE7FromHexENSt3__117basic_string_viewIcNS1_11char_traitsIcEEEE | 
| 57 | 0 |     std::string GetHex() const { return m_wrapped.GetHex(); }Unexecuted instantiation: _ZNK22transaction_identifierILb0EE6GetHexEvUnexecuted instantiation: _ZNK22transaction_identifierILb1EE6GetHexEv | 
| 58 | 379k |     std::string ToString() const { return m_wrapped.ToString(); }_ZNK22transaction_identifierILb0EE8ToStringEv| Line | Count | Source |  | 58 | 263k |     std::string ToString() const { return m_wrapped.ToString(); } | 
_ZNK22transaction_identifierILb1EE8ToStringEv| Line | Count | Source |  | 58 | 115k |     std::string ToString() const { return m_wrapped.ToString(); } | 
 | 
| 59 |  |     static constexpr auto size() { return decltype(m_wrapped)::size(); } | 
| 60 |  |     constexpr const std::byte* data() const { return reinterpret_cast<const std::byte*>(m_wrapped.data()); } | 
| 61 | 1.09M |     constexpr const std::byte* begin() const { return reinterpret_cast<const std::byte*>(m_wrapped.begin()); }_ZNK22transaction_identifierILb1EE5beginEv| Line | Count | Source |  | 61 | 1.09M |     constexpr const std::byte* begin() const { return reinterpret_cast<const std::byte*>(m_wrapped.begin()); } | 
Unexecuted instantiation: _ZNK22transaction_identifierILb0EE5beginEv | 
| 62 | 0 |     constexpr const std::byte* end() const { return reinterpret_cast<const std::byte*>(m_wrapped.end()); } | 
| 63 | 44.0M |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); }_ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR12SizeComputer20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 63 | 5.60M |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
_ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR12VectorWriter20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 63 | 5.37M |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
Unexecuted instantiation: _ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT__ZNK22transaction_identifierILb0EE9SerializeI10DataStreamEEvRT_| Line | Count | Source |  | 63 | 1.54M |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
Unexecuted instantiation: _ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIRS2_IR12VectorWriter20TransactionSerParamsES5_EEEvRT_Unexecuted instantiation: _ZNK22transaction_identifierILb0EE9SerializeI8AutoFileEEvRT__ZNK22transaction_identifierILb0EE9SerializeI10HashWriterEEvRT_| Line | Count | Source |  | 63 | 504k |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
_ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 63 | 162k |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
Unexecuted instantiation: _ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_Unexecuted instantiation: _ZNK22transaction_identifierILb1EE9SerializeI10HashWriterEEvRT__ZNK22transaction_identifierILb0EE9SerializeI12ParamsStreamIR10HashWriter20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 63 | 30.8M |     template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); } | 
 | 
| 64 | 5.28M |     template <typename Stream> void Unserialize(Stream& s) { m_wrapped.Unserialize(s); }_ZN22transaction_identifierILb0EE11UnserializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 64 | 4.97M |     template <typename Stream> void Unserialize(Stream& s) { m_wrapped.Unserialize(s); } | 
Unexecuted instantiation: _ZN22transaction_identifierILb0EE11UnserializeI10DataStreamEEvRT__ZN22transaction_identifierILb0EE11UnserializeI12ParamsStreamIR10SpanReader20TransactionSerParamsEEEvRT_| Line | Count | Source |  | 64 | 311k |     template <typename Stream> void Unserialize(Stream& s) { m_wrapped.Unserialize(s); } | 
Unexecuted instantiation: _ZN22transaction_identifierILb0EE11UnserializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_Unexecuted instantiation: _ZN22transaction_identifierILb0EE11UnserializeI8AutoFileEEvRT_Unexecuted instantiation: _ZN22transaction_identifierILb0EE11UnserializeI12ParamsStreamIR12BufferedFile20TransactionSerParamsEEEvRT_ | 
| 65 |  | }; | 
| 66 |  |  | 
| 67 |  | /** Txid commits to all transaction fields except the witness. */ | 
| 68 |  | using Txid = transaction_identifier<false>; | 
| 69 |  | /** Wtxid commits to all transaction fields including the witness. */ | 
| 70 |  | using Wtxid = transaction_identifier<true>; | 
| 71 |  |  | 
| 72 |  | template <typename T> | 
| 73 |  | concept TxidOrWtxid = std::is_same_v<T, Txid> || std::is_same_v<T, Wtxid>; | 
| 74 |  |  | 
| 75 |  | class GenTxid : public std::variant<Txid, Wtxid> | 
| 76 |  | { | 
| 77 |  | public: | 
| 78 |  |     using variant::variant; | 
| 79 |  |  | 
| 80 | 2.49M |     bool IsWtxid() const { return std::holds_alternative<Wtxid>(*this); } | 
| 81 |  |  | 
| 82 |  |     const uint256& ToUint256() const LIFETIMEBOUND | 
| 83 | 6.03M |     { | 
| 84 | 6.03M |         return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this);_ZZNK7GenTxid9ToUint256EvENKUlRKT_E_clI22transaction_identifierILb0EEEERK7uint256S2_| Line | Count | Source |  | 84 | 1.21M |         return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this); | 
_ZZNK7GenTxid9ToUint256EvENKUlRKT_E_clI22transaction_identifierILb1EEEERK7uint256S2_| Line | Count | Source |  | 84 | 4.81M |         return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this); | 
 | 
| 85 | 6.03M |     } | 
| 86 |  |  | 
| 87 |  |     friend auto operator<=>(const GenTxid& a, const GenTxid& b) | 
| 88 | 1.24M |     { | 
| 89 |  |         // Use a reference for read-only access to the hash, avoiding a copy that might not be optimized away. | 
| 90 | 1.24M |         return std::tuple<bool, const uint256&>(a.IsWtxid(), a.ToUint256()) <=> std::tuple<bool, const uint256&>(b.IsWtxid(), b.ToUint256()); | 
| 91 | 1.24M |     } | 
| 92 |  | }; | 
| 93 |  |  | 
| 94 |  | #endif // BITCOIN_PRIMITIVES_TRANSACTION_IDENTIFIER_H |