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

Function trigger_expiration

wallet/invoices.c:167–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165};
166
167static void trigger_expiration(struct invoices *invoices)
168{
169 struct list_head idlist;
170 struct invoice_id_node *idn;
171 u64 now = time_now().ts.tv_sec;
172 struct db_stmt *stmt;
173 struct invoice i;
174
175 /* Free current expiration timer */
176 invoices->expiration_timer = tal_free(invoices->expiration_timer);
177
178 /* Acquire all expired invoices and save them in a list */
179 list_head_init(&idlist);
180 stmt = db_prepare_v2(invoices->db, SQL("SELECT id"
181 " FROM invoices"
182 " WHERE state = ?"
183 " AND expiry_time <= ?"));
184 db_bind_int(stmt, 0, UNPAID);
185 db_bind_u64(stmt, 1, now);
186 db_query_prepared(stmt);
187
188 while (db_step(stmt)) {
189 idn = tal(tmpctx, struct invoice_id_node);
190 list_add_tail(&idlist, &idn->list);
191 idn->id = db_col_u64(stmt, "id");
192 }
193 tal_free(stmt);
194
195 /* Expire all those invoices */
196 update_db_expirations(invoices, now);
197
198 /* Trigger expirations */
199 list_for_each(&idlist, idn, list) {
200 /* Trigger expiration */
201 i.id = idn->id;
202 trigger_invoice_waiter_expire_or_delete(invoices, idn->id, &i);
203 }
204
205 install_expiration_timer(invoices);
206}
207
208static void install_expiration_timer(struct invoices *invoices)
209{

Callers

nothing calls this directly

Calls 11

time_nowFunction · 0.85
tal_freeFunction · 0.85
list_head_initFunction · 0.85
db_bind_intFunction · 0.85
db_bind_u64Function · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_u64Function · 0.85
update_db_expirationsFunction · 0.85
install_expiration_timerFunction · 0.85

Tested by

no test coverage detected