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

Function replace_command

lightningd/jsonrpc.c:817–884  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

815}
816
817static void replace_command(struct rpc_command_hook_payload *p,
818 const char *buffer,
819 const jsmntok_t *replacetok)
820{
821 const jsmntok_t *method = NULL, *params = NULL, *jsonrpc;
822 const char *bad;
823
824 /* Must contain "method", "params" and "id" */
825 if (replacetok->type != JSMN_OBJECT) {
826 bad = "'replace' must be an object";
827 goto fail;
828 }
829
830 method = json_get_member(buffer, replacetok, "method");
831 if (!method) {
832 bad = "missing 'method'";
833 goto fail;
834 }
835 params = json_get_member(buffer, replacetok, "params");
836 if (!params) {
837 bad = "missing 'params'";
838 goto fail;
839 }
840 if (!json_get_member(buffer, replacetok, "id")) {
841 bad = "missing 'id'";
842 goto fail;
843 }
844
845 p->cmd->json_cmd = find_cmd(p->cmd->ld->jsonrpc, buffer, method);
846 if (!p->cmd->json_cmd) {
847 bad = tal_fmt(tmpctx, "redirected to unknown method '%.*s'",
848 method->end - method->start,
849 buffer + method->start);
850 goto fail;
851 }
852 if (!command_deprecated_in_ok(p->cmd,
853 json_strdup(tmpctx, buffer, method),
854 p->cmd->json_cmd->depr_start,
855 p->cmd->json_cmd->depr_end)) {
856 bad = tal_fmt(tmpctx, "redirected to deprecated command '%.*s'",
857 method->end - method->start,
858 buffer + method->start);
859 goto fail;
860 }
861 if (p->cmd->json_cmd->dev_only && !p->cmd->ld->developer) {
862 bad = tal_fmt(tmpctx, "redirected to developer-only command '%.*s'",
863 method->end - method->start,
864 buffer + method->start);
865 goto fail;
866 }
867
868 jsonrpc = json_get_member(buffer, replacetok, "jsonrpc");
869 if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
870 bad = "jsonrpc: \"2.0\" must be specified in the request";
871 goto fail;
872 }
873
874 was_pending(command_exec(p->cmd->jcon, p->cmd, buffer, replacetok,

Callers 1

rpc_command_hook_finalFunction · 0.85

Calls 10

json_get_memberFunction · 0.85
find_cmdFunction · 0.85
json_tok_streqFunction · 0.85
command_execFunction · 0.85
command_deprecated_in_okFunction · 0.70
was_pendingFunction · 0.70
command_failFunction · 0.70
json_strdupFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected