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

Function cmd_done

plugins/commando.c:155–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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