wire: understand struct preimage, don't treat it as sha256.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-03-29 21:26:15 +10:30
parent 3a9c559dc6
commit d072f2ec06
5 changed files with 18 additions and 1 deletions

View File

@ -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'),

View File

@ -1,5 +1,6 @@
#include "utils.h"
#include "wire.h"
#include <bitcoin/preimage.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/shadouble.h>
#include <ccan/endian/endian.h>
@ -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));

View File

@ -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;

View File

@ -1,5 +1,6 @@
#include "utils.h"
#include "wire.h"
#include <bitcoin/preimage.h>
#include <bitcoin/shadouble.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
@ -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));

View File

@ -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);