From 80072b389eb48a9c7b5114dc738123baac16c12b Mon Sep 17 00:00:00 2001 From: niftynei Date: Sat, 6 Jun 2020 14:35:46 -0500 Subject: [PATCH] psbt: remove script sig info from inputs before adding them to global PSBT's dont' serialize / unserialize if there's any sig info set on the global transaction --- bitcoin/psbt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index d14686916..54517e2ba 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -116,10 +116,32 @@ struct wally_psbt_input *psbt_add_input(struct wally_psbt *psbt, { struct wally_tx *tx; struct wally_tx_input tmp_in; + u8 *script; + size_t scriptlen = 0; + struct wally_tx_witness_stack *witness = NULL; tx = psbt->tx; assert(insert_at <= tx->num_inputs); + + /* Remove any script sig or witness info before adding it ! */ + if (input->script_len > 0) { + scriptlen = input->script_len; + input->script_len = 0; + script = (u8 *)input->script; + input->script = NULL; + } + if (input->witness) { + witness = input->witness; + input->witness = NULL; + } wally_tx_add_input(tx, input); + /* Put the script + witness info back */ + if (scriptlen > 0) { + input->script_len = scriptlen; + input->script = script; + } + if (witness) + input->witness = witness; tmp_in = tx->inputs[tx->num_inputs - 1]; MAKE_ROOM(tx->inputs, insert_at, tx->num_inputs);