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

Function plugin_set_dynamic_opt

lightningd/plugin.c:2307–2368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2305}
2306
2307struct command_result *plugin_set_dynamic_opt(struct command *cmd,
2308 const struct opt_table *ot,
2309 const char **vals,
2310 size_t nvals,
2311 bool transient,
2312 struct command_result *(*success)
2313 (struct command *,
2314 const struct opt_table *,
2315 const char **,
2316 size_t,
2317 bool))
2318{
2319 struct plugin_opt *popt;
2320 struct plugin *plugin;
2321 struct jsonrpc_request *req;
2322 struct plugin_set_return *psr;
2323
2324 plugin = plugin_opt_find_any(cmd->ld->plugins, ot, &popt);
2325 assert(plugin);
2326
2327 assert(ot->type & OPT_DYNAMIC);
2328
2329 psr = tal(cmd, struct plugin_set_return);
2330 psr->cmd = cmd;
2331 /* vals is a child of cmd, so no copy needed. */
2332 psr->vals = vals;
2333 psr->nvals = nvals;
2334 psr->optname = tal_strdup(psr, ot->names + 2);
2335 psr->success = success;
2336 psr->transient = transient;
2337
2338 if (command_check_only(cmd)) {
2339 /* If plugin doesn't support check, we can't check */
2340 if (!plugin->can_check)
2341 return command_check_done(cmd);
2342 req = jsonrpc_request_start(cmd, "check",
2343 cmd->id,
2344 command_logger(cmd),
2345 NULL, plugin_setconfig_done,
2346 psr);
2347 json_add_string(req->stream, "command_to_check", "setconfig");
2348 } else {
2349 req = jsonrpc_request_start(cmd, "setconfig",
2350 cmd->id,
2351 command_logger(cmd),
2352 NULL, plugin_setconfig_done,
2353 psr);
2354 }
2355 json_add_string(req->stream, "config", psr->optname);
2356 /* Multi options: send array. Scalar: send single value or nothing. */
2357 if (ot->type & OPT_MULTI) {
2358 json_array_start(req->stream, "val");
2359 for (size_t i = 0; i < nvals; i++)
2360 json_add_string(req->stream, NULL, vals[i]);
2361 json_array_end(req->stream);
2362 } else if (nvals > 0 && vals[0]) {
2363 json_add_string(req->stream, "val", vals[0]);
2364 }

Callers 1

json_setconfigFunction · 0.85

Calls 10

plugin_opt_find_anyFunction · 0.85
json_array_startFunction · 0.85
json_array_endFunction · 0.85
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
command_loggerFunction · 0.70
jsonrpc_request_endFunction · 0.70
plugin_request_sendFunction · 0.70
command_still_pendingFunction · 0.70
json_add_stringFunction · 0.50

Tested by

no test coverage detected