| 6171 | } |
| 6172 | |
| 6173 | bool wallet_invoice_request_create(struct wallet *w, |
| 6174 | const struct sha256 *invreq_id, |
| 6175 | const char *bolt12, |
| 6176 | const struct json_escape *label, |
| 6177 | enum offer_status status) |
| 6178 | { |
| 6179 | struct db_stmt *stmt; |
| 6180 | |
| 6181 | assert(offer_status_active(status)); |
| 6182 | |
| 6183 | /* Test if already exists. */ |
| 6184 | stmt = db_prepare_v2(w->db, SQL("SELECT 1" |
| 6185 | " FROM invoicerequests" |
| 6186 | " WHERE invreq_id = ?;")); |
| 6187 | db_bind_sha256(stmt, invreq_id); |
| 6188 | db_query_prepared(stmt); |
| 6189 | |
| 6190 | if (db_step(stmt)) { |
| 6191 | db_col_ignore(stmt, "1"); |
| 6192 | tal_free(stmt); |
| 6193 | return false; |
| 6194 | } |
| 6195 | tal_free(stmt); |
| 6196 | |
| 6197 | stmt = db_prepare_v2(w->db, |
| 6198 | SQL("INSERT INTO invoicerequests (" |
| 6199 | " invreq_id" |
| 6200 | ", bolt12" |
| 6201 | ", label" |
| 6202 | ", status" |
| 6203 | ") VALUES (?, ?, ?, ?);")); |
| 6204 | |
| 6205 | db_bind_sha256(stmt, invreq_id); |
| 6206 | db_bind_text(stmt, bolt12); |
| 6207 | if (label) |
| 6208 | db_bind_json_escape(stmt, label); |
| 6209 | else |
| 6210 | db_bind_null(stmt); |
| 6211 | db_bind_int(stmt, offer_status_in_db(status)); |
| 6212 | db_exec_prepared_v2(take(stmt)); |
| 6213 | return true; |
| 6214 | } |
| 6215 | |
| 6216 | char *wallet_invoice_request_find(const tal_t *ctx, |
| 6217 | struct wallet *w, |
no test coverage detected