mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
tx: add helper for extracting script from a wally_tx
the bitcoin_tx version is basically a wrapper for the wally_tx script extraction -- here we pull it apart so we can easily get a tal'd script for a wally_tx_output
This commit is contained in:
parent
a68d79e390
commit
0388fe6db4
22
bitcoin/tx.c
22
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 u8 *wally_tx_output_get_script(const tal_t *ctx,
|
||||||
const struct bitcoin_tx *tx, int outnum)
|
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) {
|
if (output->script == NULL) {
|
||||||
/* This can happen for coinbase transactions and pegin
|
/* This can happen for coinbase transactions and pegin
|
||||||
* transactions */
|
* transactions */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = tal_dup_arr(ctx, u8, output->script, output->script_len, 0);
|
return tal_dup_arr(ctx, u8, output->script, output->script_len, 0);
|
||||||
return res;
|
}
|
||||||
|
|
||||||
|
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,
|
u8 *bitcoin_tx_output_get_witscript(const tal_t *ctx, const struct bitcoin_tx *tx,
|
||||||
|
@ -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);
|
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.
|
* Helper to get a witness script for an output.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user