Explicitly support conversion between equivalent hash types
ScriptHash <-> CScriptID CKeyID -> PKHash PKHash -> WitnessV0KeyHash
This commit is contained in:
parent
f32c1e07fd
commit
966a22d859
2 changed files with 10 additions and 0 deletions
|
@ -17,11 +17,16 @@ bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER;
|
|||
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
|
||||
|
||||
CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
|
||||
CScriptID::CScriptID(const ScriptHash& in) : uint160(static_cast<uint160>(in)) {}
|
||||
|
||||
ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
|
||||
ScriptHash::ScriptHash(const CScriptID& in) : uint160(static_cast<uint160>(in)) {}
|
||||
|
||||
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
|
||||
PKHash::PKHash(const CKeyID& pubkey_id) : uint160(pubkey_id) {}
|
||||
|
||||
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
|
||||
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : uint160(static_cast<uint160>(pubkey_hash)) {}
|
||||
|
||||
CKeyID ToKeyID(const PKHash& key_hash)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
|
|||
|
||||
class CKeyID;
|
||||
class CScript;
|
||||
struct ScriptHash;
|
||||
|
||||
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
|
||||
class CScriptID : public uint160
|
||||
|
@ -26,6 +27,7 @@ public:
|
|||
CScriptID() : uint160() {}
|
||||
explicit CScriptID(const CScript& in);
|
||||
explicit CScriptID(const uint160& in) : uint160(in) {}
|
||||
explicit CScriptID(const ScriptHash& in);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -78,6 +80,7 @@ struct PKHash : public uint160
|
|||
PKHash() : uint160() {}
|
||||
explicit PKHash(const uint160& hash) : uint160(hash) {}
|
||||
explicit PKHash(const CPubKey& pubkey);
|
||||
explicit PKHash(const CKeyID& pubkey_id);
|
||||
};
|
||||
CKeyID ToKeyID(const PKHash& key_hash);
|
||||
|
||||
|
@ -91,6 +94,7 @@ struct ScriptHash : public uint160
|
|||
explicit ScriptHash(const PKHash& hash) = delete;
|
||||
explicit ScriptHash(const uint160& hash) : uint160(hash) {}
|
||||
explicit ScriptHash(const CScript& script);
|
||||
explicit ScriptHash(const CScriptID& script);
|
||||
};
|
||||
|
||||
struct WitnessV0ScriptHash : public uint256
|
||||
|
@ -105,6 +109,7 @@ struct WitnessV0KeyHash : public uint160
|
|||
WitnessV0KeyHash() : uint160() {}
|
||||
explicit WitnessV0KeyHash(const uint160& hash) : uint160(hash) {}
|
||||
explicit WitnessV0KeyHash(const CPubKey& pubkey);
|
||||
explicit WitnessV0KeyHash(const PKHash& pubkey_hash);
|
||||
};
|
||||
CKeyID ToKeyID(const WitnessV0KeyHash& key_hash);
|
||||
|
||||
|
|
Loading…
Reference in a new issue