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

Function replace_command

lightningd/jsonrpc.c:821–888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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