diff options
author | Andrew Chow <github@achow101.com> | 2023-08-09 09:46:25 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-09-12 12:14:31 -0400 |
commit | 07d3bdf4ebc06825ea24ab6f7c87aef6a22238c6 (patch) | |
tree | 11a23667794fcd9b4052230f9cfac00e9cb6b00d /src/wallet | |
parent | 1a98a51c666e9ae77364115775ec2e0ba984e8e0 (diff) |
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/wallet')
-rw-r--r-- | src/wallet/rpc/addresses.cpp | 1 | ||||
-rw-r--r-- | src/wallet/spend.cpp | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index c1b99a4f97..e9b93afc30 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -427,6 +427,7 @@ public: explicit DescribeWalletAddressVisitor(const SigningProvider* _provider) : provider(_provider) {} UniValue operator()(const CNoDestination& dest) const { return UniValue(UniValue::VOBJ); } + UniValue operator()(const PubKeyDestination& dest) const { return UniValue(UniValue::VOBJ); } UniValue operator()(const PKHash& pkhash) const { diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 750b6c100b..5d2c299a69 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -490,8 +490,15 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet) coins_params.skip_locked = false; for (const COutput& coin : AvailableCoins(wallet, &coin_control, /*feerate=*/std::nullopt, coins_params).All()) { CTxDestination address; - if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable)) && - ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) { + if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable))) { + if (!ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) { + // For backwards compatibility, we convert P2PK output scripts into PKHash destinations + if (auto pk_dest = std::get_if<PubKeyDestination>(&address)) { + address = PKHash(pk_dest->GetPubKey()); + } else { + continue; + } + } result[address].emplace_back(coin); } } |