From 7a5a7a0ac50ae6aee726ddfc8fc148c615450ae2 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 10 Sep 2020 14:11:21 -0500 Subject: [PATCH] psbt_open: method for adding a witness_stack to a psbt input Set a stack of witnesses onto a PSBT input --- common/psbt_open.c | 12 ++++++++++++ common/psbt_open.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/common/psbt_open.c b/common/psbt_open.c index 863f5524d..a83a8916e 100644 --- a/common/psbt_open.c +++ b/common/psbt_open.c @@ -471,3 +471,15 @@ bool psbt_has_required_fields(struct wally_psbt *psbt) return true; } + +void psbt_input_set_final_witness_stack(struct wally_psbt_input *in, + const struct witness_element **elements) +{ + wally_tx_witness_stack_init_alloc(tal_count(elements), + &in->final_witness); + + for (size_t i = 0; i < tal_count(elements); i++) + wally_tx_witness_stack_add(in->final_witness, + elements[i]->witness, + tal_bytelen(elements[i]->witness)); +} diff --git a/common/psbt_open.h b/common/psbt_open.h index b4be8d093..6507e62c3 100644 --- a/common/psbt_open.h +++ b/common/psbt_open.h @@ -14,6 +14,7 @@ struct wally_psbt; struct wally_psbt_input; struct wally_psbt_output; struct wally_map; +struct witness_element; struct input_set { struct wally_tx_input tx_input; @@ -140,4 +141,11 @@ int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id); */ bool psbt_has_required_fields(struct wally_psbt *psbt); +/* psbt_input_set_final_witness_stack - Set the witness stack for PSBT input + * + * @in - input to set final_witness for + * @witness_element - elements to add to witness stack + */ +void psbt_input_set_final_witness_stack(struct wally_psbt_input *in, + const struct witness_element **elements); #endif /* LIGHTNING_COMMON_PSBT_OPEN_H */