diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 14ac04845..fab224afc 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -62,6 +62,16 @@ struct wally_psbt *create_psbt(const tal_t *ctx, size_t num_inputs, size_t num_o return psbt; } +struct wally_psbt *clone_psbt(const tal_t *ctx, struct wally_psbt *psbt) +{ + struct wally_psbt *clone; + tal_wally_start(); + if (wally_psbt_clone_alloc(psbt, 0, &clone) != WALLY_OK) + abort(); + tal_wally_end(tal_steal(ctx, clone)); + return clone; +} + struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx) { struct wally_psbt *psbt; diff --git a/bitcoin/psbt.h b/bitcoin/psbt.h index bd95fe113..459eef93c 100644 --- a/bitcoin/psbt.h +++ b/bitcoin/psbt.h @@ -49,6 +49,14 @@ struct wally_psbt *create_psbt(const tal_t *ctx, size_t num_inputs, size_t num_o struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx); +/** + * clone_psbt - Clone a PSBT onto passed in context + * + * @ctx - allocation context + * @psbt - psbt to be cloned + */ +struct wally_psbt *clone_psbt(const tal_t *ctx, struct wally_psbt *psbt); + /** * psbt_is_finalized - Check if tx is ready to be extracted *