diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index acaa2d8b15..cf35a7331b 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -508,6 +508,7 @@ RPCHelpMan getaddressinfo() {RPCResult::Type::STR, "address", "The bitcoin address validated."}, {RPCResult::Type::STR_HEX, "scriptPubKey", "The hex-encoded scriptPubKey generated by the address."}, {RPCResult::Type::BOOL, "ismine", "If the address is yours."}, + {RPCResult::Type::BOOL, "isactive", "If the key is in the active keypool (always equal to \"ismine\" in descriptor wallets)."}, {RPCResult::Type::BOOL, "iswatchonly", "If the address is watchonly."}, {RPCResult::Type::BOOL, "solvable", "If we know how to spend coins sent to this address, ignoring the possible lack of private keys."}, {RPCResult::Type::STR, "desc", /*optional=*/true, "A descriptor for spending coins sent to this address (only when solvable)."}, @@ -578,6 +579,7 @@ RPCHelpMan getaddressinfo() isminetype mine = pwallet->IsMine(dest); ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE)); + ret.pushKV("isactive", pwallet->IsDestinationActive(dest)); if (provider) { auto inferred = InferDescriptor(scriptPubKey, *provider); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3ac09430d8..bc180f1fc5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2568,6 +2568,13 @@ void CWallet::ForEachAddrBookEntry(const ListAddrBookFunc& func) const } } +bool CWallet::IsDestinationActive(const CTxDestination& dest) const +{ + const CScript& script{GetScriptForDestination(dest)}; + const std::set& spkms{GetActiveScriptPubKeyMans()}; + return std::any_of(spkms.cbegin(), spkms.cend(), [&script](const auto& spkm) { return spkm->IsKeyActive(script); }); +} + std::vector CWallet::ListAddrBookAddresses(const std::optional& _filter) const { AssertLockHeld(cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8b0ee22276..77516540b7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -768,6 +768,11 @@ public: using ListAddrBookFunc = std::function purpose)>; void ForEachAddrBookEntry(const ListAddrBookFunc& func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + /** + * Determines if a destination is in the active spkm (not imported and not dumped for a new keypool) + */ + [[nodiscard]] bool IsDestinationActive(const CTxDestination& dest) const; + /** * Marks all outputs in each one of the destinations dirty, so their cache is * reset and does not return outdated information.