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

Function wallet_payment_set_status

wallet/wallet.c:3336–3396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3334}
3335
3336void wallet_payment_set_status(struct wallet *wallet,
3337 const struct sha256 *payment_hash,
3338 u64 partid, u64 groupid,
3339 const enum wallet_payment_status newstatus,
3340 const struct preimage *preimage)
3341{
3342 struct db_stmt *stmt;
3343 struct wallet_payment *payment;
3344 u32 completed_at = 0;
3345
3346 if (newstatus != PAYMENT_PENDING)
3347 completed_at = time_now().ts.tv_sec;
3348
3349 /* We can only fail an unstored payment! */
3350 payment = find_unstored_payment(wallet, payment_hash, partid);
3351 if (payment) {
3352 assert(newstatus == PAYMENT_FAILED);
3353 tal_free(payment);
3354 return;
3355 }
3356
3357 stmt = db_prepare_v2(wallet->db,
3358 SQL("UPDATE payments SET status=?, completed_at=? "
3359 "WHERE payment_hash=? AND partid=? AND groupid=?"));
3360
3361 db_bind_int(stmt, 0, wallet_payment_status_in_db(newstatus));
3362 if (completed_at != 0) {
3363 db_bind_u64(stmt, 1, completed_at);
3364 } else {
3365 db_bind_null(stmt, 1);
3366 }
3367 db_bind_sha256(stmt, 2, payment_hash);
3368 db_bind_u64(stmt, 3, partid);
3369 db_bind_u64(stmt, 4, groupid);
3370 db_exec_prepared_v2(take(stmt));
3371
3372 if (preimage) {
3373 stmt = db_prepare_v2(wallet->db,
3374 SQL("UPDATE payments SET payment_preimage=? "
3375 "WHERE payment_hash=? AND partid=? AND groupid=?"));
3376
3377 db_bind_preimage(stmt, 0, preimage);
3378 db_bind_sha256(stmt, 1, payment_hash);
3379 db_bind_u64(stmt, 2, partid);
3380 db_bind_u64(stmt, 3, groupid);
3381 db_exec_prepared_v2(take(stmt));
3382 }
3383 if (newstatus != PAYMENT_PENDING) {
3384 stmt =
3385 db_prepare_v2(wallet->db, SQL("UPDATE payments"
3386 " SET path_secrets = NULL"
3387 " , route_nodes = NULL"
3388 " , route_channels = NULL"
3389 " WHERE payment_hash = ?"
3390 " AND partid = ? AND groupid=?;"));
3391 db_bind_sha256(stmt, 0, payment_hash);
3392 db_bind_u64(stmt, 1, partid);
3393 db_bind_u64(stmt, 2, groupid);

Callers 3

test_payment_crudFunction · 0.85
payment_succeededFunction · 0.85
payment_failedFunction · 0.85

Calls 10

time_nowFunction · 0.85
find_unstored_paymentFunction · 0.85
tal_freeFunction · 0.85
db_bind_intFunction · 0.85
db_bind_u64Function · 0.85
db_bind_nullFunction · 0.85
db_bind_sha256Function · 0.85
db_exec_prepared_v2Function · 0.85
db_bind_preimageFunction · 0.85

Tested by 1

test_payment_crudFunction · 0.68