Skip to content

Commit 966a22d

Browse files
committed
Explicitly support conversion between equivalent hash types
ScriptHash <-> CScriptID CKeyID -> PKHash PKHash -> WitnessV0KeyHash
1 parent f32c1e0 commit 966a22d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/script/standard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER;
1717
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
1818

1919
CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
20+
CScriptID::CScriptID(const ScriptHash& in) : uint160(static_cast<uint160>(in)) {}
2021

2122
ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
23+
ScriptHash::ScriptHash(const CScriptID& in) : uint160(static_cast<uint160>(in)) {}
2224

2325
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
26+
PKHash::PKHash(const CKeyID& pubkey_id) : uint160(pubkey_id) {}
27+
2428
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
29+
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : uint160(static_cast<uint160>(pubkey_hash)) {}
2530

2631
CKeyID ToKeyID(const PKHash& key_hash)
2732
{

src/script/standard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
1818

1919
class CKeyID;
2020
class CScript;
21+
struct ScriptHash;
2122

2223
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
2324
class CScriptID : public uint160
@@ -26,6 +27,7 @@ class CScriptID : public uint160
2627
CScriptID() : uint160() {}
2728
explicit CScriptID(const CScript& in);
2829
explicit CScriptID(const uint160& in) : uint160(in) {}
30+
explicit CScriptID(const ScriptHash& in);
2931
};
3032

3133
/**
@@ -78,6 +80,7 @@ struct PKHash : public uint160
7880
PKHash() : uint160() {}
7981
explicit PKHash(const uint160& hash) : uint160(hash) {}
8082
explicit PKHash(const CPubKey& pubkey);
83+
explicit PKHash(const CKeyID& pubkey_id);
8184
};
8285
CKeyID ToKeyID(const PKHash& key_hash);
8386

@@ -91,6 +94,7 @@ struct ScriptHash : public uint160
9194
explicit ScriptHash(const PKHash& hash) = delete;
9295
explicit ScriptHash(const uint160& hash) : uint160(hash) {}
9396
explicit ScriptHash(const CScript& script);
97+
explicit ScriptHash(const CScriptID& script);
9498
};
9599

96100
struct WitnessV0ScriptHash : public uint256
@@ -105,6 +109,7 @@ struct WitnessV0KeyHash : public uint160
105109
WitnessV0KeyHash() : uint160() {}
106110
explicit WitnessV0KeyHash(const uint160& hash) : uint160(hash) {}
107111
explicit WitnessV0KeyHash(const CPubKey& pubkey);
112+
explicit WitnessV0KeyHash(const PKHash& pubkey_hash);
108113
};
109114
CKeyID ToKeyID(const WitnessV0KeyHash& key_hash);
110115

0 commit comments

Comments
 (0)