Browse Source

bitcoin/psbt: psbt_txid needs a tal ctx.

It returns a wally_tx; it's an anti-pattern not to hand in a tal context.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-experimental
Rusty Russell 4 years ago
parent
commit
480f671e91
  1. 5
      bitcoin/psbt.c
  2. 4
      bitcoin/psbt.h
  3. 3
      openingd/dualopend.c
  4. 2
      plugins/spender/multifundchannel.c
  5. 4
      plugins/txprepare.c

5
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);
}

4
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

3
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,

2
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",

4
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) {

Loading…
Cancel
Save