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

Function wallet_total_forward_fees

wallet/wallet.c:5525–5551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5523}
5524
5525struct 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
5553struct db_stmt *forwarding_first(struct wallet *w,
5554 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