diff --git a/common/funding_tx.c b/common/funding_tx.c index 9767bf77c..d00de1216 100644 --- a/common/funding_tx.c +++ b/common/funding_tx.c @@ -1,4 +1,5 @@ #include "funding_tx.h" +#include #include #include #include @@ -22,9 +23,10 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, { u8 *wscript; struct bitcoin_tx *tx; + bool has_change = !amount_sat_eq(change, AMOUNT_SAT(0)); + + tx = tx_spending_utxos(ctx, utxomap, bip32_base, has_change); - tx = tx_spending_utxos(ctx, utxomap, bip32_base, - !amount_sat_eq(change, AMOUNT_SAT(0))); wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey); SUPERVERBOSE("# funding witness script = %s\n", @@ -32,7 +34,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), &funding); tal_free(wscript); - if (!amount_sat_eq(change, AMOUNT_SAT(0))) { + if (has_change) { const void *map[2]; map[0] = int2ptr(0); map[1] = int2ptr(1); @@ -45,5 +47,6 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, } permute_inputs(tx, (const void **)utxomap); + assert(bitcoin_tx_check(tx)); return tx; }