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

Function plugin_set_dynamic_opt

lightningd/plugin.c:2295–2356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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