refactor: disable default std::hash for CTransactionRef

The default std::hash for shared_ptr compares by pointer.

CTransactionRefHash or a custom hasher should be used instead.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This commit is contained in:
Sjors Provoost
2026-04-27 14:14:07 +02:00
parent 47d68cd981
commit a9301cfa07

View File

@@ -403,4 +403,16 @@ struct CMutableTransaction
typedef std::shared_ptr<const CTransaction> CTransactionRef;
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
namespace std {
/** Disable default std::hash for CTransactionRef to prevent accidentally
* comparing by pointer. Use CTransactionRefHash or provide a custom
* hasher. */
template <>
struct hash<CTransactionRef> {
hash() = delete;
// Belt-and-suspenders, already implied by the above.
size_t operator()(const CTransactionRef&) const = delete;
};
} // namespace std
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H