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

Function json_add_config

lightningd/configs.c:130–210  ·  view source on GitHub ↗

Config vars can have multiple names ("--large-channels|--wumbo"), but first * is preferred. * wrap_object means we wrap json in an object of that name, otherwise outputs * raw fields. */

Source from the content-addressed store, hash-verified

128 * raw fields.
129 */
130static void json_add_config(struct lightningd *ld,
131 struct json_stream *response,
132 bool always_include,
133 bool wrap_object,
134 const struct opt_table *ot,
135 const char **names)
136{
137 char buf[CONFIG_SHOW_BUFSIZE + sizeof("...")];
138 const char *val;
139 struct configvar *cv;
140
141 /* This tells us if they actually set the option */
142 cv = configvar_first(ld->configvars, names);
143
144 /* Ignore dev/hidden options (deprecated) unless they actually used it */
145 if (!cv
146 && (ot->desc == opt_hidden || (ot->type & OPT_DEV))
147 && !always_include) {
148 return;
149 }
150
151 /* Ignore options which simply exit */
152 if (ot->type & OPT_EXITS)
153 return;
154
155 if (ot->type & OPT_NOARG) {
156 if (wrap_object)
157 json_object_start(response, names[0]);
158 json_add_bool(response, "set", cv != NULL);
159 json_add_source(response, "source", cv);
160 json_add_config_plugin(response, ld->plugins, "plugin", ot);
161 if (ot->type & OPT_DYNAMIC)
162 json_add_bool(response, "dynamic", true);
163 if (wrap_object)
164 json_object_end(response);
165 return;
166 }
167
168 assert(ot->type & OPT_HASARG);
169 if (ot->type & OPT_MULTI) {
170 if (wrap_object)
171 json_object_start(response, names[0]);
172 json_array_start(response, configval_fieldname(ot));
173 while (cv) {
174 val = get_opt_val(ot, buf, cv);
175 json_add_configval(response, NULL, ot, val);
176 cv = configvar_next(ld->configvars, cv, names);
177 }
178 json_array_end(response);
179
180 /* Iterate again, for sources */
181 json_array_start(response, "sources");
182 for (cv = configvar_first(ld->configvars, names);
183 cv;
184 cv = configvar_next(ld->configvars, cv, names)) {
185 json_add_source(response, NULL, cv);
186 }
187 json_array_end(response);

Callers 2

json_listconfigsFunction · 0.85
setconfig_successFunction · 0.85

Calls 12

configvar_firstFunction · 0.85
json_object_startFunction · 0.85
json_add_boolFunction · 0.85
json_add_sourceFunction · 0.85
json_add_config_pluginFunction · 0.85
json_object_endFunction · 0.85
json_array_startFunction · 0.85
configval_fieldnameFunction · 0.85
get_opt_valFunction · 0.85
json_add_configvalFunction · 0.85
configvar_nextFunction · 0.85
json_array_endFunction · 0.85

Tested by

no test coverage detected