mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
db: Consolidate access to the changes in a db
We were passing them in separately, while we could just retrieve them from the db instance instead.
This commit is contained in:
parent
5baf39e7dc
commit
6020a0d587
6 changed files with 17 additions and 9 deletions
|
@ -156,13 +156,14 @@ static void db_hook_response(const char *buffer, const jsmntok_t *toks,
|
|||
io_break(ph_req);
|
||||
}
|
||||
|
||||
void plugin_hook_db_sync(struct db *db, const char **changes, const char *final)
|
||||
void plugin_hook_db_sync(struct db *db)
|
||||
{
|
||||
const struct plugin_hook *hook = &db_write_hook;
|
||||
struct jsonrpc_request *req;
|
||||
struct plugin_hook_request *ph_req;
|
||||
void *ret;
|
||||
|
||||
const char **changes = db_changes(db);
|
||||
if (!hook->plugin)
|
||||
return;
|
||||
|
||||
|
@ -177,8 +178,6 @@ void plugin_hook_db_sync(struct db *db, const char **changes, const char *final)
|
|||
json_array_start(req->stream, "writes");
|
||||
for (size_t i = 0; i < tal_count(changes); i++)
|
||||
json_add_string(req->stream, NULL, changes[i]);
|
||||
if (final)
|
||||
json_add_string(req->stream, NULL, final);
|
||||
json_array_end(req->stream);
|
||||
jsonrpc_request_end(req);
|
||||
|
||||
|
|
|
@ -108,8 +108,7 @@ bool plugin_hook_unregister(struct plugin *plugin, const char *method);
|
|||
/* Unregister all hooks a plugin has registered for */
|
||||
void plugin_hook_unregister_all(struct plugin *plugin);
|
||||
|
||||
/* Special sync plugin hook for db: changes[] are SQL statements, with optional
|
||||
* final command appended. */
|
||||
void plugin_hook_db_sync(struct db *db, const char **changes, const char *final);
|
||||
/* Special sync plugin hook for db. */
|
||||
void plugin_hook_db_sync(struct db *db);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_HOOK_H */
|
||||
|
|
|
@ -764,7 +764,7 @@ static void db_report_changes(struct db *db, const char *final, size_t min)
|
|||
assert(tal_count(db->changes) >= min);
|
||||
|
||||
if (tal_count(db->changes) > min)
|
||||
plugin_hook_db_sync(db, db->changes, final);
|
||||
plugin_hook_db_sync(db);
|
||||
db->changes = tal_free(db->changes);
|
||||
}
|
||||
|
||||
|
@ -1399,3 +1399,8 @@ void db_changes_add(struct db_stmt *stmt, const char * expanded)
|
|||
|
||||
tal_arr_expand(&db->changes, tal_strdup(db->changes, expanded));
|
||||
}
|
||||
|
||||
const char **db_changes(struct db *db)
|
||||
{
|
||||
return db->changes;
|
||||
}
|
||||
|
|
|
@ -224,4 +224,9 @@ struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
|||
#define db_prepare_v2(db,query) \
|
||||
db_prepare_v2_(__FILE__ ":" stringify(__LINE__), db, query)
|
||||
|
||||
/**
|
||||
* Access pending changes that have been added to the current transaction.
|
||||
*/
|
||||
const char **db_changes(struct db *db);
|
||||
|
||||
#endif /* LIGHTNING_WALLET_DB_H */
|
||||
|
|
|
@ -47,7 +47,7 @@ static void db_test_fatal(const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void plugin_hook_db_sync(struct db *db UNNEEDED, const char **changes UNNEEDED, const char *final UNNEEDED)
|
||||
void plugin_hook_db_sync(struct db *db UNNEEDED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -650,7 +650,7 @@ u8 *wire_sync_read(const tal_t *ctx UNNEEDED, int fd UNNEEDED)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
void plugin_hook_db_sync(struct db *db UNNEEDED, const char **changes UNNEEDED, const char *final UNNEEDED)
|
||||
void plugin_hook_db_sync(struct db *db UNNEEDED)
|
||||
{
|
||||
}
|
||||
bool fromwire_hsm_get_channel_basepoints_reply(const void *p UNNEEDED,
|
||||
|
|
Loading…
Add table
Reference in a new issue