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

Function try_command

plugins/commando.c:370–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

handle_incmdFunction · 0.85

Calls 10

destroy_commandoFunction · 0.85
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
json_add_node_idFunction · 0.85
json_add_tokFunction · 0.85
send_outreqFunction · 0.70

Tested by

no test coverage detected