Skip to content

Commit

Permalink
tx_parts: use wally to clone tx outputs
Browse files Browse the repository at this point in the history
Input cloning has not been exposed yet; I'll add that to wally in a
future release.

Changelog-None

Signed-off-by: Jon Griffiths <[email protected]>
  • Loading branch information
jgriffiths committed Jan 10, 2024
1 parent dc4dd7e commit 153a38c
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions bitcoin/tx_parts.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,6 @@ static void destroy_wally_tx_output(struct wally_tx_output *out)
wally_tx_output_free(out);
}

static struct wally_tx_output *clone_output(const struct wally_tx_output *src)
{
struct wally_tx_output *out;
int ret;

if (is_elements(chainparams)) {
ret = wally_tx_elements_output_init_alloc
(src->script, src->script_len,
src->asset, src->asset_len,
src->value, src->value_len,
src->nonce, src->nonce_len,
src->surjectionproof, src->surjectionproof_len,
src->rangeproof, src->rangeproof_len,
&out);
} else {
ret = wally_tx_output_init_alloc(src->satoshi,
src->script, src->script_len,
&out);
}
assert(ret == WALLY_OK);

tal_add_destructor(out, destroy_wally_tx_output);
return out;
}

struct tx_parts *tx_parts_from_wally_tx(const tal_t *ctx,
const struct wally_tx *wtx,
int input, int output)
Expand All @@ -93,7 +68,10 @@ struct tx_parts *tx_parts_from_wally_tx(const tal_t *ctx,
for (size_t i = 0; i < wtx->num_outputs; i++) {
if (output != -1 && output != i)
continue;
txp->outputs[i] = clone_output(&wtx->outputs[i]);
if (wally_tx_output_clone_alloc(&wtx->outputs[i],
&txp->outputs[i]) != WALLY_OK)
abort();
tal_add_destructor(txp->outputs[i], destroy_wally_tx_output);

/* Cheat a bit by also setting the numeric satoshi
* value, otherwise we end up converting a
Expand Down

0 comments on commit 153a38c

Please sign in to comment.