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

Function invoices_resolve

wallet/invoices.c:551–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

549}
550
551bool 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. */
589static void destroy_invoice_waiter(struct invoice_waiter *w)

Callers 1

wallet_invoice_resolveFunction · 0.70

Calls 9

invoice_get_statusFunction · 0.85
get_next_pay_indexFunction · 0.85
time_nowFunction · 0.85
db_bind_intFunction · 0.85
db_bind_u64Function · 0.85
db_bind_amount_msatFunction · 0.85
db_exec_prepared_v2Function · 0.85
maybe_mark_offer_usedFunction · 0.85

Tested by

no test coverage detected