mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-16 09:39:52 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user