Skip to content

Commit

Permalink
wally: Migrate the funding transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker authored and rustyrussell committed Apr 8, 2019
1 parent 3937b17 commit 710a2ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions common/funding_tx.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "funding_tx.h"
#include <assert.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/script.h>
#include <bitcoin/tx.h>
Expand All @@ -22,17 +23,18 @@ 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",
tal_hex(wscript, wscript));
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);
Expand All @@ -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;
}

0 comments on commit 710a2ab

Please sign in to comment.