@@ -52,6 +52,7 @@ const std::string TX{"tx"};
5252const std::string VERSION{" version" };
5353const std::string WALLETDESCRIPTOR{" walletdescriptor" };
5454const std::string WALLETDESCRIPTORCACHE{" walletdescriptorcache" };
55+ const std::string WALLETDESCRIPTORLHCACHE{" walletdescriptorlhcache" };
5556const std::string WALLETDESCRIPTORCKEY{" walletdescriptorckey" };
5657const std::string WALLETDESCRIPTORKEY{" walletdescriptorkey" };
5758const std::string WATCHMETA{" watchmeta" };
@@ -248,6 +249,13 @@ bool WalletBatch::WriteDescriptorParentCache(const CExtPubKey& xpub, const uint2
248249 return WriteIC (std::make_pair (std::make_pair (DBKeys::WALLETDESCRIPTORCACHE, desc_id), key_exp_index), ser_xpub);
249250}
250251
252+ bool WalletBatch::WriteDescriptorLastHardenedCache (const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index)
253+ {
254+ std::vector<unsigned char > ser_xpub (BIP32_EXTKEY_SIZE);
255+ xpub.Encode (ser_xpub.data ());
256+ return WriteIC (std::make_pair (std::make_pair (DBKeys::WALLETDESCRIPTORLHCACHE, desc_id), key_exp_index), ser_xpub);
257+ }
258+
251259bool WalletBatch::WriteDescriptorCacheItems (const uint256& desc_id, const DescriptorCache& cache)
252260{
253261 for (const auto & parent_xpub_pair : cache.GetCachedParentExtPubKeys ()) {
@@ -262,6 +270,11 @@ bool WalletBatch::WriteDescriptorCacheItems(const uint256& desc_id, const Descri
262270 }
263271 }
264272 }
273+ for (const auto & lh_xpub_pair : cache.GetCachedLastHardenedExtPubKeys ()) {
274+ if (!WriteDescriptorLastHardenedCache (lh_xpub_pair.second , desc_id, lh_xpub_pair.first )) {
275+ return false ;
276+ }
277+ }
265278 return true ;
266279}
267280
@@ -619,6 +632,17 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
619632 } else {
620633 wss.m_descriptor_caches [desc_id].CacheDerivedExtPubKey (key_exp_index, der_index, xpub);
621634 }
635+ } else if (strType == DBKeys::WALLETDESCRIPTORLHCACHE) {
636+ uint256 desc_id;
637+ uint32_t key_exp_index;
638+ ssKey >> desc_id;
639+ ssKey >> key_exp_index;
640+
641+ std::vector<unsigned char > ser_xpub (BIP32_EXTKEY_SIZE);
642+ ssValue >> ser_xpub;
643+ CExtPubKey xpub;
644+ xpub.Decode (ser_xpub.data ());
645+ wss.m_descriptor_caches [desc_id].CacheLastHardenedExtPubKey (key_exp_index, xpub);
622646 } else if (strType == DBKeys::WALLETDESCRIPTORKEY) {
623647 uint256 desc_id;
624648 CPubKey pubkey;
0 commit comments