Skip to content

Commit

Permalink
wires: towire/fromwire for wally_tx
Browse files Browse the repository at this point in the history
We're eventually moving away from 'bitcoin_tx
  • Loading branch information
niftynei authored and rustyrussell committed Oct 20, 2020
1 parent 3c98bec commit 82c0b48
Show file tree
Hide file tree
Showing 39 changed files with 80 additions and 48 deletions.
53 changes: 41 additions & 12 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,32 +547,45 @@ struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psb
return tx;
}

struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
size_t *max)
static struct wally_tx *pull_wtx(const tal_t *ctx,
const u8 **cursor,
size_t *max)
{
int flags = WALLY_TX_FLAG_USE_WITNESS;
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
struct wally_tx *wtx;

if (chainparams->is_elements)
flags |= WALLY_TX_FLAG_USE_ELEMENTS;

tal_wally_start();
if (wally_tx_from_bytes(*cursor, *max, flags, &tx->wtx) != WALLY_OK) {
if (wally_tx_from_bytes(*cursor, *max, flags, &wtx) != WALLY_OK) {
fromwire_fail(cursor, max);
tx = tal_free(tx);
wtx = tal_free(wtx);
}
tal_wally_end(tx);
tal_wally_end(tal_steal(ctx, wtx));

if (tx) {
if (wtx) {
size_t wsize;
tal_add_destructor(tx, bitcoin_tx_destroy);
tx->chainparams = chainparams;
tx->psbt = new_psbt(tx, tx->wtx);

wally_tx_get_length(tx->wtx, flags, &wsize);
wally_tx_get_length(wtx, flags, &wsize);
*cursor += wsize;
*max -= wsize;
}

return wtx;
}

struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
size_t *max)
{
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
tx->wtx = pull_wtx(tx, cursor, max);
if (!tx->wtx)
return tal_free(tx);

tal_add_destructor(tx, bitcoin_tx_destroy);
tx->chainparams = chainparams;
tx->psbt = new_psbt(tx, tx->wtx);

return tx;
}

Expand Down Expand Up @@ -691,6 +704,16 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
return tx;
}

struct wally_tx *fromwire_wally_tx(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
struct wally_tx *wtx;
wtx = pull_wtx(ctx, cursor, max);
if (!wtx)
return fromwire_fail(cursor, max);
return wtx;
}

void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid)
{
towire_sha256_double(pptr, &txid->shad);
Expand All @@ -704,6 +727,12 @@ void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
towire_wally_psbt(pptr, tx->psbt);
}

void towire_wally_tx(u8 **pptr, const struct wally_tx *wtx)
{
u8 *lin = linearize_wtx(tmpctx, wtx);
towire_u8_array(pptr, lin, tal_count(lin));
}

struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
Expand Down
2 changes: 2 additions & 0 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
const u8 **cursor, size_t *max);
struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
const u8 **cursor, size_t *max);
struct wally_tx *fromwire_wally_tx(const tal_t *ctx, const u8 **cursor, size_t *max);
void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid);
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output);
void towire_wally_tx(u8 **pptr, const struct wally_tx *wtx);

/* Various weights of transaction parts. */
size_t bitcoin_tx_core_weight(size_t num_inputs, size_t num_outputs);
Expand Down
2 changes: 1 addition & 1 deletion channeld/channeld_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion channeld/channeld_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion closingd/closingd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion closingd/closingd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/peer_status_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/peer_status_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/status_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/status_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectd/connectd_gossipd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectd/connectd_gossipd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectd/connectd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectd/connectd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossip_store_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossip_store_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossipd_peerd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossipd_peerd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossipd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gossipd/gossipd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hsmd/hsmd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hsmd/hsmd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion onchaind/onchaind_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion onchaind/onchaind_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openingd/dualopend_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openingd/dualopend_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openingd/openingd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openingd/openingd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/generate-wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class Type(FieldSet):
'route_hop',
'tx_parts',
'wally_psbt',
'wally_tx',
]

# Some BOLT types are re-typed based on their field name
Expand Down
2 changes: 1 addition & 1 deletion wire/common_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/common_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/onion_printgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/onion_printgen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/onion_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/onion_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/peer_printgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/peer_printgen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/peer_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wire/peer_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82c0b48

Please sign in to comment.