diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 3b9c112ea..60196634d 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -429,6 +429,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count, varint_t output_count, u32 nlocktime) { + int ret; struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx); assert(chainparams); @@ -447,6 +448,12 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, tx->wtx->version = 2; tx->output_witscripts = tal_arrz(tx, struct witscript*, output_count); tx->chainparams = chainparams; + + ret = wally_psbt_init_alloc(input_count, output_count, + 0, &tx->psbt); + assert(ret == WALLY_OK); + ret = wally_psbt_set_global_tx(tx->psbt, tx->wtx); + return tx; } @@ -467,7 +474,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor, size_t *max) { size_t wsize; - int flags = WALLY_TX_FLAG_USE_WITNESS; + int flags = WALLY_TX_FLAG_USE_WITNESS, ret; struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx); if (chainparams->is_elements) @@ -494,6 +501,12 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor, tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len); tx->chainparams = chainparams; + ret = wally_psbt_init_alloc(tx->wtx->num_inputs, tx->wtx->num_outputs, + 0, &tx->psbt); + assert(ret == WALLY_OK); + ret = wally_psbt_set_global_tx(tx->psbt, tx->wtx); + + *cursor += wsize; *max -= wsize; return tx; diff --git a/bitcoin/tx.h b/bitcoin/tx.h index 13651d6b2..057d50286 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -8,9 +8,11 @@ #include #include #include +#include #include #define BITCOIN_TX_DEFAULT_SEQUENCE 0xFFFFFFFF +struct wally_psbt; struct witscript { u8 *ptr; @@ -33,6 +35,9 @@ struct bitcoin_tx { /* Keep a reference to the ruleset we have to abide by */ const struct chainparams *chainparams; + + /* psbt struct */ + struct wally_psbt *psbt; }; struct bitcoin_tx_output { diff --git a/common/permute_tx.c b/common/permute_tx.c index 7de385d73..291667394 100644 --- a/common/permute_tx.c +++ b/common/permute_tx.c @@ -1,6 +1,7 @@ #include "permute_tx.h" #include #include +#include static bool input_better(const struct wally_tx_input *a, const struct wally_tx_input *b)