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

Function wallet_forward_delete

wallet/wallet.c:5847–5925  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5845}
5846
5847bool wallet_forward_delete(struct wallet *w,
5848 struct short_channel_id chan_in,
5849 const u64 *htlc_id,
5850 enum forward_status state)
5851{
5852 struct db_stmt *stmt;
5853 bool changed;
5854
5855 /* When deleting settled ones, we have to add to deleted_forward_fees! */
5856 if (state == FORWARD_SETTLED) {
5857 /* Of course, it might not be settled: don't add if they're wrong! */
5858 if (htlc_id) {
5859 stmt = db_prepare_v2(w->db, SQL("SELECT"
5860 " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
5861 " FROM forwards "
5862 " WHERE in_channel_scid = ?"
5863 " AND in_htlc_id = ?"
5864 " AND state = ?;"));
5865 db_bind_short_channel_id(stmt, chan_in);
5866 db_bind_u64(stmt, *htlc_id);
5867 db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED));
5868 } else {
5869 stmt = db_prepare_v2(w->db, SQL("SELECT"
5870 " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
5871 " FROM forwards "
5872 " WHERE in_channel_scid = ?"
5873 " AND in_htlc_id IS NULL"
5874 " AND state = ?;"));
5875 db_bind_short_channel_id(stmt, chan_in);
5876 db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED));
5877 }
5878 db_query_prepared(stmt);
5879
5880 if (db_step(stmt)) {
5881 struct amount_msat deleted;
5882
5883 deleted = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)");
5884 deleted.millisatoshis += /* Raw: db access */
5885 db_get_intvar(w->db, "deleted_forward_fees", 0);
5886 db_set_intvar(w->db, "deleted_forward_fees",
5887 deleted.millisatoshis); /* Raw: db access */
5888 }
5889 tal_free(stmt);
5890 }
5891
5892 if (htlc_id) {
5893 stmt = db_prepare_v2(w->db,
5894 SQL("DELETE FROM forwards"
5895 " WHERE in_channel_scid = ?"
5896 " AND in_htlc_id = ?"
5897 " AND state = ?"));
5898 db_bind_short_channel_id(stmt, chan_in);
5899 db_bind_u64(stmt, *htlc_id);
5900 db_bind_int(stmt, wallet_forward_status_in_db(state));
5901 } else {
5902 stmt = db_prepare_v2(w->db,
5903 SQL("DELETE FROM forwards"
5904 " WHERE in_channel_scid = ?"

Callers 1

json_delforwardFunction · 0.85

Calls 13

db_bind_short_channel_idFunction · 0.85
db_bind_u64Function · 0.85
db_bind_intFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_amount_msatFunction · 0.85
db_set_intvarFunction · 0.85
tal_freeFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_count_changesFunction · 0.85
db_get_intvarFunction · 0.50

Tested by

no test coverage detected