@@ -2135,6 +2135,15 @@ std::map<CKeyID, CKey> DescriptorScriptPubKeyMan::GetKeys() const
21352135}
21362136
21372137bool DescriptorScriptPubKeyMan::TopUp (unsigned int size)
2138+ {
2139+ WalletBatch batch (m_storage.GetDatabase ());
2140+ if (!batch.TxnBegin ()) return false ;
2141+ bool res = TopUpWithDB (batch, size);
2142+ if (!batch.TxnCommit ()) throw std::runtime_error (strprintf (" Error during descriptors keypool top up. Cannot commit changes for wallet %s" , m_storage.GetDisplayName ()));
2143+ return res;
2144+ }
2145+
2146+ bool DescriptorScriptPubKeyMan::TopUpWithDB (WalletBatch& batch, unsigned int size)
21382147{
21392148 LOCK (cs_desc_man);
21402149 unsigned int target_size;
@@ -2157,7 +2166,6 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
21572166 FlatSigningProvider provider;
21582167 provider.keys = GetKeys ();
21592168
2160- WalletBatch batch (m_storage.GetDatabase ());
21612169 uint256 id = GetID ();
21622170 for (int32_t i = m_max_cached_index + 1 ; i < new_range_end; ++i) {
21632171 FlatSigningProvider out_keys;
@@ -2326,6 +2334,8 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
23262334
23272335 // Store the master private key, and descriptor
23282336 WalletBatch batch (m_storage.GetDatabase ());
2337+ if (!batch.TxnBegin ()) throw std::runtime_error (std::string (__func__) + " : cannot start db transaction" );
2338+
23292339 if (!AddDescriptorKeyWithDB (batch, master_key.key , master_key.key .GetPubKey ())) {
23302340 throw std::runtime_error (std::string (__func__) + " : writing descriptor master private key failed" );
23312341 }
@@ -2334,9 +2344,11 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
23342344 }
23352345
23362346 // TopUp
2337- TopUp ( );
2347+ TopUpWithDB (batch );
23382348
23392349 m_storage.UnsetBlankWalletFlag (batch);
2350+
2351+ if (!batch.TxnCommit ()) throw std::runtime_error (std::string (__func__) + " : error committing db transaction" );
23402352 return true ;
23412353}
23422354
0 commit comments