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

Function wallet_payment_store

wallet/wallet.c:3033–3147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3031}
3032
3033void wallet_payment_store(struct wallet *wallet,
3034 struct wallet_payment *payment TAKES)
3035{
3036 struct db_stmt *stmt;
3037 if (!find_unstored_payment(wallet, &payment->payment_hash, payment->partid)) {
3038 /* Already stored on-disk */
3039#if DEVELOPER
3040 /* Double-check that it is indeed stored to disk
3041 * (catch bug, where we call this on a payment_hash
3042 * we never paid to) */
3043 bool res;
3044 stmt =
3045 db_prepare_v2(wallet->db, SQL("SELECT status FROM payments"
3046 " WHERE payment_hash=?"
3047 " AND partid = ? AND groupid = ?;"));
3048 db_bind_sha256(stmt, 0, &payment->payment_hash);
3049 db_bind_u64(stmt, 1, payment->partid);
3050 db_bind_u64(stmt, 2, payment->groupid);
3051 db_query_prepared(stmt);
3052 res = db_step(stmt);
3053 assert(res);
3054 db_col_ignore(stmt, "status");
3055 tal_free(stmt);
3056#endif
3057 return;
3058 }
3059
3060 /* Don't attempt to add the same payment twice */
3061 assert(!payment->id);
3062
3063 stmt = db_prepare_v2(
3064 wallet->db,
3065 SQL("INSERT INTO payments ("
3066 " status,"
3067 " payment_hash,"
3068 " destination,"
3069 " msatoshi,"
3070 " timestamp,"
3071 " path_secrets,"
3072 " route_nodes,"
3073 " route_channels,"
3074 " msatoshi_sent,"
3075 " description,"
3076 " bolt11,"
3077 " total_msat,"
3078 " partid,"
3079 " local_offer_id,"
3080 " groupid,"
3081 " paydescription"
3082 ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
3083
3084 db_bind_int(stmt, 0, payment->status);
3085 db_bind_sha256(stmt, 1, &payment->payment_hash);
3086
3087 if (payment->destination != NULL)
3088 db_bind_node_id(stmt, 2, payment->destination);
3089 else
3090 db_bind_null(stmt, 2);

Callers 2

test_payment_crudFunction · 0.85
payment_storeFunction · 0.85

Calls 15

find_unstored_paymentFunction · 0.85
db_bind_sha256Function · 0.85
db_bind_u64Function · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_ignoreFunction · 0.85
tal_freeFunction · 0.85
db_bind_intFunction · 0.85
db_bind_node_idFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_amount_msatFunction · 0.85
db_bind_secret_arrFunction · 0.85

Tested by 1

test_payment_crudFunction · 0.68