mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
psbt: create new_psbt method
Move all psbt creation into single method, new_psbt note that if a psbt is init'd for a transaction that's deserialized with scripts etc already attached, then set_global_tx will fail. instead, we empty all of this out first. if the tx is being re-init'd from a tx source that had a psbt attached (e.g. fromwire_) then the script/witness data will get populated appropriatel from there.
This commit is contained in:
15
bitcoin/tx.c
15
bitcoin/tx.c
@@ -478,7 +478,6 @@ 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);
|
||||
|
||||
@@ -496,11 +495,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
|
||||
tx->wtx->locktime = nlocktime;
|
||||
tx->wtx->version = 2;
|
||||
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);
|
||||
tx->psbt = new_psbt(tx, tx->wtx);
|
||||
|
||||
return tx;
|
||||
}
|
||||
@@ -519,7 +514,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, ret;
|
||||
int flags = WALLY_TX_FLAG_USE_WITNESS;
|
||||
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
|
||||
|
||||
if (chainparams->is_elements)
|
||||
@@ -546,11 +541,7 @@ 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);
|
||||
|
||||
tx->psbt = new_psbt(tx, tx->wtx);
|
||||
|
||||
*cursor += wsize;
|
||||
*max -= wsize;
|
||||
|
||||
Reference in New Issue
Block a user