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

Function handle_amount_and_recurrence

plugins/offers_invreq_hook.c:704–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

702}
703
704static struct command_result *handle_amount_and_recurrence(struct command *cmd,
705 struct invreq *ir,
706 struct amount_msat base_inv_amount)
707{
708 /* BOLT #12:
709 * - if `invreq_amount` is present:
710 * - MUST reject the invoice request if `invreq_amount`.`msat` is less than the
711 * *expected amount*.
712 */
713 if (ir->invreq->offer_amount && ir->invreq->invreq_amount) {
714 if (amount_msat_less(amount_msat(*ir->invreq->invreq_amount), base_inv_amount)) {
715 return fail_invreq(cmd, ir, "Amount must be at least %s",
716 fmt_amount_msat(tmpctx,
717 base_inv_amount));
718 }
719 /* BOLT #12:
720 * - MAY reject the invoice request if `invreq_amount`.`msat` greatly exceeds
721 * the *expected amount*.
722 */
723 /* Much == 5? Easier to divide and compare, than multiply. */
724 if (amount_msat_greater(amount_msat_div(amount_msat(*ir->invreq->invreq_amount), 5),
725 base_inv_amount)) {
726 return fail_invreq(cmd, ir, "Amount vastly exceeds %s",
727 fmt_amount_msat(tmpctx,
728 base_inv_amount));
729 }
730 base_inv_amount = amount_msat(*ir->invreq->invreq_amount);
731 }
732
733 /* BOLT #12:
734 * - if `invreq_amount` is present:
735 * - MUST set `invoice_amount` to `invreq_amount`
736 * - otherwise:
737 * - MUST set `invoice_amount` to the *expected amount*.
738 */
739 /* This may be adjusted by recurrence if proportional_amount set */
740 ir->inv->invoice_amount = tal_dup(ir->inv, u64,
741 &base_inv_amount.millisatoshis); /* Raw: wire protocol */
742
743 /* Last of all, we handle recurrence details, which often requires
744 * further lookups. */
745 if (ir->inv->invreq_recurrence_counter) {
746 return check_previous_invoice(cmd, ir);
747 }
748 /* We're happy with 2 hours timeout (default): they can always
749 * request another. */
750
751 /* FIXME: Fallbacks? */
752 return add_blindedpaths(cmd, ir);
753}
754
755static struct command_result *currency_done(struct command *cmd,
756 const char *method,

Callers 2

currency_doneFunction · 0.85
listoffers_doneFunction · 0.85

Calls 7

amount_msat_greaterFunction · 0.85
amount_msat_divFunction · 0.85
check_previous_invoiceFunction · 0.85
add_blindedpathsFunction · 0.85
amount_msatClass · 0.70
amount_msat_lessFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected