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

Function listoffers_done

plugins/offers_invreq_hook.c:630–828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628}
629
630static 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 }

Callers

nothing calls this directly

Calls 13

offer_decodeFunction · 0.85
plugin_feature_setFunction · 0.85
time_nowFunction · 0.85
check_payer_sigFunction · 0.85
convert_currencyFunction · 0.85
fail_internalerrFunction · 0.70
sha256Class · 0.70
json_get_memberFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected