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

Function ld_command_handle

plugins/libplugin.c:2076–2272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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