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

Function handle_init

plugins/libplugin.c:1522–1610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1520}
1521
1522static struct command_result *handle_init(struct command *cmd,
1523 const char *buf,
1524 const jsmntok_t *params)
1525{
1526 const jsmntok_t *configtok, *opttok, *t;
1527 size_t i;
1528 char *dir, *network;
1529 struct plugin *p = cmd->plugin;
1530 const char *err;
1531
1532 configtok = json_get_member(buf, params, "configuration");
1533 err = json_scan(tmpctx, buf, configtok,
1534 "{lightning-dir:%"
1535 ",network:%"
1536 ",feature_set:%"
1537 ",rpc-file:%}",
1538 JSON_SCAN_TAL(tmpctx, json_strdup, &dir),
1539 JSON_SCAN_TAL(tmpctx, json_strdup, &network),
1540 JSON_SCAN_TAL(p, json_to_feature_set, &p->our_features),
1541 JSON_SCAN_TAL(p, json_strdup, &p->rpc_location));
1542 if (err)
1543 plugin_err(p, "cannot scan init params: %s: %.*s",
1544 err, json_tok_full_len(params),
1545 json_tok_full(buf, params));
1546
1547 /* Move into lightning directory: other files are relative */
1548 if (chdir(dir) != 0)
1549 plugin_err(p, "chdir to %s: %s", dir, strerror(errno));
1550
1551 chainparams = chainparams_for_network(network);
1552
1553 /* Only attempt to connect if the plugin has configured the rpc_conn
1554 * already, if that's not the case we were told to run without an RPC
1555 * connection, so don't even log an error. */
1556 if (p->sync_io)
1557 p->sync_fd = rpc_open(p);
1558 else
1559 p->sync_fd = -1;
1560
1561 opttok = json_get_member(buf, params, "options");
1562 json_for_each_obj(i, t, opttok) {
1563 const char *name, *problem;
1564 struct plugin_option *popt;
1565
1566 name = json_strdup(tmpctx, buf, t);
1567 popt = find_opt(p, name);
1568 if (!popt)
1569 plugin_err(p, "lightningd specified unknown option '%s'?", name);
1570
1571 if (popt->multi) {
1572 size_t j;
1573 const jsmntok_t *opt;
1574 json_for_each_arr(j, opt, t+1) {
1575 problem = popt->handle(cmd, json_strdup(tmpctx, buf, opt), false, popt->arg);
1576 if (problem)
1577 plugin_err(p, "option '%s': %s", popt->name, problem);
1578 }
1579 } else {

Callers 1

ld_command_handleFunction · 0.70

Calls 15

json_get_memberFunction · 0.85
chainparams_for_networkFunction · 0.85
rpc_openFunction · 0.85
initMethod · 0.80
plugin_errFunction · 0.70
find_optFunction · 0.70
command_successFunction · 0.70
json_out_objFunction · 0.70
aux_commandFunction · 0.70
send_outreqFunction · 0.70
json_scanFunction · 0.50
json_tok_full_lenFunction · 0.50

Tested by

no test coverage detected