Skip to content

Commit

Permalink
wally: Post-migration cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <decker.christian@gmail.com>
  • Loading branch information
cdecker committed Mar 25, 2019
1 parent ab56d3d commit 74cb07c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
18 changes: 3 additions & 15 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
int bitcoin_tx_add_output(struct bitcoin_tx *tx, u8 *script,
struct amount_sat *amount)
{
size_t i = tx->used_outputs;
size_t i = tx->wtx->num_outputs;
struct wally_tx_output *output;
assert(i < tx->wtx->outputs_allocation_len);

Expand All @@ -26,15 +26,14 @@ int bitcoin_tx_add_output(struct bitcoin_tx *tx, u8 *script,
wally_tx_add_output(tx->wtx, output);
wally_tx_output_free(output);

tx->used_outputs++;
return i;
}

int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
u32 outnum, u32 sequence,
const struct amount_sat *amount, u8 *script)
{
size_t i = tx->used_inputs;
size_t i = tx->wtx->num_inputs;
struct wally_tx_input *input;
assert(i < tx->wtx->inputs_allocation_len);

Expand All @@ -50,7 +49,6 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
tx->input_amounts[i] = tal_free(tx->input_amounts[i]);
tx->input_amounts[i] = tal_dup(tx, struct amount_sat, amount);

tx->used_inputs++;
return i;
}

Expand All @@ -71,17 +69,13 @@ bool bitcoin_tx_check(const struct bitcoin_tx *tx)
if (written != tal_bytelen(newtx))
return false;

if (tx->used_inputs != tx->wtx->num_inputs ||
tx->used_outputs != tx->wtx->num_outputs)
return false;

return true;
}

void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum,
struct amount_sat *amount)
{
assert(outnum < tx->used_outputs);
assert(outnum < tx->wtx->num_outputs);
tx->wtx->outputs[outnum].satoshi = amount->satoshis; /* Raw: low-level helper */
}

Expand Down Expand Up @@ -285,9 +279,6 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
varint_t output_count)
{
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
tx->used_inputs = 0;
tx->used_outputs = 0;

wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,
&tx->wtx);
tal_add_destructor(tx, bitcoin_tx_destroy);
Expand All @@ -314,9 +305,6 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
tx->input_amounts =
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);

tx->used_outputs = tx->wtx->num_outputs;
tx->used_inputs = tx->wtx->num_inputs;

*cursor += wsize;
*max -= wsize;
return tx;
Expand Down
4 changes: 0 additions & 4 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ struct bitcoin_tx {
* unknown) */
struct amount_sat **input_amounts;
struct wally_tx *wtx;

/* Keep track of how many inputs and outputs were filled so far. This
* is needed since we allocate them in bulk. */
size_t used_inputs, used_outputs;
};

struct bitcoin_tx_output {
Expand Down

0 comments on commit 74cb07c

Please sign in to comment.