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

Function cmd_done

plugins/commando.c:158–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158static struct command_result *cmd_done(struct command *command,
159 const char *method,
160 const char *buf,
161 const jsmntok_t *obj,
162 struct commando *incoming)
163{
164 struct reply *reply = tal(plugin, struct reply);
165 reply->incoming = tal_steal(reply, incoming);
166
167 /* We make a copy, but substititing the original id! */
168 if (incoming->json_id) {
169 const char *id_start, *id_end;
170 const jsmntok_t *id = json_get_member(buf, obj, "id");
171 size_t off;
172
173 /* Old id we're going to omit */
174 id_start = json_tok_full(buf, id);
175 id_end = id_start + json_tok_full_len(id);
176
177 reply->len = obj->end - obj->start
178 - (id_end - id_start)
179 + strlen(incoming->json_id);
180 reply->buf = tal_arr(reply, char, reply->len);
181 memcpy(reply->buf, buf + obj->start,
182 id_start - (buf + obj->start));
183 off = id_start - (buf + obj->start);
184 memcpy(reply->buf + off, incoming->json_id, strlen(incoming->json_id));
185 off += strlen(incoming->json_id);
186 memcpy(reply->buf + off, id_end, (buf + obj->end) - id_end);
187 } else {
188 reply->len = obj->end - obj->start;
189 reply->buf = tal_strndup(reply, buf + obj->start, reply->len);
190 }
191 reply->off = 0;
192
193 return send_response(command, NULL, NULL, NULL, reply);
194}
195
196static struct command_result *commando_error(struct command *cmd,
197 struct commando *incoming,

Callers

nothing calls this directly

Calls 4

json_get_memberFunction · 0.85
send_responseFunction · 0.85
json_tok_fullFunction · 0.50
json_tok_full_lenFunction · 0.50

Tested by

no test coverage detected