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. */
| 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. */ |
| 319 | static 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) |
no test coverage detected