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

Function handle_init

plugins/libplugin.c:1532–1620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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