diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index ddb5fc632..2402f14df 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -706,7 +706,8 @@ struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx, } /* This only works on a non-final psbt because we're ALL SEGWIT! */ -void psbt_txid(const struct wally_psbt *psbt, struct bitcoin_txid *txid, +void psbt_txid(const tal_t *ctx, + const struct wally_psbt *psbt, struct bitcoin_txid *txid, struct wally_tx **wtx) { struct wally_tx *tx; @@ -732,7 +733,7 @@ void psbt_txid(const struct wally_psbt *psbt, struct bitcoin_txid *txid, wally_txid(tx, txid); if (wtx) - *wtx = tx; + *wtx = tal_steal(ctx, tx); else wally_tx_free(tx); } diff --git a/bitcoin/psbt.h b/bitcoin/psbt.h index 747982142..b74a18203 100644 --- a/bitcoin/psbt.h +++ b/bitcoin/psbt.h @@ -62,11 +62,13 @@ bool psbt_is_finalized(const struct wally_psbt *psbt); /** * psbt_txid - get the txid of the psbt (what it would be after finalization) + * @ctx: the context to allocate wtx off, if *@wtx isn't NULL. * @psbt: the psbt. * @txid: the transaction id (output) * @wtx: if non-NULL, returns a copy of the transaction (caller must wally_tx_free). */ -void psbt_txid(const struct wally_psbt *psbt, struct bitcoin_txid *txid, +void psbt_txid(const tal_t *ctx, + const struct wally_psbt *psbt, struct bitcoin_txid *txid, struct wally_tx **wtx); /* psbt_elements_normalize_fees - Figure out the fee output for a PSET diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 051060837..9889ef7e9 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1036,8 +1036,7 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg) return NULL; /* Find the funding transaction txid */ - struct wally_tx *funding_tx; - psbt_txid(psbt, &state->funding_txid, &funding_tx); + psbt_txid(NULL, psbt, &state->funding_txid, NULL); wscript = bitcoin_redeem_2of2(state, &state->our_funding_pubkey, diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 20b052051..37baa6613 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -1392,7 +1392,7 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc) /* Generate the TXID. */ mfc->txid = tal(mfc, struct bitcoin_txid); - psbt_txid(mfc->psbt, mfc->txid, NULL); + psbt_txid(NULL, mfc->psbt, mfc->txid, NULL); plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64": funding tx %s: %s", diff --git a/plugins/txprepare.c b/plugins/txprepare.c index bd579c827..be7414e16 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -150,7 +150,7 @@ static struct command_result *signpsbt_done(struct command *cmd, tal_free(utx->tx); /* The txid from the final should match our expectation. */ - psbt_txid(utx->psbt, &txid, &utx->tx); + psbt_txid(utx, utx->psbt, &txid, &utx->tx); if (!bitcoin_txid_eq(&txid, &utx->txid)) { return command_fail(cmd, LIGHTNINGD, "Signed tx changed txid? Had '%s' now '%s'", @@ -197,7 +197,7 @@ static struct command_result *finish_txprepare(struct command *cmd, utx = tal(NULL, struct unreleased_tx); utx->psbt = tal_steal(utx, txp->psbt); - psbt_txid(txp->psbt, &utx->txid, &utx->tx); + psbt_txid(utx, txp->psbt, &utx->txid, &utx->tx); /* If this is a withdraw, we sign and send immediately. */ if (txp->is_withdraw) {