1 #ifndef LIGHTNING_WIRE_WIRE_H
2 #define LIGHTNING_WIRE_WIRE_H
3 #include "config.h"
4 #include <ccan/short_types/short_types.h>
5 #include <ccan/tal/tal.h>
6 #include <common/errcode.h>
7 #include <secp256k1_recovery.h>
8 #include <stdlib.h>
9 
10 struct ripemd160;
11 struct sha256;
12 struct siphash_seed;
13 
14 /* Makes generate-wire.py work */
15 typedef char wirestring;
16 typedef char utf8;
17 
18 /* Read the type; returns -1 if not long enough.  cursor is a tal ptr. */
19 int fromwire_peektype(const u8 *cursor);
20 void *fromwire_fail(const u8 **cursor, size_t *max);
21 
22 void towire(u8 **pptr, const void *data, size_t len);
23 void towire_secp256k1_ecdsa_signature(u8 **pptr,
24 			      const secp256k1_ecdsa_signature *signature);
25 void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr,
26 			      const secp256k1_ecdsa_recoverable_signature *rsig);
27 void towire_sha256(u8 **pptr, const struct sha256 *sha256);
28 void towire_ripemd160(u8 **pptr, const struct ripemd160 *ripemd);
29 void towire_u8(u8 **pptr, u8 v);
30 void towire_u16(u8 **pptr, u16 v);
31 void towire_u32(u8 **pptr, u32 v);
32 void towire_u64(u8 **pptr, u64 v);
33 void towire_tu16(u8 **pptr, u16 v);
34 void towire_tu32(u8 **pptr, u32 v);
35 void towire_tu64(u8 **pptr, u64 v);
36 void towire_pad(u8 **pptr, size_t num);
37 void towire_bool(u8 **pptr, bool v);
38 void towire_errcode_t(u8 **pptr, errcode_t v);
39 
40 void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
41 void towire_utf8_array(u8 **pptr, const char *arr, size_t num);
42 
43 void towire_wirestring(u8 **pptr, const char *str);
44 void towire_siphash_seed(u8 **cursor, const struct siphash_seed *seed);
45 
46 const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
47 u8 fromwire_u8(const u8 **cursor, size_t *max);
48 u16 fromwire_u16(const u8 **cursor, size_t *max);
49 u32 fromwire_u32(const u8 **cursor, size_t *max);
50 u64 fromwire_u64(const u8 **cursor, size_t *max);
51 u16 fromwire_tu16(const u8 **cursor, size_t *max);
52 u32 fromwire_tu32(const u8 **cursor, size_t *max);
53 u64 fromwire_tu64(const u8 **cursor, size_t *max);
54 bool fromwire_bool(const u8 **cursor, size_t *max);
55 errcode_t fromwire_errcode_t(const u8 **cursor, size_t *max);
56 void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max,
57 					secp256k1_ecdsa_signature *signature);
58 void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor,
59 				    size_t *max,
60 				    secp256k1_ecdsa_recoverable_signature *rsig);
61 void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256);
62 void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd);
63 void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
64 
65 void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
66 void fromwire_utf8_array(const u8 **cursor, size_t *max, char *arr, size_t num);
67 u8 *fromwire_tal_arrn(const tal_t *ctx,
68 		       const u8 **cursor, size_t *max, size_t num);
69 char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);
70 void fromwire_siphash_seed(const u8 **cursor, size_t *max,
71 			   struct siphash_seed *seed);
72 
73 #if !EXPERIMENTAL_FEATURES
74 /* Stubs, as this subtype is only defined when EXPERIMENTAL_FEATURES */
75 struct onionmsg_path;
76 
77 void towire_onionmsg_path(u8 **p, const struct onionmsg_path *onionmsg_path);
78 struct onionmsg_path *
79 fromwire_onionmsg_path(const tal_t *ctx, const u8 **cursor, size_t *plen);
80 #endif /* EXPERIMENTAL_FEATURES */
81 #endif /* LIGHTNING_WIRE_WIRE_H */
82