aboutsummaryrefslogtreecommitdiff
path: root/src/addresstype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/addresstype.cpp')
-rw-r--r--src/addresstype.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/addresstype.cpp b/src/addresstype.cpp
index 78df1c13a4..f199d1b479 100644
--- a/src/addresstype.cpp
+++ b/src/addresstype.cpp
@@ -54,11 +54,12 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
switch (whichType) {
case TxoutType::PUBKEY: {
CPubKey pubKey(vSolutions[0]);
- if (!pubKey.IsValid())
- return false;
-
- addressRet = PKHash(pubKey);
- return true;
+ if (!pubKey.IsValid()) {
+ addressRet = CNoDestination(scriptPubKey);
+ } else {
+ addressRet = PubKeyDestination(pubKey);
+ }
+ return false;
}
case TxoutType::PUBKEYHASH: {
addressRet = PKHash(uint160(vSolutions[0]));
@@ -108,6 +109,11 @@ public:
return dest.GetScript();
}
+ CScript operator()(const PubKeyDestination& dest) const
+ {
+ return CScript() << ToByteVector(dest.GetPubKey()) << OP_CHECKSIG;
+ }
+
CScript operator()(const PKHash& keyID) const
{
return CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
@@ -138,6 +144,19 @@ public:
return CScript() << CScript::EncodeOP_N(id.GetWitnessVersion()) << id.GetWitnessProgram();
}
};
+
+class ValidDestinationVisitor
+{
+public:
+ bool operator()(const CNoDestination& dest) const { return false; }
+ bool operator()(const PubKeyDestination& dest) const { return false; }
+ bool operator()(const PKHash& dest) const { return true; }
+ bool operator()(const ScriptHash& dest) const { return true; }
+ bool operator()(const WitnessV0KeyHash& dest) const { return true; }
+ bool operator()(const WitnessV0ScriptHash& dest) const { return true; }
+ bool operator()(const WitnessV1Taproot& dest) const { return true; }
+ bool operator()(const WitnessUnknown& dest) const { return true; }
+};
} // namespace
CScript GetScriptForDestination(const CTxDestination& dest)
@@ -146,5 +165,5 @@ CScript GetScriptForDestination(const CTxDestination& dest)
}
bool IsValidDestination(const CTxDestination& dest) {
- return dest.index() != 0;
+ return std::visit(ValidDestinationVisitor(), dest);
}