Browse Source

bitcoin/psbt: wallt_tx_output needs a tal ctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-experimental
Rusty Russell 4 years ago
parent
commit
607075a3d4
  1. 4
      bitcoin/psbt.c
  2. 7
      bitcoin/tx.c
  3. 3
      bitcoin/tx.h
  4. 3
      plugins/txprepare.c

4
bitcoin/psbt.c

@ -178,7 +178,7 @@ struct wally_psbt_output *psbt_append_output(struct wally_psbt *psbt,
struct amount_sat amount) struct amount_sat amount)
{ {
struct wally_psbt_output *out; 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); out = psbt_add_output(psbt, tx_out, psbt->tx->num_outputs);
wally_tx_output_free(tx_out); 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) size_t insert_at)
{ {
struct wally_psbt_output *out; 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); out = psbt_add_output(psbt, tx_out, insert_at);
wally_tx_output_free(tx_out); wally_tx_output_free(tx_out);

7
bitcoin/tx.c

@ -26,7 +26,8 @@ struct bitcoin_tx_output *new_tx_output(const tal_t *ctx,
return output; 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) struct amount_sat amount)
{ {
u64 satoshis = amount.satoshis; /* Raw: wally API */ 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) if (ret != WALLY_OK)
return NULL; return NULL;
} }
return output; return tal_steal(ctx, output);
} }
int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, 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(tx->wtx != NULL);
assert(chainparams); assert(chainparams);
output = wally_tx_output(script, amount); output = wally_tx_output(NULL, script, amount);
assert(output); assert(output);
ret = wally_tx_add_output(tx->wtx, output); ret = wally_tx_add_output(tx->wtx, output);
assert(ret == WALLY_OK); assert(ret == WALLY_OK);

3
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! /* Helper to create a wally_tx_output: make sure to wally_tx_output_free!
* Returns NULL if amount is extreme (wally doesn't like). * 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); struct amount_sat amount);
/* Add one output to tx. */ /* Add one output to tx. */

3
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++) { for (size_t i = 0; i < tal_count(txp->outputs); i++) {
struct wally_tx_output *out; 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); txp->outputs[i].amount);
if (!out) if (!out)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
@ -189,6 +189,7 @@ static struct command_result *finish_txprepare(struct command *cmd,
struct amount_sat, struct amount_sat,
&txp->outputs[i].amount)); &txp->outputs[i].amount));
psbt_add_output(txp->psbt, out, i); psbt_add_output(txp->psbt, out, i);
wally_tx_output_free(out);
} }
/* If this is elements, we should normalize /* If this is elements, we should normalize

Loading…
Cancel
Save