Browse Source

lightningd/htlc_wire: marshal/unmashal bitcoin tx.

We want to keep the last valid tx, and its signature, for broadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
bcc9ed9aa6
  1. 19
      lightningd/htlc_wire.c
  2. 3
      lightningd/htlc_wire.h

19
lightningd/htlc_wire.c

@ -1,3 +1,4 @@
#include <bitcoin/tx.h>
#include <ccan/array_size/array_size.h>
#include <ccan/crypto/shachain/shachain.h>
#include <lightningd/htlc_wire.h>
@ -58,6 +59,14 @@ 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)
{
@ -131,3 +140,13 @@ 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;
}

3
lightningd/htlc_wire.h

@ -7,6 +7,7 @@
#include <lightningd/sphinx.h>
#include <wire/gen_onion_wire.h>
struct bitcoin_tx;
struct shachain;
/* These are how we communicate about HTLC state to the master daemon */
@ -41,6 +42,7 @@ 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);
@ -54,4 +56,5 @@ 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_LIGHTNINGD_HTLC_WIRE_H */

Loading…
Cancel
Save