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

Function jsonrpc_request_sync

plugins/bkpr/test/run-recorder.c:467–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465}
466
467const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
468 struct command *cmd,
469 const char *method,
470 const struct json_out *params TAKES,
471 const char **resp)
472{
473 sqlite3_stmt *s;
474 jsmntok_t *toks;
475 jsmn_parser parser;
476 size_t len;
477 char *buf;
478 const char *p, *querystr;
479 bool complete;
480 int rc;
481
482 if (streq(method, "listdatastore")) {
483 buf = tal_fmt(ctx, "{\"datastore\": []}");
484 goto done;
485 }
486
487 assert(streq(method, "sql"));
488
489 /* Grab select query */
490 jsmn_init(&parser);
491 p = json_out_contents(params, &len);
492 toks = toks_alloc(tmpctx);
493 assert(json_parse_input(&parser, &toks, p, len, &complete));
494 assert(complete);
495 /* { "query": <querystr> } */
496 querystr = json_strdup(tmpctx, p, toks + 2);
497
498 sqlite3_prepare_v2(bkpr_db, querystr,
499 -1, &s, NULL);
500
501 /* Make JSON-style result */
502 buf = tal_fmt(ctx, "{\"rows\": [");
503 while ((rc = sqlite3_step(s)) == SQLITE_ROW) {
504 size_t num_cols = sqlite3_column_count(s);
505
506 tal_append_fmt(&buf, "[");
507 for (size_t i = 0; i < num_cols; i++) {
508 switch (sqlite3_column_type(s, i)) {
509 case SQLITE_NULL:
510 tal_append_fmt(&buf, "null");
511 break;
512 case SQLITE_INTEGER:
513 tal_append_fmt(&buf, "%"PRIu64, (u64)sqlite3_column_int64(s, i));
514 break;
515 case SQLITE_TEXT:
516 tal_append_fmt(&buf, "\"%s\"", sqlite3_column_text(s, i));
517 break;
518 case SQLITE_BLOB: {
519 const void *blob = sqlite3_column_blob(s, i);
520 int bloblen = sqlite3_column_bytes(s, i);
521 tal_append_fmt(&buf, "\"%s\"", tal_hexstr(tmpctx, blob, bloblen));
522 break;
523 }
524 default:

Callers 13

list_awaiting_channelsFunction · 0.50
sql_reqvFunction · 0.50
init_rebalancesFunction · 0.50
init_descriptionsFunction · 0.50
init_onchain_feesFunction · 0.50
load_currencyratesFunction · 0.50
init_blockheightsFunction · 0.50
init_accountsFunction · 0.50
load_layersFunction · 0.50
bwatch_list_datastoreFunction · 0.50

Calls 8

json_out_contentsFunction · 0.85
toks_allocFunction · 0.85
json_parse_inputFunction · 0.85
tal_append_fmtFunction · 0.85
tal_hexstrFunction · 0.85
abortFunction · 0.85
tal_free_if_takenFunction · 0.85
json_strdupFunction · 0.50

Tested by

no test coverage detected