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

Function calc_tx_fee

lightningd/closing_control.c:171–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171static struct amount_sat calc_tx_fee(struct amount_sat sat_in,
172 const struct bitcoin_tx *tx)
173{
174 struct amount_asset amt;
175 struct amount_sat fee = sat_in;
176
177 for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
178 const struct wally_tx_output *txout = &tx->wtx->outputs[i];
179 if (chainparams->is_elements && !txout->script_len)
180 continue;
181
182 /* Ignore outputs that are not denominated in our main
183 * currency. */
184 amt = bitcoin_tx_output_get_amount(tx, i);
185 if (!amount_asset_is_main(&amt))
186 continue;
187
188 if (!amount_sat_sub(&fee, fee, amount_asset_to_sat(&amt)))
189 fatal("Tx spends more than input %s? %s",
190 fmt_amount_sat(tmpctx, sat_in),
191 fmt_bitcoin_tx(tmpctx, tx));
192 }
193 return fee;
194}
195
196/* Assess whether a proposed closing fee is acceptable. */
197static bool closing_fee_is_acceptable(struct lightningd *ld,

Callers 1

Calls 7

fmt_bitcoin_txFunction · 0.85
fatalFunction · 0.70
amount_asset_is_mainFunction · 0.50
amount_sat_subFunction · 0.50
amount_asset_to_satFunction · 0.50
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected