psbt: replace init/create_psbt with just create_psbt, and simplify it.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
This commit is contained in:
Jon Griffiths 2023-05-30 10:25:18 +12:00 committed by Rusty Russell
parent 909f911ff7
commit b2b8722a14

View file

@ -17,17 +17,16 @@ static void psbt_destroy(struct wally_psbt *psbt)
wally_psbt_free(psbt); wally_psbt_free(psbt);
} }
static struct wally_psbt *init_psbt(const tal_t *ctx, size_t num_inputs, size_t num_outputs) struct wally_psbt *create_psbt(const tal_t *ctx, size_t num_inputs, size_t num_outputs, u32 locktime)
{ {
int wally_err; const u32 init_flags = is_elements(chainparams) ? WALLY_PSBT_INIT_PSET : 0;
struct wally_psbt *psbt; struct wally_psbt *psbt;
int wally_err;
tal_wally_start(); tal_wally_start();
if (is_elements(chainparams)) wally_err = wally_psbt_init_alloc(2, num_inputs, num_outputs, 0, init_flags, &psbt);
wally_err = wally_psbt_init_alloc(2, num_inputs, num_outputs, 0, WALLY_PSBT_INIT_PSET, &psbt);
else
wally_err = wally_psbt_init_alloc(2, num_inputs, num_outputs, 0, 0, &psbt);
assert(wally_err == WALLY_OK); assert(wally_err == WALLY_OK);
wally_psbt_set_fallback_locktime(psbt, locktime);
/* By default we are modifying them internally; allow it */ /* By default we are modifying them internally; allow it */
wally_psbt_set_tx_modifiable_flags(psbt, WALLY_PSBT_TXMOD_INPUTS | WALLY_PSBT_TXMOD_OUTPUTS); wally_psbt_set_tx_modifiable_flags(psbt, WALLY_PSBT_TXMOD_INPUTS | WALLY_PSBT_TXMOD_OUTPUTS);
tal_add_destructor(psbt, psbt_destroy); tal_add_destructor(psbt, psbt_destroy);
@ -36,17 +35,6 @@ static struct wally_psbt *init_psbt(const tal_t *ctx, size_t num_inputs, size_t
return psbt; return psbt;
} }
/* FIXME extremely thin wrapper; remove? */
struct wally_psbt *create_psbt(const tal_t *ctx, size_t num_inputs, size_t num_outputs, u32 locktime)
{
struct wally_psbt *psbt;
psbt = init_psbt(ctx, num_inputs, num_outputs);
wally_psbt_set_fallback_locktime(psbt, locktime);
return psbt;
}
struct wally_psbt *clone_psbt(const tal_t *ctx, struct wally_psbt *psbt) struct wally_psbt *clone_psbt(const tal_t *ctx, struct wally_psbt *psbt)
{ {
struct wally_psbt *clone; struct wally_psbt *clone;