| 169 | } |
| 170 | |
| 171 | static 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. */ |
| 197 | static bool closing_fee_is_acceptable(struct lightningd *ld, |
no test coverage detected