From 9d04227a66469a6e9569b9bff82d89f42121b0bd Mon Sep 17 00:00:00 2001 From: Tibo-lg Date: Fri, 9 Jul 2021 20:40:43 +0900 Subject: [PATCH] Make ser macro public --- lightning/src/ln/mod.rs | 2 +- lightning/src/util/mod.rs | 2 +- lightning/src/util/ser.rs | 3 ++- lightning/src/util/ser_macros.rs | 14 +++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index 7500b93c0..66c63f04d 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -35,7 +35,7 @@ pub(crate) mod peer_channel_encryptor; mod channel; mod onion_utils; -mod wire; +pub mod wire; // Older rustc (which we support) refuses to let us call the get_payment_preimage_hash!() macro // without the node parameter being mut. This is incorrect, and thus newer rustcs will complain diff --git a/lightning/src/util/mod.rs b/lightning/src/util/mod.rs index cc0c3192a..5123f9db0 100644 --- a/lightning/src/util/mod.rs +++ b/lightning/src/util/mod.rs @@ -13,7 +13,7 @@ pub(crate) mod fuzz_wrappers; #[macro_use] -pub(crate) mod ser_macros; +pub mod ser_macros; pub mod events; pub mod errors; diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index b02fef275..346aa7647 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -303,7 +303,7 @@ impl Readable for U48 { /// encoded in several different ways, which we must check for at deserialization-time. Thus, if /// you're looking for an example of a variable-length integer to use for your own project, move /// along, this is a rather poor design. -pub(crate) struct BigSize(pub u64); +pub struct BigSize(pub u64); impl Writeable for BigSize { #[inline] fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { @@ -486,6 +486,7 @@ impl_array!(16); // for IPv6 impl_array!(32); // for channel id & hmac impl_array!(PUBLIC_KEY_SIZE); // for PublicKey impl_array!(COMPACT_SIGNATURE_SIZE); // for Signature +impl_array!(162); // for ECDSA adaptor signatures impl_array!(1300); // for OnionPacket.hop_data // HashMap diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index b93115dcc..93387609a 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -7,6 +7,10 @@ // You may not use this file except in accordance with one or both of these // licenses. +//! Useful macros for generating serialization related code. + +/// Encode a TLV +#[macro_export] macro_rules! encode_tlv { ($stream: expr, $type: expr, $field: expr, required) => { BigSize($type).write($stream)?; @@ -72,6 +76,8 @@ macro_rules! get_varint_length_prefixed_tlv_length { }; } +/// Encode a varint length prefixed TLV +#[macro_export] macro_rules! encode_varint_length_prefixed_tlv { ($stream: expr, {$(($type: expr, $field: expr, $fieldty: ident)),*}) => { { use util::ser::BigSize; @@ -120,15 +126,17 @@ macro_rules! check_missing_tlv { }}; } +/// Decode a TLV. +#[macro_export] macro_rules! decode_tlv { ($reader: expr, $field: ident, required) => {{ - $field = ser::Readable::read(&mut $reader)?; + $field = $crate::util::ser::Readable::read(&mut $reader)?; }}; ($reader: expr, $field: ident, vec_type) => {{ - $field = Some(ser::Readable::read(&mut $reader)?); + $field = Some($crate::util::ser::Readable::read(&mut $reader)?); }}; ($reader: expr, $field: ident, option) => {{ - $field = Some(ser::Readable::read(&mut $reader)?); + $field = Some($crate::util::ser::Readable::read(&mut $reader)?); }}; } -- 2.39.5