Merge bitcoin/bitcoin#32631: refactor: Convert GenTxid to std::variant

a60f863d3e scripted-diff: Replace GenTxidVariant with GenTxid (marcofleon)
c8ba199598 Remove old GenTxid class (marcofleon)
072a198ea4 Convert remaining instances of GenTxid to GenTxidVariant (marcofleon)
1b528391c7 Convert `txrequest` to GenTxidVariant (marcofleon)
bde4579b07 Convert `txdownloadman_impl` to GenTxidVariant (marcofleon)
c876a892ec Replace GenTxid with Txid/Wtxid overloads in `txmempool` (marcofleon)
de858ce2be move-only: make GetInfo a private CTxMemPool member (stickies-v)
eee473d9f3 Convert `CompareInvMempoolOrder` to GenTxidVariant (marcofleon)
243553d590 refactor: replace get_iter_from_wtxid with GetIter(const Wtxid&) (stickies-v)
fcf92fd640 refactor: make CTxMemPool::GetIter strongly typed (marcofleon)
11d28f21bb Implement GenTxid as a variant (marcofleon)

Pull request description:

  Part of the [type safety refactor](https://github.com/bitcoin/bitcoin/pull/32189).

  This PR changes the GenTxid class to a variant, which holds both Txids and Wtxids. This provides compile-time type safety and eliminates the manual type check (bool m_is_wtxid). Variables that can be either a Txid or a Wtxid are now using the new GenTxid variant, instead of uint256.

ACKs for top commit:
  w0xlt:
    ACK a60f863d3e
  dergoegge:
    Code review ACK a60f863d3e
  maflcko:
    review ACK a60f863d3e 🎽
  theStack:
    Code-review ACK a60f863d3e

Tree-SHA512: da9b73b7bdffee2eb9281a409205519ac330d3336094d17681896703fbca8099608782c9c85801e388e4d90af5af8abf1f34931f57bbbe6e9674d802d6066047
This commit is contained in:
merge-script
2025-07-11 13:47:19 -04:00
33 changed files with 312 additions and 315 deletions

View File

@@ -9,6 +9,11 @@
#include <uint256.h>
#include <util/types.h>
#include <compare>
#include <concepts>
#include <tuple>
#include <variant>
/** transaction_identifier represents the two canonical transaction identifier
* types (txid, wtxid).*/
template <bool has_witness>
@@ -76,4 +81,25 @@ using Txid = transaction_identifier<false>;
/** Wtxid commits to all transaction fields including the witness. */
using Wtxid = transaction_identifier<true>;
template <typename T>
concept TxidOrWtxid = std::is_same_v<T, Txid> || std::is_same_v<T, Wtxid>;
class GenTxid : public std::variant<Txid, Wtxid>
{
public:
using variant::variant;
bool IsWtxid() const { return std::holds_alternative<Wtxid>(*this); }
const uint256& ToUint256() const LIFETIMEBOUND
{
return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this);
}
friend auto operator<=>(const GenTxid& a, const GenTxid& b)
{
return std::tuple(a.IsWtxid(), a.ToUint256()) <=> std::tuple(b.IsWtxid(), b.ToUint256());
}
};
#endif // BITCOIN_UTIL_TRANSACTION_IDENTIFIER_H