@@ -2135,6 +2135,15 @@ std::map<CKeyID, CKey> DescriptorScriptPubKeyMan::GetKeys() const
2135
2135
}
2136
2136
2137
2137
bool 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)
2138
2147
{
2139
2148
LOCK (cs_desc_man);
2140
2149
unsigned int target_size;
@@ -2157,7 +2166,6 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
2157
2166
FlatSigningProvider provider;
2158
2167
provider.keys = GetKeys ();
2159
2168
2160
- WalletBatch batch (m_storage.GetDatabase ());
2161
2169
uint256 id = GetID ();
2162
2170
for (int32_t i = m_max_cached_index + 1 ; i < new_range_end; ++i) {
2163
2171
FlatSigningProvider out_keys;
@@ -2326,6 +2334,8 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
2326
2334
2327
2335
// Store the master private key, and descriptor
2328
2336
WalletBatch batch (m_storage.GetDatabase ());
2337
+ if (!batch.TxnBegin ()) throw std::runtime_error (std::string (__func__) + " : cannot start db transaction" );
2338
+
2329
2339
if (!AddDescriptorKeyWithDB (batch, master_key.key , master_key.key .GetPubKey ())) {
2330
2340
throw std::runtime_error (std::string (__func__) + " : writing descriptor master private key failed" );
2331
2341
}
@@ -2334,9 +2344,11 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
2334
2344
}
2335
2345
2336
2346
// TopUp
2337
- TopUp ( );
2347
+ TopUpWithDB (batch );
2338
2348
2339
2349
m_storage.UnsetBlankWalletFlag (batch);
2350
+
2351
+ if (!batch.TxnCommit ()) throw std::runtime_error (std::string (__func__) + " : error committing db transaction" );
2340
2352
return true ;
2341
2353
}
2342
2354
0 commit comments