| 549 | } |
| 550 | |
| 551 | bool invoices_resolve(struct invoices *invoices, |
| 552 | struct invoice invoice, |
| 553 | struct amount_msat received) |
| 554 | { |
| 555 | struct db_stmt *stmt; |
| 556 | s64 pay_index; |
| 557 | u64 paid_timestamp; |
| 558 | enum invoice_status state = invoice_get_status(invoices, invoice); |
| 559 | |
| 560 | if (state != UNPAID) |
| 561 | return false; |
| 562 | |
| 563 | /* Assign a pay-index. */ |
| 564 | pay_index = get_next_pay_index(invoices->db); |
| 565 | paid_timestamp = time_now().ts.tv_sec; |
| 566 | |
| 567 | /* Update database. */ |
| 568 | stmt = db_prepare_v2(invoices->db, SQL("UPDATE invoices" |
| 569 | " SET state=?" |
| 570 | " , pay_index=?" |
| 571 | " , msatoshi_received=?" |
| 572 | " , paid_timestamp=?" |
| 573 | " WHERE id=?;")); |
| 574 | db_bind_int(stmt, 0, PAID); |
| 575 | db_bind_u64(stmt, 1, pay_index); |
| 576 | db_bind_amount_msat(stmt, 2, &received); |
| 577 | db_bind_u64(stmt, 3, paid_timestamp); |
| 578 | db_bind_u64(stmt, 4, invoice.id); |
| 579 | db_exec_prepared_v2(take(stmt)); |
| 580 | |
| 581 | maybe_mark_offer_used(invoices->db, invoice); |
| 582 | |
| 583 | /* Tell all the waiters about the paid invoice. */ |
| 584 | trigger_invoice_waiter_resolve(invoices, invoice.id, &invoice); |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | /* Called when an invoice waiter is destructed. */ |
| 589 | static void destroy_invoice_waiter(struct invoice_waiter *w) |
no test coverage detected