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

Function listsendpays_done

plugins/autoclean.c:234–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234static struct command_result *listsendpays_done(struct command *cmd,
235 const char *buf,
236 const jsmntok_t *result,
237 struct clean_info *cinfo)
238{
239 const jsmntok_t *t, *pays = json_get_member(buf, result, "payments");
240 size_t i;
241 u64 now = time_now().ts.tv_sec;
242
243 json_for_each_arr(i, t, pays) {
244 const jsmntok_t *status = json_get_member(buf, t, "status");
245 const jsmntok_t *time;
246 enum subsystem subsys;
247 u64 paytime;
248
249 if (json_tok_streq(buf, status, "failed")) {
250 subsys = FAILEDPAYS;
251 } else if (json_tok_streq(buf, status, "complete")) {
252 subsys = SUCCEEDEDPAYS;
253 } else {
254 cinfo->num_uncleaned++;
255 continue;
256 }
257
258 /* Continue if we don't care. */
259 if (cinfo->subsystem_age[subsys] == 0) {
260 cinfo->num_uncleaned++;
261 continue;
262 }
263
264 time = json_get_member(buf, t, "created_at");
265 if (!json_to_u64(buf, time, &paytime)) {
266 plugin_err(plugin, "Bad created_at '%.*s'",
267 json_tok_full_len(time),
268 json_tok_full(buf, time));
269 }
270
271 if (paytime <= now - cinfo->subsystem_age[subsys]) {
272 struct out_req *req;
273 const jsmntok_t *phash = json_get_member(buf, t, "payment_hash");
274 const jsmntok_t *groupid = json_get_member(buf, t, "groupid");
275 const jsmntok_t *partidtok = json_get_member(buf, t, "partid");
276 u64 partid;
277 if (partidtok)
278 json_to_u64(buf, partidtok, &partid);
279 else
280 partid = 0;
281
282 req = del_request_start("delpay", cinfo, subsys);
283 json_add_tok(req->js, "payment_hash", phash, buf);
284 json_add_tok(req->js, "status", status, buf);
285 json_add_tok(req->js, "groupid", groupid, buf);
286 json_add_u64(req->js, "partid", partid);
287 send_outreq(plugin, req);
288 }
289 }
290
291 if (cinfo->cleanup_reqs_remaining)

Callers

nothing calls this directly

Calls 13

time_nowFunction · 0.85
del_request_startFunction · 0.85
json_add_tokFunction · 0.85
clean_finishedFunction · 0.85
plugin_errFunction · 0.70
send_outreqFunction · 0.70
command_still_pendingFunction · 0.70
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50
json_to_u64Function · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected