| 6231 | } |
| 6232 | |
| 6233 | bool wallet_invoice_request_create(struct wallet *w, |
| 6234 | const struct sha256 *invreq_id, |
| 6235 | const char *bolt12, |
| 6236 | const struct json_escape *label, |
| 6237 | enum offer_status status) |
| 6238 | { |
| 6239 | struct db_stmt *stmt; |
| 6240 | |
| 6241 | assert(offer_status_active(status)); |
| 6242 | |
| 6243 | /* Test if already exists. */ |
| 6244 | stmt = db_prepare_v2(w->db, SQL("SELECT 1" |
| 6245 | " FROM invoicerequests" |
| 6246 | " WHERE invreq_id = ?;")); |
| 6247 | db_bind_sha256(stmt, invreq_id); |
| 6248 | db_query_prepared(stmt); |
| 6249 | |
| 6250 | if (db_step(stmt)) { |
| 6251 | db_col_ignore(stmt, "1"); |
| 6252 | tal_free(stmt); |
| 6253 | return false; |
| 6254 | } |
| 6255 | tal_free(stmt); |
| 6256 | |
| 6257 | stmt = db_prepare_v2(w->db, |
| 6258 | SQL("INSERT INTO invoicerequests (" |
| 6259 | " invreq_id" |
| 6260 | ", bolt12" |
| 6261 | ", label" |
| 6262 | ", status" |
| 6263 | ") VALUES (?, ?, ?, ?);")); |
| 6264 | |
| 6265 | db_bind_sha256(stmt, invreq_id); |
| 6266 | db_bind_text(stmt, bolt12); |
| 6267 | if (label) |
| 6268 | db_bind_json_escape(stmt, label); |
| 6269 | else |
| 6270 | db_bind_null(stmt); |
| 6271 | db_bind_int(stmt, offer_status_in_db(status)); |
| 6272 | db_exec_prepared_v2(take(stmt)); |
| 6273 | return true; |
| 6274 | } |
| 6275 | |
| 6276 | char *wallet_invoice_request_find(const tal_t *ctx, |
| 6277 | struct wallet *w, |
no test coverage detected