diff --git a/lightningd/htlc_wire.c b/lightningd/htlc_wire.c index e7f7048c0..b62ec1be5 100644 --- a/lightningd/htlc_wire.c +++ b/lightningd/htlc_wire.c @@ -27,20 +27,20 @@ void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed) towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason)); } -void towire_htlc_state(u8 **pptr, const enum htlc_state *hstate) +void towire_htlc_state(u8 **pptr, const enum htlc_state hstate) { - towire_u8(pptr, *hstate); + towire_u8(pptr, hstate); } void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed) { - towire_htlc_state(pptr, &changed->newstate); + towire_htlc_state(pptr, changed->newstate); towire_u64(pptr, changed->id); } -void towire_side(u8 **pptr, const enum side *side) +void towire_side(u8 **pptr, const enum side side) { - towire_u8(pptr, *side); + towire_u8(pptr, side); } void fromwire_added_htlc(const u8 **cursor, size_t *max, @@ -73,28 +73,29 @@ void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max, fromwire_u8_array(cursor, max, failed->failreason, failreason_len); } -void fromwire_htlc_state(const u8 **cursor, size_t *max, - enum htlc_state *hstate) +enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max) { - *hstate = fromwire_u8(cursor, max); - if (*hstate >= HTLC_STATE_INVALID) { - *hstate = HTLC_STATE_INVALID; + enum htlc_state hstate = fromwire_u8(cursor, max); + if (hstate >= HTLC_STATE_INVALID) { + hstate = HTLC_STATE_INVALID; fromwire_fail(cursor, max); } + return hstate; } void fromwire_changed_htlc(const u8 **cursor, size_t *max, struct changed_htlc *changed) { - fromwire_htlc_state(cursor, max, &changed->newstate); + changed->newstate = fromwire_htlc_state(cursor, max); changed->id = fromwire_u64(cursor, max); } -void fromwire_side(const u8 **cursor, size_t *max, enum side *side) +enum side fromwire_side(const u8 **cursor, size_t *max) { - *side = fromwire_u8(cursor, max); - if (*side >= NUM_SIDES) { - *side = NUM_SIDES; + enum side side = fromwire_u8(cursor, max); + if (side >= NUM_SIDES) { + side = NUM_SIDES; fromwire_fail(cursor, max); } + return side; } diff --git a/lightningd/htlc_wire.h b/lightningd/htlc_wire.h index 734f75a1e..e77abfb6a 100644 --- a/lightningd/htlc_wire.h +++ b/lightningd/htlc_wire.h @@ -36,8 +36,8 @@ 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 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); @@ -47,7 +47,6 @@ 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); -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); +enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max); +enum side fromwire_side(const u8 **cursor, size_t *max); #endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */ diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 6f3eb3879..c17f209eb 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -36,7 +36,7 @@ class FieldType(object): self.tsize = FieldType._typesize(name) def is_assignable(self): - return self.name in ['u8', 'u16', 'u32', 'u64', 'bool'] + return self.name in ['u8', 'u16', 'u32', 'u64', 'bool'] or self.name.startswith('enum ') # We only accelerate the u8 case: it's common and trivial. def has_array_helper(self):