diff --git a/wire/fromwire.c b/wire/fromwire.c index 6e89583d4..9c51e51a3 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -1,6 +1,7 @@ #include "utils.h" #include "wire.h" #include +#include #include #include #include @@ -100,6 +101,11 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey) fail_pull(cursor, max); } +void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey) +{ + fromwire(cursor, max, privkey->secret, sizeof(privkey->secret)); +} + void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, secp256k1_ecdsa_signature *sig) { @@ -132,6 +138,12 @@ void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256) fromwire(cursor, max, sha256, sizeof(*sha256)); } +void fromwire_sha256_double(const u8 **cursor, size_t *max, + struct sha256_double *sha256d) +{ + fromwire_sha256(cursor, max, &sha256d->sha); +} + void fromwire_ipv6(const u8 **cursor, size_t *max, struct ipv6 *ipv6) { fromwire(cursor, max, ipv6, sizeof(*ipv6)); @@ -142,6 +154,30 @@ void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num) fromwire(cursor, max, arr, num); } +void fromwire_u32_array(const u8 **cursor, size_t *max, u32 *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + arr[i] = fromwire_u32(cursor, max); +} + +void fromwire_u64_array(const u8 **cursor, size_t *max, u64 *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + arr[i] = fromwire_u64(cursor, max); +} + +void fromwire_bool_array(const u8 **cursor, size_t *max, bool *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + arr[i] = fromwire_bool(cursor, max); +} + void fromwire_pad(const u8 **cursor, size_t *max, size_t num) { fromwire(cursor, max, NULL, num); @@ -156,6 +192,14 @@ void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max, fromwire_secp256k1_ecdsa_signature(cursor, max, arr + i); } +void fromwire_sha256_double_array(const u8 **cursor, size_t *max, + struct sha256_double *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + fromwire_sha256_double(cursor, max, arr + i); +} static char *fmt_channel_id(const tal_t *ctx, const struct channel_id *id) { return tal_fmt(ctx, "%u/%u/%u", id->blocknum, id->txnum, id->outnum); diff --git a/wire/towire.c b/wire/towire.c index 7b42330ed..a78a8c177 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -1,5 +1,6 @@ #include "utils.h" #include "wire.h" +#include #include #include #include @@ -52,6 +53,11 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey) towire(pptr, output, outputlen); } +void towire_privkey(u8 **pptr, const struct privkey *privkey) +{ + towire(pptr, privkey->secret, sizeof(privkey->secret)); +} + void towire_secp256k1_ecdsa_signature(u8 **pptr, const secp256k1_ecdsa_signature *sig) { @@ -77,6 +83,11 @@ void towire_sha256(u8 **pptr, const struct sha256 *sha256) towire(pptr, sha256, sizeof(*sha256)); } +void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d) +{ + towire_sha256(pptr, &sha256d->sha); +} + void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6) { towire(pptr, ipv6, sizeof(*ipv6)); @@ -87,6 +98,30 @@ void towire_u8_array(u8 **pptr, const u8 *arr, size_t num) towire(pptr, arr, num); } +void towire_u32_array(u8 **pptr, const u32 *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + towire_u32(pptr, arr[i]); +} + +void towire_u64_array(u8 **pptr, const u64 *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + towire_u64(pptr, arr[i]); +} + +void towire_bool_array(u8 **pptr, const bool *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + towire_bool(pptr, arr[i]); +} + void towire_pad(u8 **pptr, size_t num) { /* Simply insert zeros. */ @@ -104,3 +139,12 @@ void towire_secp256k1_ecdsa_signature_array(u8 **pptr, for (i = 0; i < num; i++) towire_secp256k1_ecdsa_signature(pptr, arr+i); } + +void towire_sha256_double_array(u8 **pptr, + const struct sha256_double *arr, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + towire_sha256_double(pptr, arr+i); +} diff --git a/wire/wire.h b/wire/wire.h index a85c1ac0c..023d46db4 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -1,14 +1,14 @@ #ifndef LIGHTNING_WIRE_WIRE_H #define LIGHTNING_WIRE_WIRE_H #include "config.h" +#include #include +#include #include #include #include #include -struct pubkey; -struct sha256; struct channel_id { u32 blocknum; u32 txnum : 24; @@ -23,10 +23,12 @@ int fromwire_peektype(const u8 *cursor); void towire(u8 **pptr, const void *data, size_t len); void towire_pubkey(u8 **pptr, const struct pubkey *pubkey); +void towire_privkey(u8 **pptr, const struct privkey *privkey); void towire_secp256k1_ecdsa_signature(u8 **pptr, const secp256k1_ecdsa_signature *signature); void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); void towire_sha256(u8 **pptr, const struct sha256 *sha256); +void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d); void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6); void towire_u8(u8 **pptr, u8 v); void towire_u16(u8 **pptr, u16 v); @@ -36,8 +38,13 @@ void towire_pad(u8 **pptr, size_t num); void towire_bool(u8 **pptr, bool v); void towire_u8_array(u8 **pptr, const u8 *arr, size_t num); +void towire_u32_array(u8 **pptr, const u32 *arr, size_t num); +void towire_u64_array(u8 **pptr, const u64 *arr, size_t num); +void towire_bool_array(u8 **pptr, const bool *arr, size_t num); void towire_secp256k1_ecdsa_signature_array(u8 **pptr, const secp256k1_ecdsa_signature *arr, size_t num); +void towire_sha256_double_array(u8 **pptr, + const struct sha256_double *arr, size_t num); const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n); @@ -46,18 +53,25 @@ u16 fromwire_u16(const u8 **cursor, size_t *max); u32 fromwire_u32(const u8 **cursor, size_t *max); u64 fromwire_u64(const u8 **cursor, size_t *max); bool fromwire_bool(const u8 **cursor, size_t *max); +void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey); void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey); void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, secp256k1_ecdsa_signature *signature); void fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id); 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_ipv6(const u8 **cursor, size_t *max, struct ipv6 *ipv6); void fromwire_pad(const u8 **cursor, size_t *max, size_t num); -void fromwire_u8_array(const u8 **cursor, size_t *max, - u8 *arr, size_t num); +void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num); +void fromwire_u32_array(const u8 **cursor, size_t *max, u32 *arr, size_t num); +void fromwire_u64_array(const u8 **cursor, size_t *max, u64 *arr, size_t num); +void fromwire_bool_array(const u8 **cursor, size_t *max, bool *arr, size_t num); + void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max, secp256k1_ecdsa_signature *arr, size_t num); - +void fromwire_sha256_double_array(const u8 **cursor, size_t *max, + struct sha256_double *arr, size_t num); #endif /* LIGHTNING_WIRE_WIRE_H */