From 10fce07d964b8ebe8366b77c8402e53a53caf688 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 4 Feb 2021 15:12:56 -0600 Subject: [PATCH] psbt: method to clone a PSBT onto a context wally offers up `wally_clone_psbt` but it's a bit clunky (requires checking return value, starting/stopping the wally_allocation context) Helper method wraps this all up nice + neat! --- bitcoin/psbt.c | 10 ++++++++++ bitcoin/psbt.h | 8 ++++++++ 2 files changed, 18 insertions(+) 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 *