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

Function ld_command_handle

plugins/libplugin.c:2066–2262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2064}
2065
2066static void ld_command_handle(struct plugin *plugin,
2067 const char *buffer,
2068 const jsmntok_t *toks)
2069{
2070 const jsmntok_t *methtok, *paramstok, *filtertok;
2071 const char *methodname;
2072 struct command *cmd;
2073 const char *id;
2074 enum command_type type;
2075
2076 methtok = json_get_member(buffer, toks, "method");
2077 paramstok = json_get_member(buffer, toks, "params");
2078 filtertok = json_get_member(buffer, toks, "filter");
2079
2080 if (!methtok || !paramstok)
2081 plugin_err(plugin, "Malformed JSON-RPC notification missing "
2082 "\"method\" or \"params\": %.*s",
2083 json_tok_full_len(toks),
2084 json_tok_full(buffer, toks));
2085
2086 methodname = json_strdup(NULL, buffer, methtok);
2087 id = json_get_id(tmpctx, buffer, toks);
2088
2089 if (!id)
2090 type = COMMAND_TYPE_NOTIFICATION;
2091 else if (streq(methodname, "check"))
2092 type = COMMAND_TYPE_CHECK;
2093 else
2094 type = COMMAND_TYPE_NORMAL;
2095
2096 cmd = new_command(plugin, plugin,
2097 id ? id : tal_fmt(tmpctx, "notification-%s", methodname),
2098 take(methodname),
2099 type);
2100
2101 if (!plugin->manifested) {
2102 if (streq(cmd->methodname, "getmanifest")) {
2103 handle_getmanifest(cmd, buffer, paramstok);
2104 plugin->manifested = true;
2105 return;
2106 }
2107 plugin_err(plugin, "Did not receive 'getmanifest' yet, but got '%s'"
2108 " instead", cmd->methodname);
2109 }
2110
2111 if (!plugin->initialized) {
2112 if (streq(cmd->methodname, "init")) {
2113 handle_init(cmd, buffer, paramstok);
2114 plugin->initialized = true;
2115 return;
2116 }
2117 plugin_err(plugin, "Did not receive 'init' yet, but got '%s'"
2118 " instead", cmd->methodname);
2119 }
2120
2121 /* If that's a notification. */
2122 if (cmd->type == COMMAND_TYPE_NOTIFICATION) {
2123 bool is_shutdown = streq(cmd->methodname, "shutdown");

Callers 1

ld_read_jsonFunction · 0.85

Calls 15

json_get_memberFunction · 0.85
json_get_idFunction · 0.85
new_commandFunction · 0.85
handle_getmanifestFunction · 0.85
is_asterix_notificationFunction · 0.85
plugin_exitFunction · 0.85
parse_filterFunction · 0.85
json_tok_copyFunction · 0.85
param_checkFunction · 0.85
tal_freeFunction · 0.85
json_tok_removeFunction · 0.85
plugin_errFunction · 0.70

Tested by

no test coverage detected