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

Function handle_amount_and_recurrence

plugins/offers_invreq_hook.c:502–557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500}
501
502static struct command_result *handle_amount_and_recurrence(struct command *cmd,
503 struct invreq *ir,
504 struct amount_msat base_inv_amount)
505{
506 /* BOLT-offers #12:
507 * - if the offer included `amount`:
508 *...
509 * - if the request contains `amount`:
510 * - MUST fail the request if its `amount` is less than the
511 * *base invoice amount*.
512 */
513 if (ir->offer->amount && ir->invreq->amount) {
514 if (amount_msat_less(amount_msat(*ir->invreq->amount), base_inv_amount)) {
515 return fail_invreq(cmd, ir, "Amount must be at least %s",
516 type_to_string(tmpctx, struct amount_msat,
517 &base_inv_amount));
518 }
519 /* BOLT-offers #12:
520 * - MAY fail the request if its `amount` is much greater than
521 * the *base invoice amount*.
522 */
523 /* Much == 5? Easier to divide and compare, than multiply. */
524 if (amount_msat_greater(amount_msat_div(amount_msat(*ir->invreq->amount), 5),
525 base_inv_amount)) {
526 return fail_invreq(cmd, ir, "Amount vastly exceeds %s",
527 type_to_string(tmpctx, struct amount_msat,
528 &base_inv_amount));
529 }
530 /* BOLT-offers #12:
531 * - MUST use the request's `amount` as the *base invoice
532 * amount*.
533 */
534 base_inv_amount = amount_msat(*ir->invreq->amount);
535 }
536
537 /* This may be adjusted by recurrence if proportional_amount set */
538 ir->inv->amount = tal_dup(ir->inv, u64,
539 &base_inv_amount.millisatoshis); /* Raw: wire protocol */
540
541 /* Last of all, we handle recurrence details, which often requires
542 * further lookups. */
543
544 /* BOLT-offers-recurrence #12:
545 * - MUST set (or not set) `recurrence_counter` exactly as the
546 * invoice_request did.
547 */
548 if (ir->invreq->recurrence_counter) {
549 ir->inv->recurrence_counter = ir->invreq->recurrence_counter;
550 return check_previous_invoice(cmd, ir);
551 }
552 /* We're happy with 2 hours timeout (default): they can always
553 * request another. */
554
555 /* FIXME: Fallbacks? */
556 return create_invoicereq(cmd, ir);
557}
558
559static struct command_result *currency_done(struct command *cmd,

Callers 2

currency_doneFunction · 0.85
listoffers_doneFunction · 0.85

Calls 7

amount_msat_lessFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_divFunction · 0.85
check_previous_invoiceFunction · 0.85
create_invoicereqFunction · 0.85
amount_msatClass · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected