diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 2d7cbbec1..7c5a36656 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -14,6 +14,7 @@ type2size = { 'struct short_channel_id': 8, 'struct ipv6': 16, 'secp256k1_ecdsa_signature': 64, + 'struct preimage': 32, 'struct pubkey': 33, 'struct sha256': 32, 'u64': 8, @@ -57,6 +58,7 @@ typemap = { ('update_fail_htlc', 'reason'): FieldType('u8'), ('node_announcement', 'alias'): FieldType('u8'), ('update_add_htlc', 'onion_routing_packet'): FieldType('u8'), + ('update_fulfill_htlc', 'payment_preimage'): FieldType('struct preimage'), ('error', 'data'): FieldType('u8'), ('shutdown', 'scriptpubkey'): FieldType('u8'), ('node_announcement', 'rgb_color'): FieldType('u8'), diff --git a/wire/fromwire.c b/wire/fromwire.c index 3859525fa..ef7ebf656 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -1,5 +1,6 @@ #include "utils.h" #include "wire.h" +#include #include #include #include @@ -150,6 +151,11 @@ void fromwire_sha256_double(const u8 **cursor, size_t *max, fromwire_sha256(cursor, max, &sha256d->sha); } +void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage) +{ + fromwire(cursor, max, preimage, sizeof(*preimage)); +} + void fromwire_ipv6(const u8 **cursor, size_t *max, struct ipv6 *ipv6) { fromwire(cursor, max, ipv6, sizeof(*ipv6)); diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index c8f7d3eda..3f22701f9 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -112,7 +112,7 @@ struct msg_accept_channel { struct msg_update_fulfill_htlc { struct channel_id channel_id; u64 id; - struct sha256 payment_preimage; + struct preimage payment_preimage; }; struct msg_shutdown { struct channel_id channel_id; diff --git a/wire/towire.c b/wire/towire.c index 3ec232cda..45b63e5a3 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -1,5 +1,6 @@ #include "utils.h" #include "wire.h" +#include #include #include #include @@ -94,6 +95,11 @@ void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d) towire_sha256(pptr, &sha256d->sha); } +void towire_preimage(u8 **pptr, const struct preimage *preimage) +{ + towire(pptr, preimage, sizeof(*preimage)); +} + void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6) { towire(pptr, ipv6, sizeof(*ipv6)); diff --git a/wire/wire.h b/wire/wire.h index 86639f82b..2188334a6 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -20,6 +20,7 @@ struct channel_id { struct ipv6 { u8 addr[16]; }; +struct preimage; /* Read the type; returns -1 if not long enough. cursor is a tal ptr. */ int fromwire_peektype(const u8 *cursor); @@ -34,6 +35,7 @@ void towire_short_channel_id(u8 **pptr, const struct short_channel_id *short_channel_id); void towire_sha256(u8 **pptr, const struct sha256 *sha256); void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d); +void towire_preimage(u8 **pptr, const struct preimage *preimage); void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6); void towire_u8(u8 **pptr, u8 v); void towire_u16(u8 **pptr, u16 v); @@ -61,6 +63,7 @@ void fromwire_short_channel_id(const u8 **cursor, size_t *max, void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256); void fromwire_sha256_double(const u8 **cursor, size_t *max, struct sha256_double *sha256d); +void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage); void fromwire_ipv6(const u8 **cursor, size_t *max, struct ipv6 *ipv6); void fromwire_pad(const u8 **cursor, size_t *max, size_t num);