From 1f165c00ae2996bf04a9074cb887b14cc88a5e57 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 10 Sep 2020 13:29:21 -0500 Subject: [PATCH] psbt_txid: it's possible a psbt may already have the finalized scriptsig 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) --- bitcoin/psbt.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 3aef70148..1551e198a 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -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; + 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)); + /* 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));