| 5523 | } |
| 5524 | |
| 5525 | struct amount_msat wallet_total_forward_fees(struct wallet *w) |
| 5526 | { |
| 5527 | struct db_stmt *stmt; |
| 5528 | struct amount_msat total, deleted; |
| 5529 | bool res; |
| 5530 | |
| 5531 | stmt = db_prepare_v2(w->db, SQL("SELECT" |
| 5532 | " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)" |
| 5533 | " FROM forwards " |
| 5534 | "WHERE state = ?;")); |
| 5535 | db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED)); |
| 5536 | db_query_prepared(stmt); |
| 5537 | |
| 5538 | res = db_step(stmt); |
| 5539 | assert(res); |
| 5540 | |
| 5541 | total = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"); |
| 5542 | tal_free(stmt); |
| 5543 | |
| 5544 | deleted = amount_msat(db_get_intvar(w->db, "deleted_forward_fees", 0)); |
| 5545 | if (!amount_msat_accumulate(&total, deleted)) |
| 5546 | db_fatal(w->db, "Adding forward fees %s + %s overflowed", |
| 5547 | fmt_amount_msat(tmpctx, total), |
| 5548 | fmt_amount_msat(tmpctx, deleted)); |
| 5549 | |
| 5550 | return total; |
| 5551 | } |
| 5552 | |
| 5553 | struct db_stmt *forwarding_first(struct wallet *w, |
| 5554 | enum forward_status status, |
nothing calls this directly
no test coverage detected