aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/walletdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r--src/wallet/walletdb.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 072357022e..9a6c5afba6 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -1136,6 +1136,9 @@ bool WalletBatch::WriteWalletFlags(const uint64_t flags)
bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
{
+ // Begin db txn
+ if (!m_batch->TxnBegin()) return false;
+
// Get cursor
std::unique_ptr<DatabaseCursor> cursor = m_batch->GetNewCursor();
if (!cursor)
@@ -1144,8 +1147,7 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
}
// Iterate the DB and look for any records that have the type prefixes
- while (true)
- {
+ while (true) {
// Read next record
DataStream key{};
DataStream value{};
@@ -1153,6 +1155,8 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
if (status == DatabaseCursor::Status::DONE) {
break;
} else if (status == DatabaseCursor::Status::FAIL) {
+ cursor.reset(nullptr);
+ m_batch->TxnAbort(); // abort db txn
return false;
}
@@ -1163,10 +1167,16 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
key >> type;
if (types.count(type) > 0) {
- m_batch->Erase(key_data);
+ if (!m_batch->Erase(key_data)) {
+ cursor.reset(nullptr);
+ m_batch->TxnAbort();
+ return false; // erase failed
+ }
}
}
- return true;
+ // Finish db txn
+ cursor.reset(nullptr);
+ return m_batch->TxnCommit();
}
bool WalletBatch::TxnBegin()