X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fwire.rs;h=d113acbfc7d4d5e50a17d2bea7012f67fa845285;hb=3baaebe7ddb2879a00b239d64dd2b138656e5c67;hp=2c77fd46b8d92f8730e19d65448665f2fd86c710;hpb=1b3249a1929929170bba9d2553d7a9c8670193e5;p=rust-lightning diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index 2c77fd46..d113acbf 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -119,15 +119,20 @@ impl Message where T: core::fmt::Debug + Type { /// # Errors /// /// Returns an error if the message payload code not be decoded as the specified type. -pub(crate) fn read( - buffer: &mut R, - custom_reader: H, -) -> Result, msgs::DecodeError> -where +pub(crate) fn read(buffer: &mut R, custom_reader: H) +-> Result, (msgs::DecodeError, Option)> where + T: core::fmt::Debug + Type + Writeable, + H::Target: CustomMessageReader, +{ + let message_type = ::read(buffer).map_err(|e| (e, None))?; + do_read(buffer, message_type, custom_reader).map_err(|e| (e, Some(message_type))) +} + +fn do_read(buffer: &mut R, message_type: u16, custom_reader: H) +-> Result, msgs::DecodeError> where T: core::fmt::Debug + Type + Writeable, H::Target: CustomMessageReader, { - let message_type = ::read(buffer)?; match message_type { msgs::Init::TYPE => { Ok(Message::Init(Readable::read(buffer)?))