diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 284dc78bb13d..0b817c5e596c 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1437,13 +1437,14 @@ static bool check_funding_details(const struct bitcoin_tx *tx, struct amount_sat funding, u32 funding_outnum) { - struct amount_asset asset = - bitcoin_tx_output_get_amount(tx, funding_outnum); + struct amount_asset asset; - if (!amount_asset_is_main(&asset)) + if (funding_outnum >= tx->wtx->num_outputs) return false; - if (funding_outnum >= tx->wtx->num_outputs) + asset = bitcoin_tx_output_get_amount(tx, funding_outnum); + + if (!amount_asset_is_main(&asset)) return false; if (!amount_sat_eq(amount_asset_to_sat(&asset), funding))