From 19a4e7f5428ef066c282c7e059b9bbbd4f399c80 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 31 May 2017 15:50:36 +0200 Subject: [PATCH] wallet: Expose transactional interface for db --- wallet/db.c | 22 +++------------------- wallet/db.h | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index 771cafdfd..81b3c0314 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -87,14 +87,7 @@ static void db_clear_error(struct db *db) static void close_db(struct db *db) { sqlite3_close(db->sql); } -/** - * db_begin_transaction - Begin a transaction - * - * We do not support nesting multiple transactions, so make sure that - * we are not in a transaction when calling this. Returns true if we - * succeeded in starting a transaction. - */ -static bool db_begin_transaction(struct db *db) +bool db_begin_transaction(struct db *db) { assert(!db->in_transaction); /* Clear any errors from previous transactions and @@ -104,13 +97,7 @@ static bool db_begin_transaction(struct db *db) return db->in_transaction; } -/** - * db_commit_transaction - Commit a running transaction - * - * Requires that we are currently in a transaction. Returns whether - * the commit was successful. - */ -static bool db_commit_transaction(struct db *db) +bool db_commit_transaction(struct db *db) { assert(db->in_transaction); bool ret = db_exec(__func__, db, "COMMIT;"); @@ -118,10 +105,7 @@ static bool db_commit_transaction(struct db *db) return ret; } -/** - * db_rollback_transaction - Whoops... undo! undo! - */ -static bool db_rollback_transaction(struct db *db) +bool db_rollback_transaction(struct db *db) { assert(db->in_transaction); bool ret = db_exec(__func__, db, "ROLLBACK;"); diff --git a/wallet/db.h b/wallet/db.h index 98d9e7355..d0e01d6dd 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -35,4 +35,26 @@ sqlite3_stmt *PRINTF_FMT(3, 4) bool PRINTF_FMT(3, 4) db_exec(const char *caller, struct db *db, const char *fmt, ...); +/** + * db_begin_transaction - Begin a transaction + * + * We do not support nesting multiple transactions, so make sure that + * we are not in a transaction when calling this. Returns true if we + * succeeded in starting a transaction. + */ +bool db_begin_transaction(struct db *db); + +/** + * db_commit_transaction - Commit a running transaction + * + * Requires that we are currently in a transaction. Returns whether + * the commit was successful. + */ +bool db_commit_transaction(struct db *db); + +/** + * db_rollback_transaction - Whoops... undo! undo! + */ +bool db_rollback_transaction(struct db *db); + #endif /* WALLET_DB_H */