| 3921 | } |
| 3922 | |
| 3923 | struct 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! */ |
| 3962 | static |
no test coverage detected