Move DescriptorCache writing to WalletBatch

Instead of adhoc writing of the items in DescriptorCache, move it all
into WalletBatch.
This commit is contained in:
Andrew Chow
2021-04-22 13:24:02 -04:00
parent 0b4c8ef75c
commit cacc391098
3 changed files with 20 additions and 11 deletions

View File

@@ -1807,17 +1807,8 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
}
// Merge and write the cache
DescriptorCache new_items = m_wallet_descriptor.cache.MergeAndDiff(temp_cache);
for (const auto& parent_xpub_pair : new_items.GetCachedParentExtPubKeys()) {
if (!batch.WriteDescriptorParentCache(parent_xpub_pair.second, id, parent_xpub_pair.first)) {
throw std::runtime_error(std::string(__func__) + ": writing cache item failed");
}
}
for (const auto& derived_xpub_map_pair : new_items.GetCachedDerivedExtPubKeys()) {
for (const auto& derived_xpub_pair : derived_xpub_map_pair.second) {
if (!batch.WriteDescriptorDerivedCache(derived_xpub_pair.second, id, derived_xpub_map_pair.first, derived_xpub_pair.first)) {
throw std::runtime_error(std::string(__func__) + ": writing cache item failed");
}
}
if (!batch.WriteDescriptorCacheItems(id, new_items)) {
throw std::runtime_error(std::string(__func__) + ": writing cache items failed");
}
m_max_cached_index++;
}