| 49 | } |
| 50 | |
| 51 | static struct bitcoin_tx *close_tx(const tal_t *ctx, |
| 52 | const struct chainparams *chainparams, |
| 53 | struct per_peer_state *pps, |
| 54 | const struct channel_id *channel_id, |
| 55 | u32 *local_wallet_index, |
| 56 | const struct ext_key *local_wallet_ext_key, |
| 57 | u8 *scriptpubkey[NUM_SIDES], |
| 58 | const struct bitcoin_outpoint *funding, |
| 59 | struct amount_sat funding_sats, |
| 60 | const u8 *funding_wscript, |
| 61 | const struct amount_sat out[NUM_SIDES], |
| 62 | enum side opener, |
| 63 | struct amount_sat fee, |
| 64 | struct amount_sat dust_limit, |
| 65 | const struct bitcoin_outpoint *wrong_funding) |
| 66 | { |
| 67 | struct bitcoin_tx *tx; |
| 68 | struct amount_sat out_minus_fee[NUM_SIDES]; |
| 69 | |
| 70 | out_minus_fee[LOCAL] = out[LOCAL]; |
| 71 | out_minus_fee[REMOTE] = out[REMOTE]; |
| 72 | if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee)) |
| 73 | peer_failed_warn(pps, channel_id, |
| 74 | "Funder cannot afford fee %s (%s and %s)", |
| 75 | type_to_string(tmpctx, struct amount_sat, &fee), |
| 76 | type_to_string(tmpctx, struct amount_sat, |
| 77 | &out[LOCAL]), |
| 78 | type_to_string(tmpctx, struct amount_sat, |
| 79 | &out[REMOTE])); |
| 80 | |
| 81 | status_debug("Making close tx at = %s/%s fee %s", |
| 82 | type_to_string(tmpctx, struct amount_sat, &out[LOCAL]), |
| 83 | type_to_string(tmpctx, struct amount_sat, &out[REMOTE]), |
| 84 | type_to_string(tmpctx, struct amount_sat, &fee)); |
| 85 | |
| 86 | /* FIXME: We need to allow this! */ |
| 87 | tx = create_close_tx(ctx, |
| 88 | chainparams, |
| 89 | local_wallet_index, local_wallet_ext_key, |
| 90 | scriptpubkey[LOCAL], scriptpubkey[REMOTE], |
| 91 | funding_wscript, |
| 92 | funding, |
| 93 | funding_sats, |
| 94 | out_minus_fee[LOCAL], |
| 95 | out_minus_fee[REMOTE], |
| 96 | dust_limit); |
| 97 | if (!tx) |
| 98 | peer_failed_err(pps, channel_id, |
| 99 | "Both outputs below dust limit:" |
| 100 | " funding = %s" |
| 101 | " fee = %s" |
| 102 | " dust_limit = %s" |
| 103 | " LOCAL = %s" |
| 104 | " REMOTE = %s", |
| 105 | type_to_string(tmpctx, struct amount_sat, &funding_sats), |
| 106 | type_to_string(tmpctx, struct amount_sat, &fee), |
| 107 | type_to_string(tmpctx, struct amount_sat, &dust_limit), |
| 108 | type_to_string(tmpctx, struct amount_sat, &out[LOCAL]), |
no test coverage detected