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

Function prev_payment

lightningd/offer.c:319–409  ·  view source on GitHub ↗

We do some sanity checks now, since we're looking up prev payment anyway, * but our main purpose is to fill in prev_basetime tweak. */

Source from the content-addressed store, hash-verified

317/* We do some sanity checks now, since we're looking up prev payment anyway,
318 * but our main purpose is to fill in prev_basetime tweak. */
319static struct command_result *prev_payment(struct command *cmd,
320 const struct json_escape *label,
321 const struct tlv_invoice_request *invreq,
322 u64 **prev_basetime)
323{
324 struct sha256 invreq_oid;
325 u64 last_recurrence = UINT64_MAX;
326 bool prev_unpaid = false;
327
328 invreq_offer_id(invreq, &invreq_oid);
329
330 for (struct db_stmt *stmt = payments_by_label(cmd->ld->wallet, label);
331 stmt;
332 stmt = payments_next(cmd->ld->wallet, stmt)) {
333 const struct wallet_payment *payment;
334 const struct tlv_invoice *inv;
335 const char *fail;
336 struct sha256 inv_oid;
337
338 payment = payment_get_details(tmpctx, stmt);
339 if (!payment->invstring)
340 continue;
341
342 inv = invoice_decode(tmpctx, payment->invstring,
343 strlen(payment->invstring),
344 NULL, chainparams, &fail);
345 if (!inv)
346 continue;
347
348 /* They can reuse labels across different offers. */
349 invoice_offer_id(inv, &inv_oid);
350 if (!sha256_eq(&inv_oid, &invreq_oid))
351 continue;
352
353 /* Be paranoid, in case someone inserts their own
354 * clashing label! */
355 if (!inv->invreq_recurrence_counter)
356 continue;
357
358 /* BOLT-recurrence #12:
359 * - if `offer_recurrence_base` is present:
360 * - MUST include `invreq_recurrence_start`
361 * - MUST set `period_offset` to the period the sender wants for the
362 * initial request
363 * - MUST set `period_offset` to the same value on all following requests.
364 */
365 if (inv->invreq_recurrence_start
366 && invreq->invreq_recurrence_start
367 && *inv->invreq_recurrence_start != *invreq->invreq_recurrence_start) {
368 tal_free(stmt);
369 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
370 "recurrence_start was"
371 " previously %u",
372 *inv->invreq_recurrence_start);
373 }
374
375 /* They should all have the same basetime */
376 if (!*prev_basetime)

Callers 1

Calls 8

invreq_offer_idFunction · 0.85
payments_by_labelFunction · 0.85
payments_nextFunction · 0.85
payment_get_detailsFunction · 0.85
invoice_decodeFunction · 0.85
invoice_offer_idFunction · 0.85
tal_freeFunction · 0.85
command_failFunction · 0.70

Tested by

no test coverage detected