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

Function check_period

plugins/offers_invreq_hook.c:226–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226static struct command_result *check_period(struct command *cmd,
227 struct invreq *ir,
228 u64 basetime)
229{
230 u64 period_idx;
231 u64 paywindow_start, paywindow_end;
232 struct command_result *err;
233
234 /* If we have a recurrence base, that overrides. */
235 if (ir->offer->recurrence_base)
236 basetime = ir->offer->recurrence_base->basetime;
237
238 /* BOLT-offers-recurrence #12:
239 * - if the invoice corresponds to an offer with `recurrence`:
240 * - MUST set `recurrence_basetime` to the start of period #0 as
241 * calculated by [Period Calculation](#offer-period-calculation).
242 */
243 ir->inv->recurrence_basetime = tal_dup(ir->inv, u64, &basetime);
244
245 period_idx = *ir->invreq->recurrence_counter;
246
247 /* BOLT-offers-recurrence #12:
248 * - if the offer had `recurrence_base` and `start_any_period`
249 * was 1:
250 * - MUST fail the request if there is no `recurrence_start`
251 * field.
252 * - MUST consider the period index for this request to be the
253 * `recurrence_start` field plus the `recurrence_counter`
254 * `counter` field.
255 */
256 if (ir->offer->recurrence_base
257 && ir->offer->recurrence_base->start_any_period) {
258 err = invreq_must_have(cmd, ir, recurrence_start);
259 if (err)
260 return err;
261 period_idx += *ir->invreq->recurrence_start;
262
263 /* BOLT-offers-recurrence #12:
264 * - MUST set (or not set) `recurrence_start` exactly as the
265 * invoice_request did.
266 */
267 ir->inv->recurrence_start
268 = tal_dup(ir->inv, u32, ir->invreq->recurrence_start);
269 } else {
270 /* BOLT-offers-recurrence #12:
271 *
272 * - otherwise:
273 * - MUST fail the request if there is a `recurrence_start`
274 * field.
275 * - MUST consider the period index for this request to be the
276 * `recurrence_counter` `counter` field.
277 */
278 err = invreq_must_not_have(cmd, ir, recurrence_start);
279 if (err)
280 return err;
281 }
282
283 /* BOLT-offers-recurrence #12:

Callers 2

prev_invoice_doneFunction · 0.85
check_previous_invoiceFunction · 0.85

Calls 4

offer_period_paywindowFunction · 0.85
set_recurring_inv_expiryFunction · 0.85
offer_period_startFunction · 0.85
create_invoicereqFunction · 0.85

Tested by

no test coverage detected