Skip to content

Commit 363f4bf

Browse files
pinheadmzluke-jr
authored andcommitted
wallet: implement IsDestinationActive() and add to rpc getaddressinfo
This connects SPKM.IsKeyActive() up to the wallet level. Github-Pull: bitcoin#27216 Rebased-From: d33f3bd
1 parent 3b8691b commit 363f4bf

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/wallet/rpc/addresses.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ RPCHelpMan getaddressinfo()
531531
{RPCResult::Type::STR, "address", "The bitcoin address validated."},
532532
{RPCResult::Type::STR_HEX, "scriptPubKey", "The hex-encoded output script generated by the address."},
533533
{RPCResult::Type::BOOL, "ismine", "If the address is yours."},
534+
{RPCResult::Type::BOOL, "isactive", "If the key is in the active keypool (always equal to \"ismine\" in descriptor wallets)."},
534535
{RPCResult::Type::BOOL, "iswatchonly", "If the address is watchonly."},
535536
{RPCResult::Type::BOOL, "solvable", "If we know how to spend coins sent to this address, ignoring the possible lack of private keys."},
536537
{RPCResult::Type::STR, "desc", /*optional=*/true, "A descriptor for spending coins sent to this address (only when solvable)."},
@@ -601,6 +602,7 @@ RPCHelpMan getaddressinfo()
601602

602603
isminetype mine = pwallet->IsMine(dest);
603604
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
605+
ret.pushKV("isactive", pwallet->IsDestinationActive(dest));
604606

605607
if (provider) {
606608
auto inferred = InferDescriptor(scriptPubKey, *provider);

src/wallet/wallet.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,13 @@ void CWallet::ForEachAddrBookEntry(const ListAddrBookFunc& func) const
26162616
}
26172617
}
26182618

2619+
bool CWallet::IsDestinationActive(const CTxDestination& dest) const
2620+
{
2621+
const CScript& script{GetScriptForDestination(dest)};
2622+
const std::set<ScriptPubKeyMan*>& spkms{GetActiveScriptPubKeyMans()};
2623+
return std::any_of(spkms.cbegin(), spkms.cend(), [&script](const auto& spkm) { return spkm->IsKeyActive(script); });
2624+
}
2625+
26192626
std::vector<CTxDestination> CWallet::ListAddrBookAddresses(const std::optional<AddrBookFilter>& _filter) const
26202627
{
26212628
AssertLockHeld(cs_wallet);

src/wallet/wallet.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,11 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
763763
using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>;
764764
void ForEachAddrBookEntry(const ListAddrBookFunc& func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
765765

766+
/**
767+
* Determines if a destination is in the active spkm (not imported and not dumped for a new keypool)
768+
*/
769+
[[nodiscard]] bool IsDestinationActive(const CTxDestination& dest) const;
770+
766771
/**
767772
* Marks all outputs in each one of the destinations dirty, so their cache is
768773
* reset and does not return outdated information.

0 commit comments

Comments
 (0)