mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 05:54:48 +02:00
wallet: implement IsDestinationActive() and add to rpc getaddressinfo
This connects SPKM.IsKeyActive() up to the wallet level. Github-Pull: #27216 Rebased-From: d33f3bdb84f1823aebe3fd88c4b2ec4df1c1fe3d
This commit is contained in:
parent
0b5e99a074
commit
ec8d084b5f
@ -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);
|
||||
|
@ -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<ScriptPubKeyMan*>& spkms{GetActiveScriptPubKeyMans()};
|
||||
return std::any_of(spkms.cbegin(), spkms.cend(), [&script](const auto& spkm) { return spkm->IsKeyActive(script); });
|
||||
}
|
||||
|
||||
std::vector<CTxDestination> CWallet::ListAddrBookAddresses(const std::optional<AddrBookFilter>& _filter) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
@ -768,6 +768,11 @@ public:
|
||||
using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> 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.
|
||||
|
Loading…
Reference in New Issue
Block a user