@@ -15,14 +15,77 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
1515
1616class CKeyID ;
1717class CScript ;
18+ struct ScriptHash ;
19+
20+ template <typename HashType>
21+ class BaseHash
22+ {
23+ protected:
24+ HashType m_hash;
25+
26+ public:
27+ BaseHash () : m_hash() {}
28+ BaseHash (const HashType& in) : m_hash(in) {}
29+
30+ unsigned char * begin ()
31+ {
32+ return m_hash.begin ();
33+ }
34+
35+ const unsigned char * begin () const
36+ {
37+ return m_hash.begin ();
38+ }
39+
40+ unsigned char * end ()
41+ {
42+ return m_hash.end ();
43+ }
44+
45+ const unsigned char * end () const
46+ {
47+ return m_hash.end ();
48+ }
49+
50+ operator std::vector<unsigned char >() const
51+ {
52+ return std::vector<unsigned char >{m_hash.begin (), m_hash.end ()};
53+ }
54+
55+ std::string ToString () const
56+ {
57+ return m_hash.ToString ();
58+ }
59+
60+ bool operator ==(const BaseHash<HashType>& other) const noexcept
61+ {
62+ return m_hash == other.m_hash ;
63+ }
64+
65+ bool operator !=(const BaseHash<HashType>& other) const noexcept
66+ {
67+ return !(m_hash == other.m_hash );
68+ }
69+
70+ bool operator <(const BaseHash<HashType>& other) const noexcept
71+ {
72+ return m_hash < other.m_hash ;
73+ }
74+
75+ size_t size () const
76+ {
77+ return m_hash.size ();
78+ }
79+ };
1880
1981/* * A reference to a CScript: the Hash160 of its serialization (see script.h) */
20- class CScriptID : public uint160
82+ class CScriptID : public BaseHash < uint160>
2183{
2284public:
23- CScriptID () : uint160 () {}
85+ CScriptID () : BaseHash () {}
2486 explicit CScriptID (const CScript& in);
25- CScriptID (const uint160& in) : uint160(in) {}
87+ explicit CScriptID (const uint160& in) : BaseHash(in) {}
88+ explicit CScriptID (const ScriptHash& in);
2689};
2790
2891/* *
@@ -67,20 +130,21 @@ class CNoDestination {
67130 friend bool operator <(const CNoDestination &a, const CNoDestination &b) { return true ; }
68131};
69132
70- struct PKHash : public uint160
133+ struct PKHash : public BaseHash < uint160>
71134{
72- PKHash () : uint160 () {}
73- explicit PKHash (const uint160& hash) : uint160 (hash) {}
135+ PKHash () : BaseHash () {}
136+ explicit PKHash (const uint160& hash) : BaseHash (hash) {}
74137 explicit PKHash (const CPubKey& pubkey);
75- using uint160::uint160 ;
138+ explicit PKHash ( const CKeyID& pubkey_id) ;
76139};
140+ CKeyID ToKeyID (const PKHash& key_hash);
77141
78- struct ScriptHash : public uint160
142+ struct ScriptHash : public BaseHash < uint160>
79143{
80- ScriptHash () : uint160 () {}
81- explicit ScriptHash (const uint160& hash) : uint160 (hash) {}
144+ ScriptHash () : BaseHash () {}
145+ explicit ScriptHash (const uint160& hash) : BaseHash (hash) {}
82146 explicit ScriptHash (const CScript& script);
83- using uint160::uint160 ;
147+ explicit ScriptHash ( const CScriptID& script) ;
84148};
85149
86150/* *
0 commit comments