db: add generic warn/error function.

This avoids the mess where we override db_fatal for teqsts, and keeps it
generic.

Also allows us to get rid of one #if DEVELOPER, and an ugly global for
bookkeeper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-06-30 04:53:08 +09:30
parent bef137209d
commit 04f485aee0
15 changed files with 149 additions and 209 deletions

View File

@@ -85,7 +85,15 @@ struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
/**
* db_open - Open or create a database
*/
struct db *db_open(const tal_t *ctx, const char *filename);
#define db_open(ctx, filename, errfn, arg) \
db_open_((ctx), (filename), \
typesafe_cb_postargs(void, void *, (errfn), (arg), \
bool, const char *, va_list), \
(arg))
struct db *db_open_(const tal_t *ctx, const char *filename,
void (*errorfn)(void *arg, bool fatal, const char *fmt, va_list ap),
void *arg);
/**
* Report a statement that changes the wallet
@@ -110,4 +118,11 @@ const char **db_changes(struct db *db);
* to re-use the normal db hook and replication logic.
*/
struct db_stmt *db_prepare_untranslated(struct db *db, const char *query);
/* Errors and warnings... */
void db_fatal(const struct db *db, const char *fmt, ...)
PRINTF_FMT(2, 3);
void db_warn(const struct db *db, const char *fmt, ...)
PRINTF_FMT(2, 3);
#endif /* LIGHTNING_DB_UTILS_H */