Browse Source

tx: remove input size assertion

this is unnecessary, and actually severely limits the functionality
of `wally_tx_add_input`, which will expand the allocated input
length if there's not enough room for the additional input

```external/libwally-core/src/transaction.c
    if (tx->num_inputs >= tx->inputs_allocation_len) {
        /* Expand the inputs array */
        struct wally_tx_input *p;
        p = realloc_array(tx->inputs, tx->inputs_allocation_len,
                          tx->num_inputs + 1, sizeof(*tx->inputs));
        ...
        tx->inputs = p;
        tx->inputs_allocation_len += 1;
```
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
cbfa045f91
  1. 7
      bitcoin/tx.c

7
bitcoin/tx.c

@ -127,11 +127,11 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
u32 outnum, u32 sequence, u32 outnum, u32 sequence,
struct amount_sat amount, u8 *script) struct amount_sat amount, u8 *script)
{ {
size_t i = tx->wtx->num_inputs;
struct wally_tx_input *input; struct wally_tx_input *input;
assert(i < tx->wtx->inputs_allocation_len); size_t i;
assert(tx->wtx != NULL); assert(tx->wtx != NULL);
i = tx->wtx->num_inputs;
wally_tx_input_init_alloc(txid->shad.sha.u.u8, wally_tx_input_init_alloc(txid->shad.sha.u.u8,
sizeof(struct bitcoin_txid), outnum, sequence, sizeof(struct bitcoin_txid), outnum, sequence,
script, tal_bytelen(script), script, tal_bytelen(script),
@ -141,6 +141,9 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
wally_tx_input_free(input); wally_tx_input_free(input);
/* Now store the input amount if we know it, so we can sign later */ /* Now store the input amount if we know it, so we can sign later */
if (tal_count(tx->input_amounts) < tx->wtx->num_inputs)
tal_resize(&tx->input_amounts, tx->wtx->num_inputs);
tx->input_amounts[i] = tal_free(tx->input_amounts[i]); tx->input_amounts[i] = tal_free(tx->input_amounts[i]);
tx->input_amounts[i] = tal_dup(tx, struct amount_sat, &amount); tx->input_amounts[i] = tal_dup(tx, struct amount_sat, &amount);

Loading…
Cancel
Save