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

Function wallet_htlc_stubs

wallet/wallet.c:3923–3959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3921}
3922
3923struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
3924 struct channel *chan, u64 commit_num)
3925{
3926 struct htlc_stub *stubs;
3927 struct sha256 payment_hash;
3928 struct db_stmt *stmt;
3929
3930 stmt = db_prepare_v2(wallet->db,
3931 SQL("SELECT channel_id, direction, cltv_expiry, "
3932 "channel_htlc_id, payment_hash, msatoshi "
3933 "FROM channel_htlcs WHERE channel_id = ? AND min_commit_num <= ? AND ((max_commit_num IS NULL) OR max_commit_num >= ?);"));
3934
3935 db_bind_u64(stmt, chan->dbid);
3936 db_bind_u64(stmt, commit_num);
3937 db_bind_u64(stmt, commit_num);
3938 db_query_prepared(stmt);
3939
3940 stubs = tal_arr(ctx, struct htlc_stub, 0);
3941
3942 while (db_step(stmt)) {
3943 struct htlc_stub stub;
3944
3945 assert(db_col_u64(stmt, "channel_id") == chan->dbid);
3946
3947 /* FIXME: merge these two enums */
3948 stub.owner = db_col_int(stmt, "direction")==DIRECTION_INCOMING?REMOTE:LOCAL;
3949 stub.cltv_expiry = db_col_int(stmt, "cltv_expiry");
3950 stub.id = db_col_u64(stmt, "channel_htlc_id");
3951 stub.amount = db_col_amount_msat(stmt, "msatoshi");
3952
3953 db_col_sha256(stmt, "payment_hash", &payment_hash);
3954 ripemd160(&stub.ripemd, payment_hash.u.u8, sizeof(payment_hash.u));
3955 tal_arr_expand(&stubs, stub);
3956 }
3957 tal_free(stmt);
3958 return stubs;
3959}
3960
3961/* FIXME: reorder! */
3962static

Callers 1

Calls 9

db_bind_u64Function · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_u64Function · 0.85
db_col_intFunction · 0.85
db_col_amount_msatFunction · 0.85
db_col_sha256Function · 0.85
tal_freeFunction · 0.85
ripemd160Class · 0.70

Tested by

no test coverage detected