wallet, export: Include descriptor cache when exporting descriptors

This commit is contained in:
Ava Chow
2026-07-08 13:39:55 -07:00
parent 9fc7b2618b
commit 1113f7590e
2 changed files with 6 additions and 5 deletions

View File

@@ -37,7 +37,8 @@ util::Expected<std::vector<WalletDescInfo>, 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<std::string> 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<DescriptorScriptPubKeyMan*>(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

View File

@@ -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<bool> internal;
std::optional<std::pair<int64_t,int64_t>> range;
int64_t next_index;
DescriptorCache cache;
};
//! Export the descriptors from a wallet so that they can be imported elsewhere