diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2022-06-29 18:13:51 +0200 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2022-07-15 12:12:25 +0200 |
commit | 55a82eaf91d252a04a0cc8ad7d948d956c6cb24f (patch) | |
tree | 8beef8c9029517c07249c5a9da756d1167974c40 | |
parent | 85b601e04363664eae1b4b802cd8dde942761939 (diff) |
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.
-rw-r--r-- | src/wallet/wallet.cpp | 12 | ||||
-rw-r--r-- | src/wallet/wallet.h | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 475627c76c..18ca630312 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3311,6 +3311,18 @@ std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& scri return nullptr; } +std::vector<WalletDescriptor> CWallet::GetWalletDescriptors(const CScript& script) const +{ + std::vector<WalletDescriptor> descs; + for (const auto spk_man: GetScriptPubKeyMans(script)) { + if (const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man)) { + LOCK(desc_spk_man->cs_desc_man); + descs.push_back(desc_spk_man->GetWalletDescriptor()); + } + } + return descs; +} + LegacyScriptPubKeyMan* CWallet::GetLegacyScriptPubKeyMan() const { if (IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index e2c3d76438..b08b491ef1 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -839,6 +839,9 @@ public: std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const; std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const; + //! Get the wallet descriptors for a script. + std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const; + //! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external. LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const; LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan(); |