|
| 1 | +#ifndef OUTPUT_HASH_H |
| 2 | +#define OUTPUT_HASH_H |
| 3 | + |
| 4 | +#include "serialize.h" |
| 5 | +#include "uint256.h" |
| 6 | + |
| 7 | +/** This class is "equivalent" to a uint256, but semantically it represents |
| 8 | + * a specific use, namely the hash used for an outpoint in the UTXO set |
| 9 | + * and referred to by following transactions. This is the normal txid |
| 10 | + * originally, but may be changed in the future e.g. with segwit-light. */ |
| 11 | +class OutputHash |
| 12 | +{ |
| 13 | + |
| 14 | +private: |
| 15 | + |
| 16 | + /** The actual hash value. */ |
| 17 | + uint256 value; |
| 18 | + |
| 19 | +public: |
| 20 | + |
| 21 | + OutputHash () = default; |
| 22 | + OutputHash (const OutputHash&) = default; |
| 23 | + OutputHash& operator= (const OutputHash&) = default; |
| 24 | + |
| 25 | + explicit OutputHash (const uint256& val) |
| 26 | + : value(val) |
| 27 | + {} |
| 28 | + |
| 29 | + ADD_SERIALIZE_METHODS; |
| 30 | + |
| 31 | + template<typename Stream, typename Operation> |
| 32 | + inline void SerializationOp (Stream& s, Operation ser_action, |
| 33 | + int nType, int nVersion) |
| 34 | + { |
| 35 | + READWRITE (value); |
| 36 | + } |
| 37 | + |
| 38 | + inline const uint256& GetValue () const |
| 39 | + { |
| 40 | + return value; |
| 41 | + } |
| 42 | + |
| 43 | + inline void SetNull () |
| 44 | + { |
| 45 | + value.SetNull (); |
| 46 | + } |
| 47 | + |
| 48 | + inline bool IsNull () const |
| 49 | + { |
| 50 | + return value.IsNull (); |
| 51 | + } |
| 52 | + |
| 53 | + inline std::string ToString () const |
| 54 | + { |
| 55 | + return value.ToString (); |
| 56 | + } |
| 57 | + |
| 58 | + inline std::string GetHex () const |
| 59 | + { |
| 60 | + return value.GetHex (); |
| 61 | + } |
| 62 | + |
| 63 | + inline friend bool operator== (const OutputHash& a, const OutputHash& b) |
| 64 | + { |
| 65 | + return a.value == b.value; |
| 66 | + } |
| 67 | + |
| 68 | + inline friend bool operator!= (const OutputHash& a, const OutputHash& b) |
| 69 | + { |
| 70 | + return !(a == b); |
| 71 | + } |
| 72 | + |
| 73 | + inline friend bool operator< (const OutputHash& a, const OutputHash& b) |
| 74 | + { |
| 75 | + return a.value < b.value; |
| 76 | + } |
| 77 | + |
| 78 | +}; |
| 79 | + |
| 80 | +#endif // OUTPUT_HASH_H |
0 commit comments