| 178 | } |
| 179 | |
| 180 | static struct command_result *listinvoices_done(struct command *cmd, |
| 181 | const char *buf, |
| 182 | const jsmntok_t *result, |
| 183 | struct clean_info *cinfo) |
| 184 | { |
| 185 | const jsmntok_t *t, *inv = json_get_member(buf, result, "invoices"); |
| 186 | size_t i; |
| 187 | u64 now = time_now().ts.tv_sec; |
| 188 | |
| 189 | json_for_each_arr(i, t, inv) { |
| 190 | const jsmntok_t *status = json_get_member(buf, t, "status"); |
| 191 | const jsmntok_t *time; |
| 192 | enum subsystem subsys; |
| 193 | u64 invtime; |
| 194 | |
| 195 | if (json_tok_streq(buf, status, "expired")) { |
| 196 | subsys = EXPIREDINVOICES; |
| 197 | time = json_get_member(buf, t, "expires_at"); |
| 198 | } else if (json_tok_streq(buf, status, "paid")) { |
| 199 | subsys = PAIDINVOICES; |
| 200 | time = json_get_member(buf, t, "paid_at"); |
| 201 | } else { |
| 202 | cinfo->num_uncleaned++; |
| 203 | continue; |
| 204 | } |
| 205 | |
| 206 | /* Continue if we don't care. */ |
| 207 | if (cinfo->subsystem_age[subsys] == 0) { |
| 208 | cinfo->num_uncleaned++; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | if (!json_to_u64(buf, time, &invtime)) { |
| 213 | plugin_err(plugin, "Bad time '%.*s'", |
| 214 | json_tok_full_len(time), |
| 215 | json_tok_full(buf, time)); |
| 216 | } |
| 217 | |
| 218 | if (invtime <= now - cinfo->subsystem_age[subsys]) { |
| 219 | struct out_req *req; |
| 220 | const jsmntok_t *label = json_get_member(buf, t, "label"); |
| 221 | |
| 222 | req = del_request_start("delinvoice", cinfo, subsys); |
| 223 | json_add_tok(req->js, "label", label, buf); |
| 224 | json_add_tok(req->js, "status", status, buf); |
| 225 | send_outreq(plugin, req); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if (cinfo->cleanup_reqs_remaining) |
| 230 | return command_still_pending(cmd); |
| 231 | return clean_finished(cinfo); |
| 232 | } |
| 233 | |
| 234 | static struct command_result *listsendpays_done(struct command *cmd, |
| 235 | const char *buf, |
nothing calls this directly
no test coverage detected