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

Function invoices_create

wallet/invoices.c:256–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256bool invoices_create(struct invoices *invoices,
257 struct invoice *pinvoice,
258 const struct amount_msat *msat TAKES,
259 const struct json_escape *label TAKES,
260 u64 expiry,
261 const char *b11enc,
262 const char *description,
263 const u8 *features,
264 const struct preimage *r,
265 const struct sha256 *rhash,
266 const struct sha256 *local_offer_id)
267{
268 struct db_stmt *stmt;
269 struct invoice dummy;
270 u64 expiry_time;
271 u64 now = time_now().ts.tv_sec;
272
273 if (invoices_find_by_label(invoices, &dummy, label)) {
274 if (taken(msat))
275 tal_free(msat);
276 if (taken(label))
277 tal_free(label);
278 return false;
279 }
280
281 /* Compute expiration. */
282 expiry_time = now + expiry;
283
284 /* Save to database. */
285 stmt = db_prepare_v2(
286 invoices->db,
287 SQL("INSERT INTO invoices"
288 " ( payment_hash, payment_key, state"
289 " , msatoshi, label, expiry_time"
290 " , pay_index, msatoshi_received"
291 " , paid_timestamp, bolt11, description, features, local_offer_id)"
292 " VALUES ( ?, ?, ?"
293 " , ?, ?, ?"
294 " , NULL, NULL"
295 " , NULL, ?, ?, ?, ?);"));
296
297 db_bind_sha256(stmt, 0, rhash);
298 db_bind_preimage(stmt, 1, r);
299 db_bind_int(stmt, 2, UNPAID);
300 if (msat)
301 db_bind_amount_msat(stmt, 3, msat);
302 else
303 db_bind_null(stmt, 3);
304 db_bind_json_escape(stmt, 4, label);
305 db_bind_u64(stmt, 5, expiry_time);
306 db_bind_text(stmt, 6, b11enc);
307 if (!description)
308 db_bind_null(stmt, 7);
309 else
310 db_bind_text(stmt, 7, description);
311 db_bind_talarr(stmt, 8, features);
312 if (local_offer_id)
313 db_bind_sha256(stmt, 9, local_offer_id);

Callers 1

wallet_invoice_createFunction · 0.70

Calls 15

time_nowFunction · 0.85
takenFunction · 0.85
tal_freeFunction · 0.85
db_bind_sha256Function · 0.85
db_bind_preimageFunction · 0.85
db_bind_intFunction · 0.85
db_bind_amount_msatFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_json_escapeFunction · 0.85
db_bind_u64Function · 0.85
db_bind_textFunction · 0.85
db_bind_talarrFunction · 0.85

Tested by

no test coverage detected