| 4552 | } |
| 4553 | |
| 4554 | const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, |
| 4555 | const tal_t *ctx, |
| 4556 | enum forward_status status, |
| 4557 | const struct short_channel_id *chan_in, |
| 4558 | const struct short_channel_id *chan_out) |
| 4559 | { |
| 4560 | struct forwarding *results = tal_arr(ctx, struct forwarding, 0); |
| 4561 | size_t count = 0; |
| 4562 | struct db_stmt *stmt; |
| 4563 | |
| 4564 | // placeholder for any parameter, the value doesn't matter because it's discarded by sql |
| 4565 | const int any = -1; |
| 4566 | |
| 4567 | stmt = db_prepare_v2( |
| 4568 | w->db, |
| 4569 | SQL("SELECT" |
| 4570 | " state" |
| 4571 | ", in_msatoshi" |
| 4572 | ", out_msatoshi" |
| 4573 | ", in_channel_scid" |
| 4574 | ", out_channel_scid" |
| 4575 | ", in_htlc_id" |
| 4576 | ", out_htlc_id" |
| 4577 | ", received_time" |
| 4578 | ", resolved_time" |
| 4579 | ", failcode " |
| 4580 | ", forward_style " |
| 4581 | "FROM forwards " |
| 4582 | "WHERE (1 = ? OR state = ?) AND " |
| 4583 | "(1 = ? OR in_channel_scid = ?) AND " |
| 4584 | "(1 = ? OR out_channel_scid = ?)")); |
| 4585 | |
| 4586 | if (status == FORWARD_ANY) { |
| 4587 | // any status |
| 4588 | db_bind_int(stmt, 0, 1); |
| 4589 | db_bind_int(stmt, 1, any); |
| 4590 | } else { |
| 4591 | // specific forward status |
| 4592 | db_bind_int(stmt, 0, 0); |
| 4593 | db_bind_int(stmt, 1, status); |
| 4594 | } |
| 4595 | |
| 4596 | if (chan_in) { |
| 4597 | // specific in_channel |
| 4598 | db_bind_int(stmt, 2, 0); |
| 4599 | db_bind_scid(stmt, 3, chan_in); |
| 4600 | } else { |
| 4601 | // any in_channel |
| 4602 | db_bind_int(stmt, 2, 1); |
| 4603 | db_bind_int(stmt, 3, any); |
| 4604 | } |
| 4605 | |
| 4606 | if (chan_out) { |
| 4607 | // specific out_channel |
| 4608 | db_bind_int(stmt, 4, 0); |
| 4609 | db_bind_scid(stmt, 5, chan_out); |
| 4610 | } else { |
| 4611 | // any out_channel |
no test coverage detected