Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ int wally_psbt_to_bytes(
return ret;
}
p += varint_to_bytes(tx_len, p);
ret = wally_tx_to_bytes(psbt->tx, 0, p, end - p, &tx_len);
ret = wally_partial_tx_to_bytes(psbt->tx, 0, p, end - p, true, &tx_len);
if (ret != WALLY_OK) {
return ret;
}
Expand Down
26 changes: 20 additions & 6 deletions src/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,8 @@ static int tx_to_bytes(const struct wally_tx *tx,
uint32_t flags,
unsigned char *bytes_out, size_t len,
size_t *written,
bool is_elements)
bool is_elements,
bool partial_ok)
{
size_t n, i, j, witness_count;
const bool anyonecanpay = opts && opts->sighash & WALLY_SIGHASH_ANYONECANPAY;
Expand All @@ -1983,11 +1984,14 @@ static int tx_to_bytes(const struct wally_tx *tx,
if (written)
*written = 0;

if (!is_valid_tx(tx) || !tx->num_inputs || !tx->num_outputs ||
if (!is_valid_tx(tx) ||
(flags & ~WALLY_TX_FLAG_USE_WITNESS) || !bytes_out || !written ||
tx_get_length(tx, opts, flags, &n, is_elements) != WALLY_OK)
return WALLY_EINVAL;

if (!partial_ok && (!tx->num_inputs || !tx->num_outputs))
return WALLY_EINVAL;

if (opts && (flags & WALLY_TX_FLAG_USE_WITNESS))
return WALLY_ERROR; /* Segwit tx hashing is handled elsewhere */

Expand Down Expand Up @@ -2138,17 +2142,27 @@ static int tx_to_bytes(const struct wally_tx *tx,
return WALLY_OK;
}

int wally_tx_to_bytes(const struct wally_tx *tx, uint32_t flags,
unsigned char *bytes_out, size_t len,
size_t *written)
int wally_partial_tx_to_bytes(const struct wally_tx *tx, uint32_t flags,
unsigned char *bytes_out, size_t len,
bool partial_ok,
size_t *written)
{
size_t is_elements = 0;

#ifdef BUILD_ELEMENTS
if (wally_tx_is_elements(tx, &is_elements) != WALLY_OK)
return WALLY_EINVAL;
#endif
return tx_to_bytes(tx, NULL, flags, bytes_out, len, written, is_elements);
return tx_to_bytes(tx, NULL, flags, bytes_out, len, written, is_elements,
partial_ok);
}


int wally_tx_to_bytes(const struct wally_tx *tx, uint32_t flags,
unsigned char *bytes_out, size_t len,
size_t *written)
{
return wally_partial_tx_to_bytes(tx, flags, bytes_out, len, false, written);
}

static int tx_to_hex(const struct wally_tx *tx, uint32_t flags,
Expand Down
4 changes: 4 additions & 0 deletions src/transaction_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ int analyze_tx(const unsigned char *bytes, size_t bytes_len,
struct wally_tx_witness_stack *clone_witness(
const struct wally_tx_witness_stack *stack);
int clone_tx(struct wally_tx *tx, struct wally_tx **output);
int wally_partial_tx_to_bytes(const struct wally_tx *tx, uint32_t flags,
unsigned char *bytes_out, size_t len,
bool partial_ok,
size_t *written);

#ifdef __cplusplus
}
Expand Down