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

Function calc_tx_fee

lightningd/closing_control.c:168–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 9

tal_bytelenFunction · 0.85
tal_freeFunction · 0.85
fatalFunction · 0.70
amount_asset_is_mainFunction · 0.50
amount_sat_subFunction · 0.50
amount_asset_to_satFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected