aboutsummaryrefslogtreecommitdiff
path: root/src/addresstype.cpp
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-08-09 09:46:25 -0400
committerAndrew Chow <github@achow101.com>2023-09-12 12:14:31 -0400
commit07d3bdf4ebc06825ea24ab6f7c87aef6a22238c6 (patch)
tree11a23667794fcd9b4052230f9cfac00e9cb6b00d /src/addresstype.cpp
parent1a98a51c666e9ae77364115775ec2e0ba984e8e0 (diff)
downloadbitcoin-07d3bdf4ebc06825ea24ab6f7c87aef6a22238c6.tar.xz
Add PubKeyDestination for P2PK scripts
P2PK scripts are not PKHash destinations, they should have their own type. This also results in no longer showing a p2pkh address for p2pk outputs. However for backwards compatibility, ListCoinst will still do this conversion.
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);
}