| 346 | } |
| 347 | |
| 348 | static struct command_result *prev_invoice_done(struct command *cmd, |
| 349 | const char *buf, |
| 350 | const jsmntok_t *result, |
| 351 | struct invreq *ir) |
| 352 | { |
| 353 | const jsmntok_t *status, *arr, *b12; |
| 354 | struct tlv_invoice *previnv; |
| 355 | char *fail; |
| 356 | |
| 357 | /* Was it created? */ |
| 358 | arr = json_get_member(buf, result, "invoices"); |
| 359 | if (arr->size == 0) { |
| 360 | return fail_invreq(cmd, ir, |
| 361 | "No previous invoice #%u", |
| 362 | *ir->inv->recurrence_counter - 1); |
| 363 | } |
| 364 | |
| 365 | /* Was it paid? */ |
| 366 | status = json_get_member(buf, arr + 1, "status"); |
| 367 | if (!json_tok_streq(buf, status, "paid")) { |
| 368 | return fail_invreq(cmd, ir, |
| 369 | "Previous invoice #%u status %.*s", |
| 370 | *ir->inv->recurrence_counter - 1, |
| 371 | json_tok_full_len(status), |
| 372 | json_tok_full(buf, status)); |
| 373 | } |
| 374 | |
| 375 | /* Decode it */ |
| 376 | b12 = json_get_member(buf, arr + 1, "bolt12"); |
| 377 | if (!b12) { |
| 378 | return fail_internalerr(cmd, ir, |
| 379 | "Previous invoice #%u no bolt12 (%.*s)", |
| 380 | *ir->inv->recurrence_counter - 1, |
| 381 | json_tok_full_len(arr + 1), |
| 382 | json_tok_full(buf, arr + 1)); |
| 383 | } |
| 384 | previnv = invoice_decode(tmpctx, buf + b12->start, b12->end - b12->start, |
| 385 | plugin_feature_set(cmd->plugin), |
| 386 | chainparams, &fail); |
| 387 | if (!previnv) { |
| 388 | return fail_internalerr(cmd, ir, |
| 389 | "Previous invoice %.*s can't decode?", |
| 390 | json_tok_full_len(b12), |
| 391 | json_tok_full(buf, b12)); |
| 392 | } |
| 393 | if (!previnv->recurrence_basetime) { |
| 394 | return fail_internalerr(cmd, ir, |
| 395 | "Previous invoice %.*s no recurrence_basetime?", |
| 396 | json_tok_full_len(b12), json_tok_full(buf, b12)); |
| 397 | } |
| 398 | return check_period(cmd, ir, *previnv->recurrence_basetime); |
| 399 | } |
| 400 | |
| 401 | /* Now, we need to check the previous invoice was paid, and maybe get timebase */ |
| 402 | static struct command_result *check_previous_invoice(struct command *cmd, |
nothing calls this directly
no test coverage detected