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

@@ -248,6 +248,23 @@ bool WalletBatch::WriteDescriptorParentCache(const CExtPubKey& xpub, const uint2
return WriteIC(std::make_pair(std::make_pair(DBKeys::WALLETDESCRIPTORCACHE, desc_id), key_exp_index), ser_xpub);
}
bool WalletBatch::WriteDescriptorCacheItems(const uint256& desc_id, const DescriptorCache& cache)
{
for (const auto& parent_xpub_pair : cache.GetCachedParentExtPubKeys()) {
if (!WriteDescriptorParentCache(parent_xpub_pair.second, desc_id, parent_xpub_pair.first)) {
return false;
}
}
for (const auto& derived_xpub_map_pair : cache.GetCachedDerivedExtPubKeys()) {
for (const auto& derived_xpub_pair : derived_xpub_map_pair.second) {
if (!WriteDescriptorDerivedCache(derived_xpub_pair.second, desc_id, derived_xpub_map_pair.first, derived_xpub_pair.first)) {
return false;
}
}
}
return true;
}
class CWalletScanState {
public:
unsigned int nKeys{0};