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

Function try_command

plugins/commando.c:367–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367static struct command_result *try_command(struct command *cmd,
368 struct commando *incoming STEALS)
369{
370 const jsmntok_t *toks, *method, *params, *runetok, *id, *filter;
371 const char *buf = (const char *)incoming->contents;
372 struct cond_info *cinfo;
373 struct rune *rune;
374 struct out_req *req;
375
376 toks = json_parse_simple(incoming, buf, tal_bytelen(buf));
377 if (!toks) {
378 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
379 "Invalid JSON");
380 }
381
382 if (toks[0].type != JSMN_OBJECT) {
383 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
384 "Not a JSON object");
385 }
386 method = json_get_member(buf, toks, "method");
387 if (!method) {
388 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
389 "No method");
390 }
391 params = json_get_member(buf, toks, "params");
392 if (params && (params->type != JSMN_OBJECT && params->type != JSMN_ARRAY)) {
393 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
394 "Params must be object or array");
395 }
396 filter = json_get_member(buf, toks, "filter");
397 id = json_get_member(buf, toks, "id");
398 if (!id) {
399 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
400 "missing id field");
401 }
402 runetok = json_get_member(buf, toks, "rune");
403 if (!runetok) {
404 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
405 "Missing rune");
406 }
407 rune = rune_from_base64n(tmpctx, buf + runetok->start,
408 runetok->end - runetok->start);
409 if (!rune) {
410 return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE,
411 "Invalid rune");
412 }
413 /* Gather all the info we need to execute this command (steals toks). */
414 cinfo = new_cond_info(incoming, incoming, toks, method, params, id, filter);
415
416 /* Don't count this towards incomings anymore */
417 destroy_commando(incoming, &incoming_commands);
418 tal_del_destructor2(incoming, destroy_commando, &incoming_commands);
419
420 req = jsonrpc_request_start(cmd, "checkrune",
421 checkrune_done, checkrune_failed,
422 cinfo);
423 json_add_node_id(req->js, "nodeid", &incoming->peer);
424 json_add_tok(req->js, "rune", runetok, cinfo->buf);

Callers 1

handle_incmdFunction · 0.85

Calls 10

json_parse_simpleFunction · 0.85
tal_bytelenFunction · 0.85
commando_errorFunction · 0.85
json_get_memberFunction · 0.85
rune_from_base64nFunction · 0.85
new_cond_infoFunction · 0.85
destroy_commandoFunction · 0.85
json_add_node_idFunction · 0.85
json_add_tokFunction · 0.85
send_outreqFunction · 0.70

Tested by

no test coverage detected