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

Function install_expiration_timer

wallet/invoices.c:211–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211static void install_expiration_timer(struct invoices *invoices)
212{
213 bool res;
214 struct db_stmt *stmt;
215 struct timerel rel;
216 struct timeabs expiry;
217 struct timeabs now = clock_time();
218
219 assert(!invoices->expiration_timer);
220
221 /* Find unpaid invoice with nearest expiry time */
222 stmt = db_prepare_v2(invoices->wallet->db, SQL("SELECT MIN(expiry_time)"
223 " FROM invoices"
224 " WHERE state = ?;"));
225 db_bind_int(stmt, UNPAID);
226
227 db_query_prepared(stmt);
228
229 res = db_step(stmt);
230 assert(res);
231
232 if (db_col_is_null(stmt, "MIN(expiry_time)"))
233 /* Nothing to install */
234 goto done;
235
236 invoices->min_expiry_time = db_col_u64(stmt,
237 "MIN(expiry_time)");
238
239 memset(&expiry, 0, sizeof(expiry));
240 expiry.ts.tv_sec = invoices->min_expiry_time;
241
242 /* Hi! On a 32 bit time_t platform with an expiry after 2038? Let's
243 * not set a timer, assuming you'll upgrade before then! */
244 if (expiry.ts.tv_sec != invoices->min_expiry_time)
245 goto done;
246
247 /* now > expiry */
248 if (time_after(now, expiry))
249 expiry = now;
250
251 /* rel = expiry - now */
252 rel = time_between(expiry, now);
253
254 /* Have it called at indicated timerel. */
255 invoices->expiration_timer = new_reltimer(invoices->timers,
256 invoices,
257 rel,
258 &trigger_expiration,
259 invoices);
260done:
261 tal_free(stmt);
262}
263
264bool invoices_create(struct invoices *invoices,
265 u64 *inv_dbid,

Callers 2

trigger_expirationFunction · 0.85
invoices_createFunction · 0.85

Calls 9

clock_timeFunction · 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