mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
wallet: Upgrade existing descriptor caches
Add functions to upgrade existing descriptor caches to support the use of last hardened xpub caching.
This commit is contained in:
@@ -2278,3 +2278,32 @@ bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv)
|
||||
|
||||
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, priv);
|
||||
}
|
||||
|
||||
void DescriptorScriptPubKeyMan::UpgradeDescriptorCache()
|
||||
{
|
||||
LOCK(cs_desc_man);
|
||||
if (m_storage.IsLocked() || m_storage.IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if we have the last hardened xpub cache
|
||||
if (m_wallet_descriptor.cache.GetCachedLastHardenedExtPubKeys().size() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Expand the descriptor
|
||||
FlatSigningProvider provider;
|
||||
provider.keys = GetKeys();
|
||||
FlatSigningProvider out_keys;
|
||||
std::vector<CScript> scripts_temp;
|
||||
DescriptorCache temp_cache;
|
||||
if (!m_wallet_descriptor.descriptor->Expand(0, provider, scripts_temp, out_keys, &temp_cache)){
|
||||
throw std::runtime_error("Unable to expand descriptor");
|
||||
}
|
||||
|
||||
// Cache the last hardened xpubs
|
||||
DescriptorCache diff = m_wallet_descriptor.cache.MergeAndDiff(temp_cache);
|
||||
if (!WalletBatch(m_storage.GetDatabase()).WriteDescriptorCacheItems(GetID(), diff)) {
|
||||
throw std::runtime_error(std::string(__func__) + ": writing cache items failed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user