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

Function wallet_forward_delete

wallet/wallet.c:5787–5865  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5785}
5786
5787bool wallet_forward_delete(struct wallet *w,
5788 struct short_channel_id chan_in,
5789 const u64 *htlc_id,
5790 enum forward_status state)
5791{
5792 struct db_stmt *stmt;
5793 bool changed;
5794
5795 /* When deleting settled ones, we have to add to deleted_forward_fees! */
5796 if (state == FORWARD_SETTLED) {
5797 /* Of course, it might not be settled: don't add if they're wrong! */
5798 if (htlc_id) {
5799 stmt = db_prepare_v2(w->db, SQL("SELECT"
5800 " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
5801 " FROM forwards "
5802 " WHERE in_channel_scid = ?"
5803 " AND in_htlc_id = ?"
5804 " AND state = ?;"));
5805 db_bind_short_channel_id(stmt, chan_in);
5806 db_bind_u64(stmt, *htlc_id);
5807 db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED));
5808 } else {
5809 stmt = db_prepare_v2(w->db, SQL("SELECT"
5810 " CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
5811 " FROM forwards "
5812 " WHERE in_channel_scid = ?"
5813 " AND in_htlc_id IS NULL"
5814 " AND state = ?;"));
5815 db_bind_short_channel_id(stmt, chan_in);
5816 db_bind_int(stmt, wallet_forward_status_in_db(FORWARD_SETTLED));
5817 }
5818 db_query_prepared(stmt);
5819
5820 if (db_step(stmt)) {
5821 struct amount_msat deleted;
5822
5823 deleted = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)");
5824 deleted.millisatoshis += /* Raw: db access */
5825 db_get_intvar(w->db, "deleted_forward_fees", 0);
5826 db_set_intvar(w->db, "deleted_forward_fees",
5827 deleted.millisatoshis); /* Raw: db access */
5828 }
5829 tal_free(stmt);
5830 }
5831
5832 if (htlc_id) {
5833 stmt = db_prepare_v2(w->db,
5834 SQL("DELETE FROM forwards"
5835 " WHERE in_channel_scid = ?"
5836 " AND in_htlc_id = ?"
5837 " AND state = ?"));
5838 db_bind_short_channel_id(stmt, chan_in);
5839 db_bind_u64(stmt, *htlc_id);
5840 db_bind_int(stmt, wallet_forward_status_in_db(state));
5841 } else {
5842 stmt = db_prepare_v2(w->db,
5843 SQL("DELETE FROM forwards"
5844 " 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