mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-24 22:09:20 +02:00
wallet: introduce active db txn listeners
Useful to ensure that the in-memory state is updated only after successfully committing the data to disk.
This commit is contained in:
@@ -1347,12 +1347,34 @@ bool WalletBatch::TxnBegin()
|
||||
|
||||
bool WalletBatch::TxnCommit()
|
||||
{
|
||||
return m_batch->TxnCommit();
|
||||
bool res = m_batch->TxnCommit();
|
||||
if (res) {
|
||||
for (const auto& listener : m_txn_listeners) {
|
||||
listener.on_commit();
|
||||
}
|
||||
// txn finished, clear listeners
|
||||
m_txn_listeners.clear();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool WalletBatch::TxnAbort()
|
||||
{
|
||||
return m_batch->TxnAbort();
|
||||
bool res = m_batch->TxnAbort();
|
||||
if (res) {
|
||||
for (const auto& listener : m_txn_listeners) {
|
||||
listener.on_abort();
|
||||
}
|
||||
// txn finished, clear listeners
|
||||
m_txn_listeners.clear();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void WalletBatch::RegisterTxnListener(const DbTxnListener& l)
|
||||
{
|
||||
assert(m_batch->HasActiveTxn());
|
||||
m_txn_listeners.emplace_back(l);
|
||||
}
|
||||
|
||||
std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error)
|
||||
|
||||
Reference in New Issue
Block a user