| 262 | } |
| 263 | |
| 264 | bool invoices_create(struct invoices *invoices, |
| 265 | u64 *inv_dbid, |
| 266 | const struct amount_msat *msat TAKES, |
| 267 | const struct json_escape *label TAKES, |
| 268 | u64 expiry, |
| 269 | const char *b11enc, |
| 270 | const char *description, |
| 271 | const u8 *features, |
| 272 | const struct preimage *r, |
| 273 | const struct sha256 *rhash, |
| 274 | const struct sha256 *local_offer_id) |
| 275 | { |
| 276 | struct db_stmt *stmt; |
| 277 | u64 expiry_time; |
| 278 | u64 now = clock_time().ts.tv_sec; |
| 279 | |
| 280 | if (invoices_find_by_label(invoices, inv_dbid, label)) { |
| 281 | tal_free_if_taken(msat); |
| 282 | tal_free_if_taken(label); |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | /* Compute expiration. */ |
| 287 | expiry_time = now + expiry; |
| 288 | |
| 289 | *inv_dbid = invoice_index_created(invoices->wallet->ld, UNPAID, label, b11enc); |
| 290 | |
| 291 | /* Save to database. */ |
| 292 | stmt = db_prepare_v2( |
| 293 | invoices->wallet->db, |
| 294 | SQL("INSERT INTO invoices" |
| 295 | " ( id, payment_hash, payment_key, state" |
| 296 | " , msatoshi, label, expiry_time" |
| 297 | " , pay_index, msatoshi_received" |
| 298 | " , paid_timestamp, bolt11, description, features, local_offer_id)" |
| 299 | " VALUES ( ?, ?, ?, ?" |
| 300 | " , ?, ?, ?" |
| 301 | " , NULL, NULL" |
| 302 | " , NULL, ?, ?, ?, ?);")); |
| 303 | |
| 304 | db_bind_u64(stmt, *inv_dbid); |
| 305 | db_bind_sha256(stmt, rhash); |
| 306 | db_bind_preimage(stmt, r); |
| 307 | db_bind_int(stmt, UNPAID); |
| 308 | if (msat) |
| 309 | db_bind_amount_msat(stmt, *msat); |
| 310 | else |
| 311 | db_bind_null(stmt); |
| 312 | db_bind_json_escape(stmt, label); |
| 313 | db_bind_u64(stmt, expiry_time); |
| 314 | db_bind_text(stmt, b11enc); |
| 315 | if (!description) |
| 316 | db_bind_null(stmt); |
| 317 | else |
| 318 | db_bind_text(stmt, description); |
| 319 | db_bind_talarr(stmt, features); |
| 320 | if (local_offer_id) |
| 321 | db_bind_sha256(stmt, local_offer_id); |
nothing calls this directly
no test coverage detected