| 166 | } |
| 167 | |
| 168 | static 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. */ |
| 198 | static bool closing_fee_is_acceptable(struct lightningd *ld, |
no test coverage detected