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

Function read_rpc_reply

plugins/libplugin.c:488–521  ·  view source on GitHub ↗

Reads rpc reply and returns tokens, setting contents to 'error' or * 'result' (depending on *error). */

Source from the content-addressed store, hash-verified

486/* Reads rpc reply and returns tokens, setting contents to 'error' or
487 * 'result' (depending on *error). */
488static const jsmntok_t *read_rpc_reply(const tal_t *ctx,
489 struct plugin *plugin,
490 const jsmntok_t **contents,
491 bool *error,
492 int *reqlen)
493{
494 const jsmntok_t *toks;
495
496 do {
497 *reqlen = read_json_from_rpc(plugin);
498
499 toks = json_parse_simple(ctx,
500 membuf_elems(&plugin->rpc_conn->mb),
501 *reqlen);
502 if (!toks)
503 plugin_err(plugin, "Malformed JSON reply '%.*s'",
504 *reqlen, membuf_elems(&plugin->rpc_conn->mb));
505 /* FIXME: Don't simply ignore notifications here! */
506 } while (!json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks,
507 "id"));
508
509 *contents = json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks, "error");
510 if (*contents)
511 *error = true;
512 else {
513 *contents = json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks,
514 "result");
515 if (!*contents)
516 plugin_err(plugin, "JSON reply with no 'result' nor 'error'? '%.*s'",
517 *reqlen, membuf_elems(&plugin->rpc_conn->mb));
518 *error = false;
519 }
520 return toks;
521}
522
523/* Send request, return response, set resp/len to reponse */
524static const jsmntok_t *sync_req(const tal_t *ctx,

Callers 1

sync_reqFunction · 0.85

Calls 4

read_json_from_rpcFunction · 0.85
plugin_errFunction · 0.70
json_parse_simpleFunction · 0.50
json_get_memberFunction · 0.50

Tested by

no test coverage detected