| 5078 | } |
| 5079 | |
| 5080 | void wallet_offer_mark_used(struct db *db, const struct sha256 *offer_id) |
| 5081 | { |
| 5082 | struct db_stmt *stmt; |
| 5083 | enum offer_status status; |
| 5084 | |
| 5085 | stmt = db_prepare_v2(db, SQL("SELECT status" |
| 5086 | " FROM offers" |
| 5087 | " WHERE offer_id = ?;")); |
| 5088 | db_bind_sha256(stmt, 0, offer_id); |
| 5089 | db_query_prepared(stmt); |
| 5090 | if (!db_step(stmt)) |
| 5091 | fatal("%s: unknown offer_id %s", |
| 5092 | __func__, |
| 5093 | type_to_string(tmpctx, struct sha256, offer_id)); |
| 5094 | |
| 5095 | status = offer_status_in_db(db_col_int(stmt, "status")); |
| 5096 | tal_free(stmt); |
| 5097 | |
| 5098 | if (!offer_status_active(status)) |
| 5099 | fatal("%s: offer_id %s not active: status %i", |
| 5100 | __func__, |
| 5101 | type_to_string(tmpctx, struct sha256, offer_id), |
| 5102 | status); |
| 5103 | |
| 5104 | if (!offer_status_used(status)) { |
| 5105 | enum offer_status newstatus; |
| 5106 | |
| 5107 | if (offer_status_single(status)) |
| 5108 | newstatus = OFFER_SINGLE_USE_USED; |
| 5109 | else |
| 5110 | newstatus = OFFER_MULTIPLE_USE_USED; |
| 5111 | offer_status_update(db, offer_id, status, newstatus); |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | |
| 5116 | /* We join key parts with nuls for now. */ |
no test coverage detected