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

Function plugin_rpcmethod_add

lightningd/plugin.c:1162–1242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1160}
1161
1162static const char *plugin_rpcmethod_add(struct plugin *plugin,
1163 const char *buffer,
1164 const jsmntok_t *meth)
1165{
1166 const jsmntok_t *nametok, *categorytok, *desctok, *longdesctok,
1167 *usagetok, *deptok;
1168 struct json_command *cmd;
1169 const char *usage;
1170
1171 nametok = json_get_member(buffer, meth, "name");
1172 categorytok = json_get_member(buffer, meth, "category");
1173 desctok = json_get_member(buffer, meth, "description");
1174 longdesctok = json_get_member(buffer, meth, "long_description");
1175 usagetok = json_get_member(buffer, meth, "usage");
1176 deptok = json_get_member(buffer, meth, "deprecated");
1177
1178 if (!nametok || nametok->type != JSMN_STRING) {
1179 return tal_fmt(plugin,
1180 "rpcmethod does not have a string \"name\": %.*s",
1181 meth->end - meth->start, buffer + meth->start);
1182 }
1183
1184 if (!desctok || desctok->type != JSMN_STRING) {
1185 return tal_fmt(plugin,
1186 "rpcmethod does not have a string "
1187 "\"description\": %.*s",
1188 meth->end - meth->start, buffer + meth->start);
1189 }
1190
1191 if (longdesctok && longdesctok->type != JSMN_STRING) {
1192 return tal_fmt(plugin,
1193 "\"long_description\" is not a string: %.*s",
1194 meth->end - meth->start, buffer + meth->start);
1195 }
1196
1197 if (usagetok && usagetok->type != JSMN_STRING) {
1198 return tal_fmt(plugin,
1199 "\"usage\" is not a string: %.*s",
1200 meth->end - meth->start, buffer + meth->start);
1201 }
1202
1203 cmd = notleak(tal(plugin, struct json_command));
1204 cmd->name = json_strdup(cmd, buffer, nametok);
1205 if (categorytok)
1206 cmd->category = json_strdup(cmd, buffer, categorytok);
1207 else
1208 cmd->category = "plugin";
1209 cmd->description = json_strdup(cmd, buffer, desctok);
1210 if (longdesctok)
1211 cmd->verbose = json_strdup(cmd, buffer, longdesctok);
1212 else
1213 cmd->verbose = cmd->description;
1214 if (usagetok)
1215 usage = json_strdup(tmpctx, buffer, usagetok);
1216 else
1217 return tal_fmt(plugin,
1218 "\"usage\" not provided by plugin");
1219

Callers 1

plugin_rpcmethods_addFunction · 0.85

Calls 5

jsonrpc_command_addFunction · 0.85
find_plugin_for_commandFunction · 0.70
json_get_memberFunction · 0.50
json_strdupFunction · 0.50
json_to_boolFunction · 0.50

Tested by

no test coverage detected