| 171 | } |
| 172 | |
| 173 | static 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 | |
| 205 | static u32 calc_max_close_feerate(struct lightningd *ld, |
| 206 | struct channel *channel) |
no test coverage detected