MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_offer_create

Function wallet_offer_create

wallet/wallet.c:4935–4976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4933}
4934
4935bool wallet_offer_create(struct wallet *w,
4936 const struct sha256 *offer_id,
4937 const char *bolt12,
4938 const struct json_escape *label,
4939 enum offer_status status)
4940{
4941 struct db_stmt *stmt;
4942
4943 assert(offer_status_active(status));
4944
4945 /* Test if already exists. */
4946 stmt = db_prepare_v2(w->db, SQL("SELECT 1"
4947 " FROM offers"
4948 " WHERE offer_id = ?;"));
4949 db_bind_sha256(stmt, 0, offer_id);
4950 db_query_prepared(stmt);
4951
4952 if (db_step(stmt)) {
4953 db_col_ignore(stmt, "1");
4954 tal_free(stmt);
4955 return false;
4956 }
4957 tal_free(stmt);
4958
4959 stmt = db_prepare_v2(w->db,
4960 SQL("INSERT INTO offers ("
4961 " offer_id"
4962 ", bolt12"
4963 ", label"
4964 ", status"
4965 ") VALUES (?, ?, ?, ?);"));
4966
4967 db_bind_sha256(stmt, 0, offer_id);
4968 db_bind_text(stmt, 1, bolt12);
4969 if (label)
4970 db_bind_json_escape(stmt, 2, label);
4971 else
4972 db_bind_null(stmt, 2);
4973 db_bind_int(stmt, 3, offer_status_in_db(status));
4974 db_exec_prepared_v2(take(stmt));
4975 return true;
4976}
4977
4978char *wallet_offer_find(const tal_t *ctx,
4979 struct wallet *w,

Callers 1

json_createofferFunction · 0.85

Calls 12

offer_status_activeFunction · 0.85
db_bind_sha256Function · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_ignoreFunction · 0.85
tal_freeFunction · 0.85
db_bind_textFunction · 0.85
db_bind_json_escapeFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_intFunction · 0.85
offer_status_in_dbFunction · 0.85
db_exec_prepared_v2Function · 0.85

Tested by

no test coverage detected