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

Function prev_payment

lightningd/offer.c:279–368  ·  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 invreq->payer_info tweak. */

Source from the content-addressed store, hash-verified

277/* We do some sanity checks now, since we're looking up prev payment anyway,
278 * but our main purpose is to fill in invreq->payer_info tweak. */
279static struct command_result *prev_payment(struct command *cmd,
280 const char *label,
281 struct tlv_invoice_request *invreq,
282 u64 **prev_basetime)
283{
284 const struct wallet_payment **payments;
285 bool prev_paid = false;
286
287 assert(!invreq->payer_info);
288 payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL);
289
290 for (size_t i = 0; i < tal_count(payments); i++) {
291 const struct tlv_invoice *inv;
292 char *fail;
293
294 /* FIXME: Restrict db queries instead */
295 if (!payments[i]->label || !streq(label, payments[i]->label))
296 continue;
297
298 if (!payments[i]->invstring)
299 continue;
300
301 inv = invoice_decode(tmpctx, payments[i]->invstring,
302 strlen(payments[i]->invstring),
303 NULL, chainparams, &fail);
304 if (!inv)
305 continue;
306
307 /* They can reuse labels across different offers. */
308 if (!sha256_eq(inv->offer_id, invreq->offer_id))
309 continue;
310
311 /* Be paranoid, in case someone inserts their own
312 * clashing label! */
313 if (!inv->recurrence_counter)
314 continue;
315
316 /* BOLT-offers-recurrence #12:
317 * - if the offer contained `recurrence_base` with
318 * `start_any_period` non-zero:
319 * - MUST include `recurrence_start`
320 * - MUST set `period_offset` to the period the sender wants
321 * for the initial request
322 * - MUST set `period_offset` to the same value on all
323 * following requests.
324 */
325 if (invreq->recurrence_start) {
326 if (!inv->recurrence_start)
327 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
328 "unexpected"
329 " recurrence_start");
330 if (*inv->recurrence_start != *invreq->recurrence_start)
331 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
332 "recurrence_start was"
333 " previously %u",
334 *inv->recurrence_start);
335 } else {
336 if (inv->recurrence_start)

Callers 1

Calls 3

wallet_payment_listFunction · 0.85
command_failFunction · 0.70
invoice_decodeFunction · 0.50

Tested by

no test coverage detected