Browse Source

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.
travis-debug
Christian Decker 5 years ago
committed by neil saitug
parent
commit
6020a0d587
  1. 5
      lightningd/plugin_hook.c
  2. 5
      lightningd/plugin_hook.h
  3. 7
      wallet/db.c
  4. 5
      wallet/db.h
  5. 2
      wallet/test/run-db.c
  6. 2
      wallet/test/run-wallet.c

5
lightningd/plugin_hook.c

@ -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);

5
lightningd/plugin_hook.h

@ -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 */

7
wallet/db.c

@ -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;
}

5
wallet/db.h

@ -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 */

2
wallet/test/run-db.c

@ -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)
{
}

2
wallet/test/run-wallet.c

@ -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…
Cancel
Save