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!
This commit is contained in:
niftynei 2021-02-04 15:12:56 -06:00 committed by neil saitug
parent 7ba6097d3c
commit 10fce07d96
2 changed files with 18 additions and 0 deletions

View File

@ -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;

View File

@ -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
*