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

Function prepare_stop_conn

lightningd/jsonrpc.c:169–207  ·  view source on GitHub ↗

We prepare a canned JSON response, for top level to write as reply * immediately before we exit. */

Source from the content-addressed store, hash-verified

167/* We prepare a canned JSON response, for top level to write as reply
168 * immediately before we exit. */
169static struct command_result *prepare_stop_conn(struct command *cmd,
170 const char *why)
171{
172 struct json_out *jout;
173 const char *p;
174 size_t len;
175
176 /* With rpc_command_hook, jcon might have closed in the meantime! */
177 if (!cmd->jcon) {
178 /* Return us to toplevel lightningd.c */
179 log_debug(cmd->ld->log, "io_break: %s", __func__);
180 io_break(cmd->ld);
181 return command_still_pending(cmd);
182 }
183
184 cmd->ld->stop_conn = cmd->jcon->conn;
185
186 jout = json_out_new(tmpctx);
187 json_out_start(jout, NULL, '{');
188 json_out_addstr(jout, "jsonrpc", "2.0");
189 /* Copy input id token exactly */
190 memcpy(json_out_member_direct(jout, "id", strlen(cmd->id)),
191 cmd->id, strlen(cmd->id));
192 json_out_start(jout, "result", '{');
193 json_out_addstr(jout, "result", why);
194 json_out_end(jout, '}');
195 json_out_end(jout, '}');
196 json_out_finished(jout);
197
198 /* Add two \n */
199 memcpy(json_out_direct(jout, 2), "\n\n", strlen("\n\n"));
200 p = json_out_contents(jout, &len);
201 cmd->ld->stop_response = tal_strndup(cmd->ld, p, len);
202
203 /* Wake write loop in case it's not already. */
204 io_wake(cmd->jcon);
205
206 return command_still_pending(cmd);
207}
208
209static struct command_result *json_stop(struct command *cmd,
210 const char *buffer,

Callers 2

json_stopFunction · 0.85
json_recoverFunction · 0.85

Calls 11

io_breakFunction · 0.85
json_out_newFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_member_directFunction · 0.85
json_out_endFunction · 0.85
json_out_finishedFunction · 0.85
json_out_directFunction · 0.85
json_out_contentsFunction · 0.85
io_wakeFunction · 0.85
command_still_pendingFunction · 0.70

Tested by

no test coverage detected