MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_total_forward_fees

Function wallet_total_forward_fees

wallet/wallet.c:5562–5588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5560}
5561
5562struct 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
5590struct db_stmt *forwarding_first(struct wallet *w,
5591 enum forward_status status,

Callers

nothing calls this directly

Calls 11

db_bind_intFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_amount_msatFunction · 0.85
tal_freeFunction · 0.85
amount_msat_accumulateFunction · 0.85
db_fatalFunction · 0.85
amount_msatClass · 0.70
db_get_intvarFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected