mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
wallet: Expose transactional interface for db
This commit is contained in:
parent
5396335363
commit
19a4e7f542
2 changed files with 25 additions and 19 deletions
22
wallet/db.c
22
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;");
|
||||
|
|
22
wallet/db.h
22
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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue