diff --git a/common/htlc_wire.c b/common/htlc_wire.c index a3077400e..490f7c007 100644 --- a/common/htlc_wire.c +++ b/common/htlc_wire.c @@ -60,14 +60,6 @@ void towire_shachain(u8 **pptr, const struct shachain *shachain) } } -void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx) -{ - u8 *txlin = linearize_tx(NULL, tx); - - towire(pptr, txlin, tal_len(txlin)); - tal_free(txlin); -} - void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added) { @@ -141,16 +133,3 @@ void fromwire_shachain(const u8 **cursor, size_t *max, fromwire_sha256(cursor, max, &shachain->known[i].hash); } } - -void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx) -{ - /* FIXME: We'd really expect to allocate tx ourselves, but - * for the sake of simple structures, we don't write the - * generator that way. */ - struct bitcoin_tx *tx2 = pull_bitcoin_tx(tx, cursor, max); - if (tx2) { - *tx = *tx2; - /* This hangs around with tx until freed */ - notleak(tx2); - } -} diff --git a/common/htlc_wire.h b/common/htlc_wire.h index 020e554f2..ad4642ad5 100644 --- a/common/htlc_wire.h +++ b/common/htlc_wire.h @@ -42,7 +42,6 @@ void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed); void towire_htlc_state(u8 **pptr, const enum htlc_state hstate); void towire_side(u8 **pptr, const enum side side); void towire_shachain(u8 **pptr, const struct shachain *shachain); -void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx); void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added); @@ -56,5 +55,4 @@ enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max); enum side fromwire_side(const u8 **cursor, size_t *max); void fromwire_shachain(const u8 **cursor, size_t *max, struct shachain *shachain); -void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx); #endif /* LIGHTNING_COMMON_HTLC_WIRE_H */ diff --git a/wire/fromwire.c b/wire/fromwire.c index dace8bd04..03e5a5cbd 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -228,3 +228,7 @@ void derive_channel_id(struct channel_id *channel_id, channel_id->id[sizeof(*channel_id)-1] ^= txout; } +void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx) +{ + pull_bitcoin_tx_onto(tx, cursor, max, tx); +} diff --git a/wire/towire.c b/wire/towire.c index 2e0c0eb04..44927a527 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -153,3 +153,11 @@ void towire_pad(u8 **pptr, size_t num) tal_resize(pptr, oldsize + num); memset(*pptr + oldsize, 0, num); } + +void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx) +{ + tal_t *tmpctx = tal_tmpctx(NULL); + u8 *lin = linearize_tx(tmpctx, tx); + towire_u8_array(pptr, lin, tal_len(lin)); + tal_free(tmpctx); +} diff --git a/wire/wire.h b/wire/wire.h index ad0ce699e..ca17ffd82 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -54,6 +54,8 @@ void towire_bool(u8 **pptr, bool v); void towire_u8_array(u8 **pptr, const u8 *arr, size_t num); +void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx); + const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n); u8 fromwire_u8(const u8 **cursor, size_t *max); u16 fromwire_u16(const u8 **cursor, size_t *max); @@ -84,4 +86,6 @@ void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd void fromwire_pad(const u8 **cursor, size_t *max, size_t num); void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num); + +void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx); #endif /* LIGHTNING_WIRE_WIRE_H */