wally: Migrate the funding transaction

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-03-15 14:10:29 +01:00 committed by Rusty Russell
parent 3937b17e2b
commit 710a2abc5f

View file

@ -1,4 +1,5 @@
#include "funding_tx.h" #include "funding_tx.h"
#include <assert.h>
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <bitcoin/tx.h> #include <bitcoin/tx.h>
@ -22,9 +23,10 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
{ {
u8 *wscript; u8 *wscript;
struct bitcoin_tx *tx; 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); wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey);
SUPERVERBOSE("# funding witness script = %s\n", 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); bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), &funding);
tal_free(wscript); tal_free(wscript);
if (!amount_sat_eq(change, AMOUNT_SAT(0))) { if (has_change) {
const void *map[2]; const void *map[2];
map[0] = int2ptr(0); map[0] = int2ptr(0);
map[1] = int2ptr(1); map[1] = int2ptr(1);
@ -45,5 +47,6 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
} }
permute_inputs(tx, (const void **)utxomap); permute_inputs(tx, (const void **)utxomap);
assert(bitcoin_tx_check(tx));
return tx; return tx;
} }