| 6029 | } |
| 6030 | |
| 6031 | bool wallet_offer_create(struct wallet *w, |
| 6032 | const struct sha256 *offer_id, |
| 6033 | const char *bolt12, |
| 6034 | const struct json_escape *label, |
| 6035 | enum offer_status status, |
| 6036 | bool force_paths) |
| 6037 | { |
| 6038 | struct db_stmt *stmt; |
| 6039 | |
| 6040 | assert(offer_status_active(status)); |
| 6041 | |
| 6042 | /* Test if already exists. */ |
| 6043 | stmt = db_prepare_v2(w->db, SQL("SELECT 1" |
| 6044 | " FROM offers" |
| 6045 | " WHERE offer_id = ?;")); |
| 6046 | db_bind_sha256(stmt, offer_id); |
| 6047 | db_query_prepared(stmt); |
| 6048 | |
| 6049 | if (db_step(stmt)) { |
| 6050 | db_col_ignore(stmt, "1"); |
| 6051 | tal_free(stmt); |
| 6052 | return false; |
| 6053 | } |
| 6054 | tal_free(stmt); |
| 6055 | |
| 6056 | stmt = db_prepare_v2(w->db, |
| 6057 | SQL("INSERT INTO offers (" |
| 6058 | " offer_id" |
| 6059 | ", bolt12" |
| 6060 | ", label" |
| 6061 | ", status" |
| 6062 | ", force_paths" |
| 6063 | ") VALUES (?, ?, ?, ?, ?);")); |
| 6064 | |
| 6065 | db_bind_sha256(stmt, offer_id); |
| 6066 | db_bind_text(stmt, bolt12); |
| 6067 | if (label) |
| 6068 | db_bind_json_escape(stmt, label); |
| 6069 | else |
| 6070 | db_bind_null(stmt); |
| 6071 | db_bind_int(stmt, offer_status_in_db(status)); |
| 6072 | db_bind_int(stmt, force_paths); |
| 6073 | db_exec_prepared_v2(take(stmt)); |
| 6074 | return true; |
| 6075 | } |
| 6076 | |
| 6077 | char *wallet_offer_find(const tal_t *ctx, |
| 6078 | struct wallet *w, |
no test coverage detected