lightningd/htlc_wire: routines to marshal/unmarshal enum htlc_state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-06-20 15:27:03 +09:30
parent 9868e896d9
commit be1b9eb4cf
2 changed files with 22 additions and 6 deletions

View File

@ -26,9 +26,14 @@ void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed)
towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason)); towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason));
} }
void towire_htlc_state(u8 **pptr, const enum htlc_state *hstate)
{
towire_u8(pptr, *hstate);
}
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed) void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed)
{ {
towire_u8(pptr, changed->newstate); towire_htlc_state(pptr, &changed->newstate);
towire_u64(pptr, changed->id); towire_u64(pptr, changed->id);
} }
@ -61,12 +66,20 @@ void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
fromwire_u8_array(cursor, max, failed->failreason, failreason_len); fromwire_u8_array(cursor, max, failed->failreason, failreason_len);
} }
void fromwire_htlc_state(const u8 **cursor, size_t *max,
enum htlc_state *hstate)
{
*hstate = fromwire_u8(cursor, max);
if (*hstate >= HTLC_STATE_INVALID) {
*hstate = HTLC_STATE_INVALID;
fromwire_fail(cursor, max);
}
}
void fromwire_changed_htlc(const u8 **cursor, size_t *max, void fromwire_changed_htlc(const u8 **cursor, size_t *max,
struct changed_htlc *changed) struct changed_htlc *changed)
{ {
changed->newstate = fromwire_u8(cursor, max); fromwire_htlc_state(cursor, max, &changed->newstate);
changed->id = fromwire_u64(cursor, max); changed->id = fromwire_u64(cursor, max);
if (changed->newstate >= HTLC_STATE_INVALID)
fromwire_fail(cursor, max);
} }

View File

@ -30,10 +30,12 @@ struct changed_htlc {
u64 id; u64 id;
}; };
void towire_added_htlc(u8 **pptr, const struct added_htlc *added); void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled); void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed); void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed); void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
void towire_htlc_state(u8 **pptr, const enum htlc_state *hstate);
void fromwire_added_htlc(const u8 **cursor, size_t *max, void fromwire_added_htlc(const u8 **cursor, size_t *max,
struct added_htlc *added); struct added_htlc *added);
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max, void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
@ -42,5 +44,6 @@ void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
struct failed_htlc *failed); struct failed_htlc *failed);
void fromwire_changed_htlc(const u8 **cursor, size_t *max, void fromwire_changed_htlc(const u8 **cursor, size_t *max,
struct changed_htlc *changed); struct changed_htlc *changed);
void fromwire_htlc_state(const u8 **cursor, size_t *max,
enum htlc_state *hstate);
#endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */ #endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */