Browse Source

wally: Add wally_tx in bitcoin_tx

Allows us to slowly migrate individual parts.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pr-2587
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
9609d762c8
  1. 15
      bitcoin/tx.c
  2. 2
      bitcoin/tx.h

15
bitcoin/tx.c

@ -328,12 +328,22 @@ void bitcoin_txid(const struct bitcoin_tx *tx, struct bitcoin_txid *txid)
sha256_double_done(&ctx, &txid->shad);
}
/* Use the bitcoin_tx destructor to also free the wally_tx */
static void bitcoin_tx_destroy(struct bitcoin_tx *tx)
{
wally_tx_free(tx->wtx);
}
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);
size_t i;
wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,
&tx->wtx);
tal_add_destructor(tx, bitcoin_tx_destroy);
tx->output = tal_arrz(tx, struct bitcoin_tx_output, output_count);
tx->input = tal_arrz(tx, struct bitcoin_tx_input, input_count);
for (i = 0; i < tal_count(tx->input); i++) {
@ -441,6 +451,11 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
u64 count;
u8 flag = 0;
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
if (wally_tx_from_bytes(*cursor, *max, 0, &tx->wtx) != WALLY_OK) {
*cursor = 0;
return tal_free(tx);
}
tal_add_destructor(tx, bitcoin_tx_destroy);
tx->version = pull_le32(cursor, max);
count = pull_length(cursor, max, 32 + 4 + 4 + 1);

2
bitcoin/tx.h

@ -8,6 +8,7 @@
#include <ccan/structeq/structeq.h>
#include <ccan/tal/tal.h>
#include <common/amount.h>
#include <wally_transaction.h>
struct bitcoin_txid {
struct sha256_double shad;
@ -20,6 +21,7 @@ struct bitcoin_tx {
struct bitcoin_tx_input *input;
struct bitcoin_tx_output *output;
u32 lock_time;
struct wally_tx *wtx;
};
struct bitcoin_tx_output {

Loading…
Cancel
Save