Skip to content

Commit 55a82ea

Browse files
committed
wallet: allow to fetch the wallet descriptors for a given Script
We currently expose a method to get the signing providers, which allows to infer a descriptor from the scriptPubKey. But in order to identify "on" what descriptor a coin was received, we need access to the descriptors that were imported to the wallet.
1 parent 85b601e commit 55a82ea

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,18 @@ std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& scri
33113311
return nullptr;
33123312
}
33133313

3314+
std::vector<WalletDescriptor> CWallet::GetWalletDescriptors(const CScript& script) const
3315+
{
3316+
std::vector<WalletDescriptor> descs;
3317+
for (const auto spk_man: GetScriptPubKeyMans(script)) {
3318+
if (const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man)) {
3319+
LOCK(desc_spk_man->cs_desc_man);
3320+
descs.push_back(desc_spk_man->GetWalletDescriptor());
3321+
}
3322+
}
3323+
return descs;
3324+
}
3325+
33143326
LegacyScriptPubKeyMan* CWallet::GetLegacyScriptPubKeyMan() const
33153327
{
33163328
if (IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
839839
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
840840
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
841841

842+
//! Get the wallet descriptors for a script.
843+
std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const;
844+
842845
//! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
843846
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;
844847
LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan();

0 commit comments

Comments
 (0)