| 5969 | } |
| 5970 | |
| 5971 | bool wallet_offer_create(struct wallet *w, |
| 5972 | const struct sha256 *offer_id, |
| 5973 | const char *bolt12, |
| 5974 | const struct json_escape *label, |
| 5975 | enum offer_status status, |
| 5976 | bool force_paths) |
| 5977 | { |
| 5978 | struct db_stmt *stmt; |
| 5979 | |
| 5980 | assert(offer_status_active(status)); |
| 5981 | |
| 5982 | /* Test if already exists. */ |
| 5983 | stmt = db_prepare_v2(w->db, SQL("SELECT 1" |
| 5984 | " FROM offers" |
| 5985 | " WHERE offer_id = ?;")); |
| 5986 | db_bind_sha256(stmt, offer_id); |
| 5987 | db_query_prepared(stmt); |
| 5988 | |
| 5989 | if (db_step(stmt)) { |
| 5990 | db_col_ignore(stmt, "1"); |
| 5991 | tal_free(stmt); |
| 5992 | return false; |
| 5993 | } |
| 5994 | tal_free(stmt); |
| 5995 | |
| 5996 | stmt = db_prepare_v2(w->db, |
| 5997 | SQL("INSERT INTO offers (" |
| 5998 | " offer_id" |
| 5999 | ", bolt12" |
| 6000 | ", label" |
| 6001 | ", status" |
| 6002 | ", force_paths" |
| 6003 | ") VALUES (?, ?, ?, ?, ?);")); |
| 6004 | |
| 6005 | db_bind_sha256(stmt, offer_id); |
| 6006 | db_bind_text(stmt, bolt12); |
| 6007 | if (label) |
| 6008 | db_bind_json_escape(stmt, label); |
| 6009 | else |
| 6010 | db_bind_null(stmt); |
| 6011 | db_bind_int(stmt, offer_status_in_db(status)); |
| 6012 | db_bind_int(stmt, force_paths); |
| 6013 | db_exec_prepared_v2(take(stmt)); |
| 6014 | return true; |
| 6015 | } |
| 6016 | |
| 6017 | char *wallet_offer_find(const tal_t *ctx, |
| 6018 | struct wallet *w, |
no test coverage detected