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

Function install_expiration_timer

wallet/invoices.c:208–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208static void install_expiration_timer(struct invoices *invoices)
209{
210 bool res;
211 struct db_stmt *stmt;
212 struct timerel rel;
213 struct timeabs expiry;
214 struct timeabs now = time_now();
215
216 assert(!invoices->expiration_timer);
217
218 /* Find unpaid invoice with nearest expiry time */
219 stmt = db_prepare_v2(invoices->db, SQL("SELECT MIN(expiry_time)"
220 " FROM invoices"
221 " WHERE state = ?;"));
222 db_bind_int(stmt, 0, UNPAID);
223
224 db_query_prepared(stmt);
225
226 res = db_step(stmt);
227 assert(res);
228
229 if (db_col_is_null(stmt, "MIN(expiry_time)"))
230 /* Nothing to install */
231 goto done;
232
233 invoices->min_expiry_time = db_col_u64(stmt,
234 "MIN(expiry_time)");
235
236 memset(&expiry, 0, sizeof(expiry));
237 expiry.ts.tv_sec = invoices->min_expiry_time;
238
239 /* now > expiry */
240 if (time_after(now, expiry))
241 expiry = now;
242
243 /* rel = expiry - now */
244 rel = time_between(expiry, now);
245
246 /* Have it called at indicated timerel. */
247 invoices->expiration_timer = new_reltimer(invoices->timers,
248 invoices,
249 rel,
250 &trigger_expiration,
251 invoices);
252done:
253 tal_free(stmt);
254}
255
256bool invoices_create(struct invoices *invoices,
257 struct invoice *pinvoice,

Callers 3

invoices_newFunction · 0.85
trigger_expirationFunction · 0.85
invoices_createFunction · 0.85

Calls 9

time_nowFunction · 0.85
db_bind_intFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_is_nullFunction · 0.85
db_col_u64Function · 0.85
time_afterFunction · 0.85
time_betweenFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected