From 55a82eaf91d252a04a0cc8ad7d948d956c6cb24f Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 29 Jun 2022 18:13:51 +0200 Subject: [PATCH] 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. --- src/wallet/wallet.cpp | 12 ++++++++++++ src/wallet/wallet.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 475627c76c7..18ca6303122 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3311,6 +3311,18 @@ std::unique_ptr CWallet::GetSolvingProvider(const CScript& scri return nullptr; } +std::vector CWallet::GetWalletDescriptors(const CScript& script) const +{ + std::vector descs; + for (const auto spk_man: GetScriptPubKeyMans(script)) { + if (const auto desc_spk_man = dynamic_cast(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 e2c3d76438f..b08b491ef1a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -839,6 +839,9 @@ public: std::unique_ptr GetSolvingProvider(const CScript& script) const; std::unique_ptr GetSolvingProvider(const CScript& script, SignatureData& sigdata) const; + //! Get the wallet descriptors for a script. + std::vector GetWalletDescriptors(const CScript& script) const; + //! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external. LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const; LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan();