Skip to content

Commit

Permalink
psbt_txid: it's possible a psbt may already have the finalized scriptsig
Browse files Browse the repository at this point in the history
If we've already got a scriptSig field filled out for a PSBT input, we
use that instead of 'deriving' the scriptSig from the redeemscript
(finalizing a PSBT removes the redeemscript field)
  • Loading branch information
niftynei authored and rustyrussell committed Sep 23, 2020
1 parent c5f748e commit 1f165c0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,16 +748,20 @@ void psbt_txid(const tal_t *ctx,
wally_tx_clone_alloc(psbt->tx, 0, &tx);

for (size_t i = 0; i < tx->num_inputs; i++) {
u8 *script;
if (!psbt->inputs[i].redeem_script)
continue;

/* P2SH requires push of the redeemscript, from libwally src */
script = tal_arr(tmpctx, u8, 0);
script_push_bytes(&script,
psbt->inputs[i].redeem_script,
psbt->inputs[i].redeem_script_len);
wally_tx_set_input_script(tx, i, script, tal_bytelen(script));
if (psbt->inputs[i].final_scriptsig) {
wally_tx_set_input_script(tx, i,
psbt->inputs[i].final_scriptsig,
psbt->inputs[i].final_scriptsig_len);
} else if (psbt->inputs[i].redeem_script) {
u8 *script;

/* P2SH requires push of the redeemscript, from libwally src */
script = tal_arr(tmpctx, u8, 0);
script_push_bytes(&script,
psbt->inputs[i].redeem_script,
psbt->inputs[i].redeem_script_len);
wally_tx_set_input_script(tx, i, script, tal_bytelen(script));
}
}
tal_gather_wally(tal_steal(ctx, tx));

Expand Down

0 comments on commit 1f165c0

Please sign in to comment.