Skip to content

Commit 055c053

Browse files
committed
wallet: provide WalletBatch to 'DeleteRecords'
So it can be used within an external db txn context.
1 parent 122d103 commit 055c053

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,15 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
20362036
}
20372037

20382038
bool LegacyDataSPKM::DeleteRecords()
2039+
{
2040+
return RunWithinTxn(m_storage.GetDatabase(), /*process_desc=*/"delete legacy records", [&](WalletBatch& batch){
2041+
return DeleteRecordsWithDB(batch);
2042+
});
2043+
}
2044+
2045+
bool LegacyDataSPKM::DeleteRecordsWithDB(WalletBatch& batch)
20392046
{
20402047
LOCK(cs_KeyStore);
2041-
WalletBatch batch(m_storage.GetDatabase());
20422048
return batch.EraseRecords(DBKeys::LEGACY_TYPES);
20432049
}
20442050

src/wallet/scriptpubkeyman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,9 @@ class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
366366
/** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan.
367367
* Does not modify this ScriptPubKeyMan. */
368368
std::optional<MigrationData> MigrateToDescriptor();
369-
/** Delete all the records ofthis LegacyScriptPubKeyMan from disk*/
369+
/** Delete all the records of this LegacyScriptPubKeyMan from disk*/
370370
bool DeleteRecords();
371+
bool DeleteRecordsWithDB(WalletBatch& batch);
371372
};
372373

373374
// Implements the full legacy wallet behavior

src/wallet/walletdb.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,10 +1335,8 @@ bool WalletBatch::WriteWalletFlags(const uint64_t flags)
13351335

13361336
bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
13371337
{
1338-
return RunWithinTxn(*this, "erase records", [&types](WalletBatch& self) {
1339-
return std::all_of(types.begin(), types.end(), [&self](const std::string& type) {
1340-
return self.m_batch->ErasePrefix(DataStream() << type);
1341-
});
1338+
return std::all_of(types.begin(), types.end(), [&](const std::string& type) {
1339+
return m_batch->ErasePrefix(DataStream() << type);
13421340
});
13431341
}
13441342

0 commit comments

Comments
 (0)