| 423 | } |
| 424 | |
| 425 | static struct command_result *check_period(struct command *cmd, |
| 426 | struct invreq *ir, |
| 427 | u64 basetime) |
| 428 | { |
| 429 | u64 period_idx; |
| 430 | u64 paywindow_start, paywindow_end; |
| 431 | struct command_result *err; |
| 432 | |
| 433 | /* If we have a recurrence base, that overrides. */ |
| 434 | if (ir->invreq->offer_recurrence_base) |
| 435 | basetime = ir->invreq->offer_recurrence_base->basetime; |
| 436 | |
| 437 | /* BOLT-recurrence #12: |
| 438 | * - if `offer_recurrence_optional` or `offer_recurrence_compulsory` |
| 439 | * are present: |
| 440 | * - MUST set `invoice_recurrence_basetime`.`basetime` to the |
| 441 | * start of period #0 as calculated by |
| 442 | * [Period Calculation](#offer-period-calculation). |
| 443 | */ |
| 444 | ir->inv->invoice_recurrence_basetime = tal_dup(ir->inv, u64, &basetime); |
| 445 | |
| 446 | period_idx = *ir->invreq->invreq_recurrence_counter; |
| 447 | |
| 448 | /* BOLT-recurrence #12: |
| 449 | * - if `offer_recurrence_base` is present: |
| 450 | * - MUST reject the invoice request if there is no `invreq_recurrence_start` |
| 451 | * field. |
| 452 | * - MUST consider the period index for this request to be the |
| 453 | * `invreq_recurrence_start` field plus the `invreq_recurrence_counter` |
| 454 | * `counter` field. |
| 455 | */ |
| 456 | if (ir->invreq->offer_recurrence_base) { |
| 457 | err = invreq_must_have(cmd, ir, invreq_recurrence_start); |
| 458 | if (err) { |
| 459 | plugin_log(cmd->plugin, LOG_BROKEN, "MISSING invreq_recurrence_start!"); |
| 460 | return err; |
| 461 | } |
| 462 | period_idx += *ir->invreq->invreq_recurrence_start; |
| 463 | } else { |
| 464 | /* BOLT-recurrence #12: |
| 465 | * |
| 466 | * - otherwise: |
| 467 | * - MUST reject the invoice request if there is a `invreq_recurrence_start` |
| 468 | * field. |
| 469 | * - MUST consider the period index for this request to be the |
| 470 | * `invreq_recurrence_counter` `counter` field. |
| 471 | */ |
| 472 | err = invreq_must_not_have(cmd, ir, invreq_recurrence_start); |
| 473 | if (err) |
| 474 | return err; |
| 475 | } |
| 476 | |
| 477 | /* BOLT-recurrence #12: |
| 478 | * - if `offer_recurrence_limit` is present: |
| 479 | * - MUST reject the invoice request if the period index is greater than |
| 480 | * `max_period_index`. |
| 481 | */ |
| 482 | if (ir->invreq->offer_recurrence_limit |
no test coverage detected