Replace CScriptID and CKeyID in CTxDestination with dedicated type

This commit is contained in:
Gregory Sanders 2019-02-19 17:00:45 -05:00 committed by Steven Roose
parent 3e7cff1e45
commit aa375e66c1
No known key found for this signature in database
GPG key ID: 7FC91380BB4CE800
28 changed files with 201 additions and 179 deletions

View file

@ -21,6 +21,10 @@ unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
{
CSHA256().Write(in.data(), in.size()).Finalize(begin());
@ -174,17 +178,17 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
if (!pubKey.IsValid())
return false;
addressRet = pubKey.GetID();
addressRet = PKHash(pubKey);
return true;
}
else if (whichType == TX_PUBKEYHASH)
{
addressRet = CKeyID(uint160(vSolutions[0]));
addressRet = PKHash(uint160(vSolutions[0]));
return true;
}
else if (whichType == TX_SCRIPTHASH)
{
addressRet = CScriptID(uint160(vSolutions[0]));
addressRet = ScriptHash(uint160(vSolutions[0]));
return true;
} else if (whichType == TX_WITNESS_V0_KEYHASH) {
WitnessV0KeyHash hash;
@ -229,7 +233,7 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::
if (!pubKey.IsValid())
continue;
CTxDestination address = pubKey.GetID();
CTxDestination address = PKHash(pubKey);
addressRet.push_back(address);
}
@ -262,13 +266,13 @@ public:
return false;
}
bool operator()(const CKeyID &keyID) const {
bool operator()(const PKHash &keyID) const {
script->clear();
*script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
return true;
}
bool operator()(const CScriptID &scriptID) const {
bool operator()(const ScriptHash &scriptID) const {
script->clear();
*script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
return true;