From 607075a3d43408216ad76d279d3b4b74eab65b72 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Sep 2020 19:54:26 +0930 Subject: [PATCH] bitcoin/psbt: wallt_tx_output needs a tal ctx. Signed-off-by: Rusty Russell --- bitcoin/psbt.c | 4 ++-- bitcoin/tx.c | 7 ++++--- bitcoin/tx.h | 3 ++- plugins/txprepare.c | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 2402f14df..bc49222cb 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -178,7 +178,7 @@ struct wally_psbt_output *psbt_append_output(struct wally_psbt *psbt, struct amount_sat amount) { struct wally_psbt_output *out; - struct wally_tx_output *tx_out = wally_tx_output(script, amount); + struct wally_tx_output *tx_out = wally_tx_output(NULL, script, amount); out = psbt_add_output(psbt, tx_out, psbt->tx->num_outputs); wally_tx_output_free(tx_out); @@ -190,7 +190,7 @@ struct wally_psbt_output *psbt_insert_output(struct wally_psbt *psbt, size_t insert_at) { struct wally_psbt_output *out; - struct wally_tx_output *tx_out = wally_tx_output(script, amount); + struct wally_tx_output *tx_out = wally_tx_output(NULL, script, amount); out = psbt_add_output(psbt, tx_out, insert_at); wally_tx_output_free(tx_out); diff --git a/bitcoin/tx.c b/bitcoin/tx.c index bbdf306a2..9a8d09b99 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -26,7 +26,8 @@ struct bitcoin_tx_output *new_tx_output(const tal_t *ctx, return output; } -struct wally_tx_output *wally_tx_output(const u8 *script, +struct wally_tx_output *wally_tx_output(const tal_t *ctx, + const u8 *script, struct amount_sat amount) { u64 satoshis = amount.satoshis; /* Raw: wally API */ @@ -53,7 +54,7 @@ struct wally_tx_output *wally_tx_output(const u8 *script, if (ret != WALLY_OK) return NULL; } - return output; + return tal_steal(ctx, output); } int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, @@ -69,7 +70,7 @@ int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, assert(tx->wtx != NULL); assert(chainparams); - output = wally_tx_output(script, amount); + output = wally_tx_output(NULL, script, amount); assert(output); ret = wally_tx_add_output(tx->wtx, output); assert(ret == WALLY_OK); diff --git a/bitcoin/tx.h b/bitcoin/tx.h index c2e1bc299..2c2a87636 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -83,7 +83,8 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, /* Helper to create a wally_tx_output: make sure to wally_tx_output_free! * Returns NULL if amount is extreme (wally doesn't like). */ -struct wally_tx_output *wally_tx_output(const u8 *script, +struct wally_tx_output *wally_tx_output(const tal_t *ctx, + const u8 *script, struct amount_sat amount); /* Add one output to tx. */ diff --git a/plugins/txprepare.c b/plugins/txprepare.c index be7414e16..a37610363 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -178,7 +178,7 @@ static struct command_result *finish_txprepare(struct command *cmd, for (size_t i = 0; i < tal_count(txp->outputs); i++) { struct wally_tx_output *out; - out = wally_tx_output(txp->outputs[i].script, + out = wally_tx_output(NULL, txp->outputs[i].script, txp->outputs[i].amount); if (!out) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, @@ -189,6 +189,7 @@ static struct command_result *finish_txprepare(struct command *cmd, struct amount_sat, &txp->outputs[i].amount)); psbt_add_output(txp->psbt, out, i); + wally_tx_output_free(out); } /* If this is elements, we should normalize