psbt: handle 'unsetting' final witness stack

Prior to this commit, passing a NULL stack to `bitcoin_tx_input_set_witness`
unsets the witness stack on the bitcoin_tx's wally_tx but leaves the
final witness on the PSBT unchanged.

at the moment, libwally's `wally_psbt_input_set_final_witness` will blow
up if you attempt to set a NULL witness -- instead we manually remove it
if the passed in stack is NULL. previously we would leave the PSBT's
witness unchanged.
This commit is contained in:
niftynei 2020-05-28 22:09:59 -05:00 committed by Christian Decker
parent 58282819a9
commit 9e0ef45048

View File

@ -309,7 +309,6 @@ void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
{
struct wally_tx_witness_stack *stack = NULL;
size_t stack_size = tal_count(witness);
struct wally_psbt_input *in;
/* Free any lingering witness */
if (witness) {
@ -321,17 +320,21 @@ void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
wally_tx_set_input_witness(tx->wtx, innum, stack);
/* Also add to the psbt */
if (stack) {
assert(innum < tx->psbt->num_inputs);
in = &tx->psbt->inputs[innum];
wally_psbt_input_set_final_witness(in, stack);
if (stack)
wally_psbt_input_set_final_witness(&tx->psbt->inputs[innum], stack);
else {
/* FIXME: libwally-psbt doesn't allow 'unsetting' of witness via
* the set method at the moment, so we do it manually*/
struct wally_psbt_input *in = &tx->psbt->inputs[innum];
if (in->final_witness)
wally_tx_witness_stack_free(in->final_witness);
in->final_witness = NULL;
}
if (stack)
wally_tx_witness_stack_free(stack);
if (taken(witness))
tal_free(witness);
}
void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script)