mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 06:54:30 +01:00
wire: Move bitcoin_tx serialization from htlc_wire to wire
Removes the need to keep a second transaction around and marking it as `noleak`, just to make sure that dependencies are not free'd along with the original tx. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user