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

Function wallet_total_forward_fees

wallet/wallet.c:4506–4532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4504}
4505
4506struct amount_msat wallet_total_forward_fees(struct wallet *w)
4507{
4508 struct db_stmt *stmt;
4509 struct amount_msat total, deleted;
4510 bool res;
4511
4512 stmt = db_prepare_v2(w->db, SQL("SELECT"
4513 " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
4514 " FROM forwards "
4515 "WHERE state = ?;"));
4516 db_bind_int(stmt, 0, wallet_forward_status_in_db(FORWARD_SETTLED));
4517 db_query_prepared(stmt);
4518
4519 res = db_step(stmt);
4520 assert(res);
4521
4522 db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)", &total);
4523 tal_free(stmt);
4524
4525 deleted = amount_msat(db_get_intvar(w->db, "deleted_forward_fees", 0));
4526 if (!amount_msat_add(&total, total, deleted))
4527 db_fatal("Adding forward fees %s + %s overflowed",
4528 type_to_string(tmpctx, struct amount_msat, &total),
4529 type_to_string(tmpctx, struct amount_msat, &deleted));
4530
4531 return total;
4532}
4533
4534bool string_to_forward_status(const char *status_str,
4535 size_t len,

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_addFunction · 0.85
amount_msatClass · 0.70
db_fatalFunction · 0.70
db_get_intvarFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected