diff options
author | Pieter Wuille <pieter@wuille.net> | 2020-07-22 17:17:00 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2020-07-30 13:44:54 -0700 |
commit | 9efd86a908cf09d9ddbadd3195f202635117d505 (patch) | |
tree | ec801408297a936d5602b9fa1438a44accf7d4b6 /src/primitives/transaction.h | |
parent | d362f19355b36531a4a82094e0259f7f3db500a7 (diff) | |
download | bitcoin-9efd86a908cf09d9ddbadd3195f202635117d505.tar.xz |
refactor: add GenTxid (=txid or wtxid) type and use it for tx request logic
Diffstat (limited to 'src/primitives/transaction.h')
-rw-r--r-- | src/primitives/transaction.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 4514db578a..544bab6d9b 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -12,6 +12,8 @@ #include <serialize.h> #include <uint256.h> +#include <tuple> + static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000; /** An outpoint - a combination of a transaction hash and an index n into its vout */ @@ -388,4 +390,17 @@ typedef std::shared_ptr<const CTransaction> CTransactionRef; static inline CTransactionRef MakeTransactionRef() { return std::make_shared<const CTransaction>(); } template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); } +/** A generic txid reference (txid or wtxid). */ +class GenTxid +{ + const bool m_is_wtxid; + const uint256 m_hash; +public: + GenTxid(bool is_wtxid, const uint256& hash) : m_is_wtxid(is_wtxid), m_hash(hash) {} + bool IsWtxid() const { return m_is_wtxid; } + const uint256& GetHash() const { return m_hash; } + friend bool operator==(const GenTxid& a, const GenTxid& b) { return a.m_is_wtxid == b.m_is_wtxid && a.m_hash == b.m_hash; } + friend bool operator<(const GenTxid& a, const GenTxid& b) { return std::tie(a.m_is_wtxid, a.m_hash) < std::tie(b.m_is_wtxid, b.m_hash); } +}; + #endif // BITCOIN_PRIMITIVES_TRANSACTION_H |