diff --git a/src/wallet/export.cpp b/src/wallet/export.cpp index 9f9a9486db8..fb6bdf5a307 100644 --- a/src/wallet/export.cpp +++ b/src/wallet/export.cpp @@ -37,7 +37,8 @@ util::Expected, std::string> ExportDescriptors(const wallet.IsActiveScriptPubKeyMan(*desc_spk_man), wallet.IsInternalScriptPubKeyMan(desc_spk_man), is_range ? std::optional(std::make_pair(wallet_descriptor.GetStart(), wallet_descriptor.GetEnd())) : std::nullopt, - wallet_descriptor.GetNext() + wallet_descriptor.GetNext(), + wallet_descriptor.cache ); } return wallet_descriptors; @@ -105,11 +106,10 @@ util::Result ExportWatchOnlyWallet(const CWallet& wallet, const fs: WalletDescriptor w_desc(std::move(descs.at(0)), desc_info.creation_time, range_start, range_end, desc_info.next_index); - // For descriptors that cannot self expand (i.e. needs private keys or cache), retrieve the cache + // For descriptors that cannot self expand (i.e. needs private keys or cache), set the cache uint256 desc_id = w_desc.id; if (!w_desc.descriptor->CanSelfExpand()) { - DescriptorScriptPubKeyMan* desc_spkm = dynamic_cast(wallet.GetScriptPubKeyMan(desc_id)); - w_desc.cache = WITH_LOCK(desc_spkm->cs_desc_man, return desc_spkm->GetWalletDescriptor().cache); + w_desc.cache = desc_info.cache; } // Add to the watchonly wallet diff --git a/src/wallet/export.h b/src/wallet/export.h index 5f2289302cc..509336676ab 100644 --- a/src/wallet/export.h +++ b/src/wallet/export.h @@ -14,7 +14,7 @@ namespace wallet { // Struct containing all of the info from WalletDescriptor, except with the descriptor as a string, -// and without its ID or cache. +// and without its ID. // Used when exporting descriptors from the wallet. struct WalletDescInfo { std::string descriptor; @@ -23,6 +23,7 @@ struct WalletDescInfo { std::optional internal; std::optional> range; int64_t next_index; + DescriptorCache cache; }; //! Export the descriptors from a wallet so that they can be imported elsewhere