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

Function wallet_htlc_save_out

wallet/wallet.c:2442–2508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2440}
2441
2442void wallet_htlc_save_out(struct wallet *wallet,
2443 const struct channel *chan,
2444 struct htlc_out *out)
2445{
2446 struct db_stmt *stmt;
2447
2448 /* We absolutely need the incoming HTLC to be persisted before
2449 * we can persist it's dependent */
2450 assert(out->in == NULL || out->in->dbid != 0);
2451
2452 stmt = db_prepare_v2(
2453 wallet->db,
2454 SQL("INSERT INTO channel_htlcs ("
2455 " channel_id,"
2456 " channel_htlc_id,"
2457 " direction,"
2458 " origin_htlc,"
2459 " msatoshi,"
2460 " cltv_expiry,"
2461 " payment_hash,"
2462 " payment_key,"
2463 " hstate,"
2464 " routing_onion,"
2465 " malformed_onion,"
2466 " partid,"
2467 " groupid,"
2468 " fees_msat,"
2469 " min_commit_num"
2470 ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?);"));
2471
2472 db_bind_u64(stmt, 0, chan->dbid);
2473 db_bind_u64(stmt, 1, out->key.id);
2474 db_bind_int(stmt, 2, DIRECTION_OUTGOING);
2475 if (out->in)
2476 db_bind_u64(stmt, 3, out->in->dbid);
2477 else
2478 db_bind_null(stmt, 3);
2479 db_bind_amount_msat(stmt, 4, &out->msat);
2480 db_bind_int(stmt, 5, out->cltv_expiry);
2481 db_bind_sha256(stmt, 6, &out->payment_hash);
2482
2483 if (out->preimage)
2484 db_bind_preimage(stmt, 7, out->preimage);
2485 else
2486 db_bind_null(stmt, 7);
2487 db_bind_int(stmt, 8, out->hstate);
2488
2489 db_bind_blob(stmt, 9, out->onion_routing_packet,
2490 sizeof(out->onion_routing_packet));
2491
2492 /* groupid and partid are only relevant when we are the origin */
2493 if (!out->am_origin) {
2494 db_bind_null(stmt, 10);
2495 db_bind_null(stmt, 11);
2496 } else {
2497 db_bind_u64(stmt, 10, out->partid);
2498 db_bind_u64(stmt, 11, out->groupid);
2499 }

Callers 2

test_htlc_crudFunction · 0.85
update_out_htlcFunction · 0.85

Calls 11

db_bind_u64Function · 0.85
db_bind_intFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_amount_msatFunction · 0.85
db_bind_sha256Function · 0.85
db_bind_preimageFunction · 0.85
db_bind_blobFunction · 0.85
min_u64Function · 0.85
db_exec_prepared_v2Function · 0.85
db_last_insert_id_v2Function · 0.85
tal_freeFunction · 0.85

Tested by 1

test_htlc_crudFunction · 0.68