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

Function calc_tx_fee

lightningd/closing_control.c:173–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173static bool calc_tx_fee(struct channel *channel,
174 const struct bitcoin_tx *tx,
175 struct amount_sat *fee_result)
176{
177 struct amount_asset amt;
178 struct amount_sat sat_in = channel->funding_sats;
179
180 for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
181 const struct wally_tx_output *txout = &tx->wtx->outputs[i];
182 if (chainparams->is_elements && !txout->script_len)
183 continue;
184
185 /* Ignore outputs that are not denominated in our main
186 * currency. */
187 amt = bitcoin_tx_output_get_amount(tx, i);
188 if (!amount_asset_is_main(&amt))
189 continue;
190
191 if (!amount_sat_sub(&sat_in, sat_in, amount_asset_to_sat(&amt))) {
192 /* Important we dont abort here incase we're force
193 * closing due to things going wrong. */
194 log_unusual(channel->log,
195 "Tx spends more than input %s? %s",
196 fmt_amount_sat(tmpctx, sat_in),
197 fmt_bitcoin_tx(tmpctx, tx));
198 return false;
199 }
200 }
201 *fee_result = sat_in;
202 return true;
203}
204
205static u32 calc_max_close_feerate(struct lightningd *ld,
206 struct channel *channel)

Callers 1

Calls 6

fmt_bitcoin_txFunction · 0.85
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