diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 9ffe7376a..5401f8179 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -17,6 +17,21 @@ #define SEGREGATED_WITNESS_FLAG 0x1 +/* FIXME: When wally exposes this, we will clash and can remove this one */ +int wally_tx_clone(struct wally_tx *tx, struct wally_tx **output) +{ + u8 *txlin = linearize_wtx(NULL, tx); + int flags = WALLY_TX_FLAG_USE_WITNESS; + int ret; + + if (chainparams->is_elements) + flags |= WALLY_TX_FLAG_USE_ELEMENTS; + + ret = wally_tx_from_bytes(txlin, tal_bytelen(txlin), flags, output); + tal_free(txlin); + return ret; +} + int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, u8 *wscript, struct amount_sat amount) { diff --git a/bitcoin/tx.h b/bitcoin/tx.h index b9c69048d..f5b2b2919 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -217,4 +217,6 @@ void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output) * Get the base64 string encoded PSBT of a bitcoin transaction. */ char *bitcoin_tx_to_psbt_base64(const tal_t *ctx, struct bitcoin_tx *tx); + +int wally_tx_clone(struct wally_tx *tx, struct wally_tx **output); #endif /* LIGHTNING_BITCOIN_TX_H */