diff --git a/bitcoin/tx.c b/bitcoin/tx.c index ca0a15973..57cc593fd 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -265,22 +265,26 @@ void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum, } } -const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, - const struct bitcoin_tx *tx, int outnum) +const u8 *wally_tx_output_get_script(const tal_t *ctx, + const struct wally_tx_output *output) { - const struct wally_tx_output *output; - u8 *res; - assert(outnum < tx->wtx->num_outputs); - output = &tx->wtx->outputs[outnum]; - if (output->script == NULL) { /* This can happen for coinbase transactions and pegin * transactions */ return NULL; } - res = tal_dup_arr(ctx, u8, output->script, output->script_len, 0); - return res; + return tal_dup_arr(ctx, u8, output->script, output->script_len, 0); +} + +const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, + const struct bitcoin_tx *tx, int outnum) +{ + const struct wally_tx_output *output; + assert(outnum < tx->wtx->num_outputs); + output = &tx->wtx->outputs[outnum]; + + return wally_tx_output_get_script(ctx, output); } u8 *bitcoin_tx_output_get_witscript(const tal_t *ctx, const struct bitcoin_tx *tx, diff --git a/bitcoin/tx.h b/bitcoin/tx.h index 982f6ff22..bdc2928e0 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -126,6 +126,15 @@ void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum, */ const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, const struct bitcoin_tx *tx, int outnum); +/** + * Helper to get the script of a script's output as a tal_arr + * + * The script attached to a `wally_tx_output` is not a `tal_arr`, so in order to keep the + * comfort of being able to call `tal_bytelen` and similar on a script we just + * return a `tal_arr` clone of the original script. + */ +const u8 *wally_tx_output_get_script(const tal_t *ctx, + const struct wally_tx_output *output); /** * Helper to get a witness script for an output. */