| 3885 | } |
| 3886 | |
| 3887 | struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet, |
| 3888 | struct channel *chan, u64 commit_num) |
| 3889 | { |
| 3890 | struct htlc_stub *stubs; |
| 3891 | struct sha256 payment_hash; |
| 3892 | struct db_stmt *stmt; |
| 3893 | |
| 3894 | stmt = db_prepare_v2(wallet->db, |
| 3895 | SQL("SELECT channel_id, direction, cltv_expiry, " |
| 3896 | "channel_htlc_id, payment_hash " |
| 3897 | "FROM channel_htlcs WHERE channel_id = ? AND min_commit_num <= ? AND ((max_commit_num IS NULL) OR max_commit_num >= ?);")); |
| 3898 | |
| 3899 | db_bind_u64(stmt, chan->dbid); |
| 3900 | db_bind_u64(stmt, commit_num); |
| 3901 | db_bind_u64(stmt, commit_num); |
| 3902 | db_query_prepared(stmt); |
| 3903 | |
| 3904 | stubs = tal_arr(ctx, struct htlc_stub, 0); |
| 3905 | |
| 3906 | while (db_step(stmt)) { |
| 3907 | struct htlc_stub stub; |
| 3908 | |
| 3909 | assert(db_col_u64(stmt, "channel_id") == chan->dbid); |
| 3910 | |
| 3911 | /* FIXME: merge these two enums */ |
| 3912 | stub.owner = db_col_int(stmt, "direction")==DIRECTION_INCOMING?REMOTE:LOCAL; |
| 3913 | stub.cltv_expiry = db_col_int(stmt, "cltv_expiry"); |
| 3914 | stub.id = db_col_u64(stmt, "channel_htlc_id"); |
| 3915 | |
| 3916 | db_col_sha256(stmt, "payment_hash", &payment_hash); |
| 3917 | ripemd160(&stub.ripemd, payment_hash.u.u8, sizeof(payment_hash.u)); |
| 3918 | tal_arr_expand(&stubs, stub); |
| 3919 | } |
| 3920 | tal_free(stmt); |
| 3921 | return stubs; |
| 3922 | } |
| 3923 | |
| 3924 | /* FIXME: reorder! */ |
| 3925 | static |
no test coverage detected