From a4f290daba28d361e77f7cd486fae59593febcd7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 18 Aug 2017 14:13:52 +0930 Subject: [PATCH] htlc_wire: marshal/unmarshal shachain object. We want to hand it to onchaind. Signed-off-by: Rusty Russell --- lightningd/htlc_wire.c | 32 ++++++++++++++++++++++++++++++++ lightningd/htlc_wire.h | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/lightningd/htlc_wire.c b/lightningd/htlc_wire.c index b62ec1be5..04640aa63 100644 --- a/lightningd/htlc_wire.c +++ b/lightningd/htlc_wire.c @@ -1,3 +1,5 @@ +#include +#include #include #include @@ -43,6 +45,19 @@ void towire_side(u8 **pptr, const enum side side) towire_u8(pptr, side); } +void towire_shachain(u8 **pptr, const struct shachain *shachain) +{ + size_t i; + + towire_u64(pptr, shachain->min_index); + towire_u32(pptr, shachain->num_valid); + + for (i = 0; i < shachain->num_valid; i++) { + towire_u64(pptr, shachain->known[i].index); + towire_sha256(pptr, &shachain->known[i].hash); + } +} + void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added) { @@ -99,3 +114,20 @@ enum side fromwire_side(const u8 **cursor, size_t *max) } return side; } + +void fromwire_shachain(const u8 **cursor, size_t *max, + struct shachain *shachain) +{ + size_t i; + + shachain->min_index = fromwire_u64(cursor, max); + shachain->num_valid = fromwire_u32(cursor, max); + if (shachain->num_valid > ARRAY_SIZE(shachain->known)) { + fromwire_fail(cursor, max); + return; + } + for (i = 0; i < shachain->num_valid; i++) { + shachain->known[i].index = fromwire_u64(cursor, max); + fromwire_sha256(cursor, max, &shachain->known[i].hash); + } +} diff --git a/lightningd/htlc_wire.h b/lightningd/htlc_wire.h index e77abfb6a..fe5c8d58c 100644 --- a/lightningd/htlc_wire.h +++ b/lightningd/htlc_wire.h @@ -7,6 +7,8 @@ #include #include +struct shachain; + /* These are how we communicate about HTLC state to the master daemon */ struct added_htlc { u64 id; @@ -38,6 +40,7 @@ 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 towire_shachain(u8 **pptr, const struct shachain *shachain); void fromwire_added_htlc(const u8 **cursor, size_t *max, struct added_htlc *added); @@ -49,4 +52,6 @@ void fromwire_changed_htlc(const u8 **cursor, size_t *max, struct changed_htlc *changed); 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); #endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */