wally: Remove tx->input and tx->output, wally all the way!

This is what all of this has been working towards: ripping out the handwoven
transaction handling. By removing the custom parsing we can finally switch
over to using `wally_tx` as sole representation of transactions in
memory. The commit is a bit larger but it's mostly removing setters and old
references to the input and output fields.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2019-03-25 13:52:31 +01:00
committed by Rusty Russell
parent cf9f484168
commit 509bb2c7ae
6 changed files with 16 additions and 210 deletions

View File

@@ -58,7 +58,6 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx,
/* Can't have no outputs at all! */
if (num_outputs == 0)
return tal_free(tx);
tal_resize(&tx->output, num_outputs);
permute_outputs(tx, NULL, NULL);
assert(bitcoin_tx_check(tx));

View File

@@ -198,7 +198,6 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
}
assert(n <= tx->wtx->num_outputs);
tal_resize(&tx->output, n);
/* BOLT #3:
*

View File

@@ -34,27 +34,6 @@ static size_t find_best_in(struct wally_tx_input *inputs, size_t num)
return best;
}
static void swap_inputs(struct bitcoin_tx_input *inputs,
const void **map,
size_t i1, size_t i2)
{
struct bitcoin_tx_input tmpinput;
const void *tmp;
if (i1 == i2)
return;
tmpinput = inputs[i1];
inputs[i1] = inputs[i2];
inputs[i2] = tmpinput;
if (map) {
tmp = map[i1];
map[i1] = map[i2];
map[i2] = tmp;
}
}
static void swap_wally_inputs(struct wally_tx_input *inputs,
const void **map,
size_t i1, size_t i2)
@@ -99,38 +78,10 @@ void permute_inputs(struct bitcoin_tx *tx, const void **map)
best_pos = i + find_best_in(inputs + i, num_inputs - i);
/* Swap best into first place. */
swap_wally_inputs(tx->wtx->inputs, map, i, best_pos);
swap_inputs(tx->input, NULL, i, best_pos);
swap_input_amounts(tx->input_amounts, i, best_pos);
}
}
static void swap_outputs(struct bitcoin_tx_output *outputs,
const void **map,
u32 *cltvs,
size_t i1, size_t i2)
{
struct bitcoin_tx_output tmpoutput;
if (i1 == i2)
return;
tmpoutput = outputs[i1];
outputs[i1] = outputs[i2];
outputs[i2] = tmpoutput;
if (map) {
const void *tmp = map[i1];
map[i1] = map[i2];
map[i2] = tmp;
}
if (cltvs) {
u32 tmp = cltvs[i1];
cltvs[i1] = cltvs[i2];
cltvs[i2] = tmp;
}
}
static void swap_wally_outputs(struct wally_tx_output *outputs,
const void **map,
u32 *cltvs,
@@ -223,6 +174,5 @@ void permute_outputs(struct bitcoin_tx *tx, u32 *cltvs, const void **map)
/* Swap best into first place. */
swap_wally_outputs(tx->wtx->outputs, map, cltvs, i, best_pos);
swap_outputs(tx->output, NULL, NULL, i, best_pos);
}
}