tx_parts: use wally to clone tx outputs

Input cloning has not been exposed yet; I'll add that to wally in a
future release.

Changelog-None

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
This commit is contained in:
Jon Griffiths 2023-11-20 15:26:58 +13:00 committed by Christian Decker
parent 23a04d1bba
commit 2e670a2a62

View file

@ -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)
@ -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