| 628 | } |
| 629 | |
| 630 | static struct command_result *listoffers_done(struct command *cmd, |
| 631 | const char *buf, |
| 632 | const jsmntok_t *result, |
| 633 | struct invreq *ir) |
| 634 | { |
| 635 | const jsmntok_t *arr = json_get_member(buf, result, "offers"); |
| 636 | const jsmntok_t *offertok, *activetok, *b12tok; |
| 637 | bool active; |
| 638 | char *fail; |
| 639 | struct command_result *err; |
| 640 | struct amount_msat amt; |
| 641 | |
| 642 | /* BOLT-offers #12: |
| 643 | * |
| 644 | * - MUST fail the request if the `offer_id` does not refer to an |
| 645 | * unexpired offer. |
| 646 | */ |
| 647 | if (arr->size == 0) |
| 648 | return fail_invreq(cmd, ir, "Unknown offer"); |
| 649 | |
| 650 | offertok = arr + 1; |
| 651 | |
| 652 | activetok = json_get_member(buf, offertok, "active"); |
| 653 | if (!activetok) { |
| 654 | return fail_internalerr(cmd, ir, |
| 655 | "Missing active: %.*s", |
| 656 | json_tok_full_len(offertok), |
| 657 | json_tok_full(buf, offertok)); |
| 658 | } |
| 659 | json_to_bool(buf, activetok, &active); |
| 660 | if (!active) |
| 661 | return fail_invreq(cmd, ir, "Offer no longer available"); |
| 662 | |
| 663 | b12tok = json_get_member(buf, offertok, "bolt12"); |
| 664 | if (!b12tok) { |
| 665 | return fail_internalerr(cmd, ir, |
| 666 | "Missing bolt12: %.*s", |
| 667 | json_tok_full_len(offertok), |
| 668 | json_tok_full(buf, offertok)); |
| 669 | } |
| 670 | ir->offer = offer_decode(ir, |
| 671 | buf + b12tok->start, |
| 672 | b12tok->end - b12tok->start, |
| 673 | plugin_feature_set(cmd->plugin), |
| 674 | chainparams, &fail); |
| 675 | if (!ir->offer) { |
| 676 | return fail_internalerr(cmd, ir, |
| 677 | "Invalid offer: %s (%.*s)", |
| 678 | fail, |
| 679 | json_tok_full_len(offertok), |
| 680 | json_tok_full(buf, offertok)); |
| 681 | } |
| 682 | |
| 683 | if (ir->offer->absolute_expiry |
| 684 | && time_now().ts.tv_sec >= *ir->offer->absolute_expiry) { |
| 685 | /* FIXME: do deloffer to disable it */ |
| 686 | return fail_invreq(cmd, ir, "Offer expired"); |
| 687 | } |
nothing calls this directly
no test coverage detected