Skip to content

Commit

Permalink
wellet: use create_psbt and psbt_append_input instead of constructing…
Browse files Browse the repository at this point in the history
… via bitcoin_tx.

Suggested-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Aug 21, 2020
1 parent 44db670 commit 1e15734
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions wallet/reservation.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,9 @@ static struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
{
struct pubkey key;
u8 *scriptSig, *scriptPubkey, *redeemscript;
struct bitcoin_tx *tx;
struct wally_psbt *psbt;

/* FIXME: Currently the easiest way to get a PSBT is via a tx */
tx = bitcoin_tx(ctx, chainparams, tal_count(utxos), 0, nlocktime);
psbt = create_psbt(ctx, tal_count(utxos), 0, nlocktime);

for (size_t i = 0; i < tal_count(utxos); i++) {
u32 this_nsequence;
Expand Down Expand Up @@ -256,17 +255,12 @@ static struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
else
this_nsequence = nsequence;

bitcoin_tx_add_input(tx, &utxos[i]->txid, utxos[i]->outnum,
this_nsequence, scriptSig, utxos[i]->amount,
scriptPubkey, NULL);

/* Add redeemscript to the PSBT input */
if (redeemscript)
psbt_input_set_redeemscript(tx->psbt, i, redeemscript);

psbt_append_input(psbt, &utxos[i]->txid, utxos[i]->outnum,
this_nsequence, scriptSig, utxos[i]->amount,
scriptPubkey, NULL, redeemscript);
}

return tx->psbt;
return psbt;
}

static struct command_result *finish_psbt(struct command *cmd,
Expand Down

0 comments on commit 1e15734

Please sign in to comment.