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

Function param_hops_array

common/json_param.c:612–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612struct command_result *param_hops_array(struct command *cmd, const char *name,
613 const char *buffer, const jsmntok_t *tok,
614 struct sphinx_hop **hops)
615{
616 const jsmntok_t *hop, *payloadtok, *pubkeytok;
617 struct sphinx_hop h;
618 size_t i;
619 if (tok->type != JSMN_ARRAY) {
620 return command_fail_badparam(cmd, name, buffer, tok,
621 "should be an array of hops");
622 }
623
624 *hops = tal_arr(cmd, struct sphinx_hop, 0);
625
626 json_for_each_arr(i, hop, tok) {
627 payloadtok = json_get_member(buffer, hop, "payload");
628 pubkeytok = json_get_member(buffer, hop, "pubkey");
629
630 if (!pubkeytok)
631 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
632 "Hop %zu does not have a pubkey", i);
633
634 if (!payloadtok)
635 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
636 "Hop %zu does not have a payload", i);
637
638 h.raw_payload = json_tok_bin_from_hex(*hops, buffer, payloadtok);
639 if (!json_to_pubkey(buffer, pubkeytok, &h.pubkey))
640 return command_fail_badparam(cmd, name, buffer, pubkeytok,
641 "should be a pubkey");
642
643 if (!h.raw_payload)
644 return command_fail_badparam(cmd, name, buffer,
645 payloadtok,
646 "should be hex");
647
648 tal_arr_expand(hops, h);
649 }
650
651 if (tal_count(*hops) == 0) {
652 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
653 "At least one hop must be specified.");
654 }
655
656 return NULL;
657}
658
659struct command_result *param_secrets_array(struct command *cmd,
660 const char *name, const char *buffer,

Callers

nothing calls this directly

Calls 5

command_fail_badparamFunction · 0.85
json_get_memberFunction · 0.70
json_tok_bin_from_hexFunction · 0.70
json_to_pubkeyFunction · 0.70
command_failFunction · 0.50

Tested by

no test coverage detected