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

Function jsonrpc_io_parse

common/jsonrpc_io.c:58–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58const char *jsonrpc_io_parse(const tal_t *ctx,
59 struct jsonrpc_io *json_in,
60 const jsmntok_t **toks,
61 const char **buf)
62{
63 bool complete;
64
65 /* If we're read any more, add that */
66 add_newly_read(json_in);
67 *toks = NULL;
68 *buf = NULL;
69
70 /* Our JSON parser is pretty good at incremental parsing, but
71 * `getrawblock` gives a giant 2MB token, which forces it to re-parse
72 * every time until we have all of it. However, we can't complete a
73 * JSON object without a '}', so we do a cheaper check here.
74 */
75 if (!memchr(membuf_elems(&json_in->membuf), '}',
76 membuf_num_elems(&json_in->membuf)))
77 return NULL;
78
79 if (!json_parse_input(&json_in->parser, &json_in->toks,
80 membuf_elems(&json_in->membuf),
81 membuf_num_elems(&json_in->membuf),
82 &complete)) {
83 return tal_fmt(ctx, "Failed to parse RPC JSON response '%.*s'",
84 (int)membuf_num_elems(&json_in->membuf),
85 membuf_elems(&json_in->membuf));
86 }
87
88 if (!complete)
89 return NULL;
90
91 /* Must have jsonrpc to be valid! */
92 if (!json_get_member(membuf_elems(&json_in->membuf),
93 json_in->toks,
94 "jsonrpc")) {
95 return tal_fmt(ctx,
96 "JSON-RPC message does not contain \"jsonrpc\" field: '%.*s'",
97 (int)membuf_num_elems(&json_in->membuf),
98 membuf_elems(&json_in->membuf));
99 }
100
101 *toks = json_in->toks;
102 *buf = membuf_elems(&json_in->membuf);
103 return NULL;
104}
105
106void jsonrpc_io_parse_done(struct jsonrpc_io *json_in)
107{

Callers 6

plugin_read_jsonFunction · 0.85
read_jsonFunction · 0.85
pump_nextFunction · 0.85
read_one_json_syncFunction · 0.85
rpc_conn_read_responseFunction · 0.85
ld_read_jsonFunction · 0.85

Calls 3

add_newly_readFunction · 0.85
json_parse_inputFunction · 0.85
json_get_memberFunction · 0.85

Tested by 1

pump_nextFunction · 0.68