| 5560 | } |
| 5561 | |
| 5562 | struct amount_msat wallet_total_forward_fees(struct wallet *w) |
| 5563 | { |
| 5564 | struct db_stmt *stmt; |
| 5565 | struct amount_msat total, deleted; |
| 5566 | bool res; |
| 5567 | |
| 5568 | stmt = db_prepare_v2(w->db, SQL("SELECT" |
| 5569 | " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)" |
| 5570 | " FROM forwards " |
| 5571 | "WHERE state = ?;")); |
| 5572 | db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED)); |
| 5573 | db_query_prepared(stmt); |
| 5574 | |
| 5575 | res = db_step(stmt); |
| 5576 | assert(res); |
| 5577 | |
| 5578 | total = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"); |
| 5579 | tal_free(stmt); |
| 5580 | |
| 5581 | deleted = amount_msat(db_get_intvar(w->db, "deleted_forward_fees", 0)); |
| 5582 | if (!amount_msat_accumulate(&total, deleted)) |
| 5583 | db_fatal(w->db, "Adding forward fees %s + %s overflowed", |
| 5584 | fmt_amount_msat(tmpctx, total), |
| 5585 | fmt_amount_msat(tmpctx, deleted)); |
| 5586 | |
| 5587 | return total; |
| 5588 | } |
| 5589 | |
| 5590 | struct db_stmt *forwarding_first(struct wallet *w, |
| 5591 | enum forward_status status, |
nothing calls this directly
no test coverage detected