MCPcopy Create free account
hub / github.com/ElementsProject/lightning / watch_init

Function watch_init

plugins/sql.c:1337–1369  ·  view source on GitHub ↗

First time we initialize counters and figure where we're up to */

Source from the content-addressed store, hash-verified

1335
1336/* First time we initialize counters and figure where we're up to */
1337static void watch_init(struct command *cmd,
1338 struct table_desc *td,
1339 const char *indexname,
1340 u64 *max)
1341{
1342 struct json_out *params = json_out_new(NULL);
1343 const jsmntok_t *result, *valtok;
1344 const char *buf;
1345 u64 val;
1346
1347 json_out_start(params, NULL, '{');
1348 json_out_addstr(params, "subsystem", td->waitname);
1349 json_out_addstr(params, "indexname", indexname);
1350 json_out_add(params, "nextvalue", false, "0");
1351 json_out_end(params, '}');
1352
1353 result = jsonrpc_request_sync(tmpctx, cmd, "wait", take(params), &buf);
1354
1355 valtok = json_get_member(buf, result, indexname);
1356 if (!valtok || !json_to_u64(buf, valtok, &val)) {
1357 plugin_err(cmd->plugin,
1358 "Invalid wait reply for %s %s: '%.*s'",
1359 td->name, indexname,
1360 json_tok_full_len(result),
1361 json_tok_full(buf, result));
1362 }
1363
1364 if (max != NULL)
1365 *max = val;
1366
1367 /* Place watch for when it increases */
1368 watch_for(sql_of(cmd->plugin), td, indexname, val + 1);
1369}
1370
1371static struct command_result *refresh_tables(struct command *cmd,
1372 struct db_query *dbq)

Callers 1

refresh_tablesFunction · 0.85

Calls 13

json_out_newFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_addFunction · 0.85
json_out_endFunction · 0.85
json_get_memberFunction · 0.85
watch_forFunction · 0.85
sql_ofFunction · 0.85
jsonrpc_request_syncFunction · 0.70
plugin_errFunction · 0.70
json_to_u64Function · 0.50
json_tok_full_lenFunction · 0.50

Tested by

no test coverage detected