mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Replace CScriptID and CKeyID in CTxDestination with dedicated type
This commit is contained in:
parent
3e7cff1e45
commit
aa375e66c1
28 changed files with 201 additions and 179 deletions
|
|
@ -228,7 +228,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
CScript P2PKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(pubkey.GetID()); }
|
||||
CScript P2PKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(PKHash(pubkey)); }
|
||||
CScript P2PKGetScript(const CPubKey& pubkey) { return GetScriptForRawPubKey(pubkey); }
|
||||
CScript P2WPKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(WitnessV0KeyHash(pubkey.GetID())); }
|
||||
|
||||
|
|
@ -320,7 +320,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
CScript ConvertP2SH(const CScript& script) { return GetScriptForDestination(CScriptID(script)); }
|
||||
CScript ConvertP2SH(const CScript& script) { return GetScriptForDestination(ScriptHash(script)); }
|
||||
CScript ConvertP2WSH(const CScript& script) { return GetScriptForDestination(WitnessV0ScriptHash(script)); }
|
||||
|
||||
/** A parsed combo(P) descriptor. */
|
||||
|
|
@ -347,14 +347,14 @@ public:
|
|||
CKeyID keyid = key.GetID();
|
||||
{
|
||||
CScript p2pk = GetScriptForRawPubKey(key);
|
||||
CScript p2pkh = GetScriptForDestination(keyid);
|
||||
CScript p2pkh = GetScriptForDestination(PKHash(keyid));
|
||||
output_scripts = std::vector<CScript>{std::move(p2pk), std::move(p2pkh)};
|
||||
out.pubkeys.emplace(keyid, key);
|
||||
}
|
||||
if (key.IsCompressed()) {
|
||||
CScript p2wpkh = GetScriptForDestination(WitnessV0KeyHash(keyid));
|
||||
CScriptID p2wpkh_id(p2wpkh);
|
||||
CScript p2sh_p2wpkh = GetScriptForDestination(p2wpkh_id);
|
||||
CScript p2sh_p2wpkh = GetScriptForDestination(ScriptHash(p2wpkh_id));
|
||||
out.scripts.emplace(p2wpkh_id, p2wpkh);
|
||||
output_scripts.push_back(std::move(p2wpkh));
|
||||
output_scripts.push_back(std::move(p2sh_p2wpkh));
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ IsMineResult IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey,
|
|||
// This also applies to the P2WSH case.
|
||||
break;
|
||||
}
|
||||
ret = std::max(ret, IsMineInner(keystore, GetScriptForDestination(CKeyID(uint160(vSolutions[0]))), IsMineSigVersion::WITNESS_V0));
|
||||
ret = std::max(ret, IsMineInner(keystore, GetScriptForDestination(PKHash(uint160(vSolutions[0]))), IsMineSigVersion::WITNESS_V0));
|
||||
break;
|
||||
}
|
||||
case TX_PUBKEYHASH:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,22 @@ public:
|
|||
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
|
||||
};
|
||||
|
||||
struct PKHash : public uint160
|
||||
{
|
||||
PKHash() : uint160() {}
|
||||
explicit PKHash(const uint160& hash) : uint160(hash) {}
|
||||
explicit PKHash(const CPubKey& pubkey);
|
||||
using uint160::uint160;
|
||||
};
|
||||
|
||||
struct ScriptHash : public uint160
|
||||
{
|
||||
ScriptHash() : uint160() {}
|
||||
explicit ScriptHash(const uint160& hash) : uint160(hash) {}
|
||||
explicit ScriptHash(const CScript& script);
|
||||
using uint160::uint160;
|
||||
};
|
||||
|
||||
struct WitnessV0ScriptHash : public uint256
|
||||
{
|
||||
WitnessV0ScriptHash() : uint256() {}
|
||||
|
|
@ -129,15 +145,15 @@ public:
|
|||
/**
|
||||
* A txout script template with a specific destination. It is either:
|
||||
* * CNoDestination: no destination set
|
||||
* * CKeyID: TX_PUBKEYHASH destination (P2PKH)
|
||||
* * CScriptID: TX_SCRIPTHASH destination (P2SH)
|
||||
* * PKHash: TX_PUBKEYHASH destination (P2PKH)
|
||||
* * ScriptHash: TX_SCRIPTHASH destination (P2SH)
|
||||
* * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH)
|
||||
* * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH)
|
||||
* * WitnessUnknown: TX_WITNESS_UNKNOWN destination (P2W???)
|
||||
* * NullData: TX_NULL_DATA destination (OP_RETURN)
|
||||
* A CTxDestination is the internal data type encoded in a bitcoin address
|
||||
*/
|
||||
typedef boost::variant<CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown, NullData> CTxDestination;
|
||||
typedef boost::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown, NullData> CTxDestination;
|
||||
|
||||
/** Check whether a CTxDestination is a CNoDestination. */
|
||||
bool IsValidDestination(const CTxDestination& dest);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue