lightningd/htlc_wire: wire types for sending HTLCs to/from channel daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
7c9b66e67f
commit
ad3ab53fa4
|
@ -48,6 +48,7 @@ LIGHTNINGD_LIB_SRC := \
|
|||
lightningd/funding_tx.c \
|
||||
lightningd/gossip_msg.c \
|
||||
lightningd/htlc_tx.c \
|
||||
lightningd/htlc_wire.c \
|
||||
lightningd/key_derive.c \
|
||||
lightningd/msg_queue.c \
|
||||
lightningd/peer_failed.c \
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
#include <lightningd/htlc_wire.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
/* FIXME: We could adapt tools/generate-wire.py to generate structures
|
||||
* and code like this. */
|
||||
void towire_added_htlc(u8 **pptr, const struct added_htlc *added)
|
||||
{
|
||||
towire_u64(pptr, added->id);
|
||||
towire_u64(pptr, added->amount_msat);
|
||||
towire_sha256(pptr, &added->payment_hash);
|
||||
towire_u32(pptr, added->cltv_expiry);
|
||||
towire(pptr, added->onion_routing_packet,
|
||||
sizeof(added->onion_routing_packet));
|
||||
}
|
||||
|
||||
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
|
||||
{
|
||||
towire_u64(pptr, fulfilled->id);
|
||||
towire_preimage(pptr, &fulfilled->payment_preimage);
|
||||
}
|
||||
|
||||
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed)
|
||||
{
|
||||
towire_u64(pptr, failed->id);
|
||||
towire_u16(pptr, tal_count(failed->failreason));
|
||||
towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason));
|
||||
}
|
||||
|
||||
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed)
|
||||
{
|
||||
towire_u8(pptr, changed->newstate);
|
||||
towire_u64(pptr, changed->id);
|
||||
}
|
||||
|
||||
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
||||
struct added_htlc *added)
|
||||
{
|
||||
added->id = fromwire_u64(cursor, max);
|
||||
added->amount_msat = fromwire_u64(cursor, max);
|
||||
fromwire_sha256(cursor, max, &added->payment_hash);
|
||||
added->cltv_expiry = fromwire_u32(cursor, max);
|
||||
fromwire(cursor, max, added->onion_routing_packet,
|
||||
sizeof(added->onion_routing_packet));
|
||||
}
|
||||
|
||||
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
|
||||
struct fulfilled_htlc *fulfilled)
|
||||
{
|
||||
fulfilled->id = fromwire_u64(cursor, max);
|
||||
fromwire_preimage(cursor, max, &fulfilled->payment_preimage);
|
||||
}
|
||||
|
||||
void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct failed_htlc *failed)
|
||||
{
|
||||
u16 failreason_len;
|
||||
|
||||
failed->id = fromwire_u64(cursor, max);
|
||||
failreason_len = fromwire_u16(cursor, max);
|
||||
failed->failreason = tal_arr(ctx, u8, failreason_len);
|
||||
fromwire_u8_array(cursor, max, failed->failreason, failreason_len);
|
||||
}
|
||||
|
||||
void fromwire_changed_htlc(const u8 **cursor, size_t *max,
|
||||
struct changed_htlc *changed)
|
||||
{
|
||||
changed->newstate = fromwire_u8(cursor, max);
|
||||
changed->id = fromwire_u64(cursor, max);
|
||||
|
||||
if (changed->newstate >= HTLC_STATE_INVALID)
|
||||
fromwire_fail(cursor, max);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef LIGHTNING_LIGHTNINGD_HTLC_WIRE_H
|
||||
#define LIGHTNING_LIGHTNINGD_HTLC_WIRE_H
|
||||
#include "config.h"
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <daemon/htlc_state.h>
|
||||
#include <lightningd/sphinx.h>
|
||||
|
||||
/* These are how we communicate about HTLC state to the master daemon */
|
||||
struct added_htlc {
|
||||
u64 id;
|
||||
u64 amount_msat;
|
||||
struct sha256 payment_hash;
|
||||
u32 cltv_expiry;
|
||||
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
|
||||
};
|
||||
|
||||
struct fulfilled_htlc {
|
||||
u64 id;
|
||||
struct preimage payment_preimage;
|
||||
};
|
||||
|
||||
struct failed_htlc {
|
||||
u64 id;
|
||||
u8 *failreason;
|
||||
};
|
||||
|
||||
struct changed_htlc {
|
||||
enum htlc_state newstate;
|
||||
u64 id;
|
||||
};
|
||||
|
||||
void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
|
||||
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
|
||||
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
|
||||
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
|
||||
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
||||
struct added_htlc *added);
|
||||
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
|
||||
struct fulfilled_htlc *fulfilled);
|
||||
void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct failed_htlc *failed);
|
||||
void fromwire_changed_htlc(const u8 **cursor, size_t *max,
|
||||
struct changed_htlc *changed);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */
|
|
@ -27,6 +27,7 @@ type2size = {
|
|||
# These struct array helpers require a context to allocate from.
|
||||
varlen_structs = [
|
||||
'gossip_getnodes_entry',
|
||||
'failed_htlc',
|
||||
]
|
||||
|
||||
class FieldType(object):
|
||||
|
|
Loading…
Reference in New Issue