| 1737 | } |
| 1738 | |
| 1739 | struct rebalance **list_rebalances(const tal_t *ctx, struct db *db) |
| 1740 | { |
| 1741 | struct rebalance **result; |
| 1742 | struct db_stmt *stmt; |
| 1743 | |
| 1744 | stmt = db_prepare_v2(db, SQL("SELECT " |
| 1745 | " in_e.id" |
| 1746 | ", out_e.id" |
| 1747 | ", in_acct.name" |
| 1748 | ", out_acct.name" |
| 1749 | ", in_e.credit" |
| 1750 | ", out_e.fees" |
| 1751 | " FROM channel_events in_e" |
| 1752 | " LEFT OUTER JOIN channel_events out_e" |
| 1753 | " ON in_e.rebalance_id = out_e.id" |
| 1754 | " LEFT OUTER JOIN accounts out_acct" |
| 1755 | " ON out_acct.id = out_e.account_id" |
| 1756 | " LEFT OUTER JOIN accounts in_acct" |
| 1757 | " ON in_acct.id = in_e.account_id" |
| 1758 | " WHERE in_e.rebalance_id IS NOT NULL" |
| 1759 | " AND in_e.credit > 0")); |
| 1760 | db_query_prepared(stmt); |
| 1761 | result = tal_arr(ctx, struct rebalance *, 0); |
| 1762 | while (db_step(stmt)) { |
| 1763 | struct rebalance *r = stmt2rebalance(result, stmt); |
| 1764 | tal_arr_expand(&result, r); |
| 1765 | } |
| 1766 | tal_free(stmt); |
| 1767 | return result; |
| 1768 | } |
| 1769 | |
| 1770 | char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db, |
| 1771 | struct bitcoin_txid *txid) |