From f918c3a0e7c3614efbe7423891d26a259e67fd24 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 20 Jun 2017 15:28:03 +0930 Subject: [PATCH] lightningd/htlc_wire: routines to marshal/unmarshal enum side. Signed-off-by: Rusty Russell --- lightningd/htlc_wire.c | 13 +++++++++++++ lightningd/htlc_wire.h | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lightningd/htlc_wire.c b/lightningd/htlc_wire.c index ac0f51819..3e6430728 100644 --- a/lightningd/htlc_wire.c +++ b/lightningd/htlc_wire.c @@ -37,6 +37,11 @@ void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed) towire_u64(pptr, changed->id); } +void towire_side(u8 **pptr, const enum side *side) +{ + towire_u8(pptr, *side); +} + void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added) { @@ -83,3 +88,11 @@ void fromwire_changed_htlc(const u8 **cursor, size_t *max, changed->id = fromwire_u64(cursor, max); } +void fromwire_side(const u8 **cursor, size_t *max, enum side *side) +{ + *side = fromwire_u8(cursor, max); + if (*side >= NUM_SIDES) { + *side = NUM_SIDES; + fromwire_fail(cursor, max); + } +} diff --git a/lightningd/htlc_wire.h b/lightningd/htlc_wire.h index 2e7975c02..5c918620c 100644 --- a/lightningd/htlc_wire.h +++ b/lightningd/htlc_wire.h @@ -3,7 +3,7 @@ #include "config.h" #include #include -#include +#include #include /* These are how we communicate about HTLC state to the master daemon */ @@ -30,12 +30,13 @@ struct changed_htlc { 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 towire_htlc_state(u8 **pptr, const enum htlc_state *hstate); +void towire_side(u8 **pptr, const enum side *side); + void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added); void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max, @@ -46,4 +47,5 @@ void fromwire_changed_htlc(const u8 **cursor, size_t *max, struct changed_htlc *changed); void fromwire_htlc_state(const u8 **cursor, size_t *max, enum htlc_state *hstate); +void fromwire_side(const u8 **cursor, size_t *max, enum side *side); #endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */