Add message structs required for dual-funded channels
[rust-lightning] / lightning / src / ln / wire.rs
index cbf5c77d60095d73abe235c7652eeccb8380cf04..32447e8979e4a1e41fdcae7bb8e373c6bf17e3a4 100644 (file)
@@ -9,12 +9,12 @@
 
 //! Wire encoding/decoding for Lightning messages according to [BOLT #1], and for
 //! custom message through the [`CustomMessageReader`] trait.
-//! 
+//!
 //! [BOLT #1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
 
-use io;
-use ln::msgs;
-use util::ser::{Readable, Writeable, Writer};
+use crate::io;
+use crate::ln::msgs;
+use crate::util::ser::{Readable, Writeable, Writer};
 
 /// Trait to be implemented by custom message (unrelated to the channel/gossip LN layers)
 /// decoders.
@@ -42,7 +42,7 @@ pub(crate) trait TestEq {}
 impl<T> TestEq for T {}
 
 
-/// A Lightning message returned by [`read()`] when decoding bytes received over the wire. Each
+/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
 /// variant contains a message from [`msgs`] or otherwise the message type if unknown.
 #[allow(missing_docs)]
 #[derive(Debug)]
@@ -60,6 +60,7 @@ pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
        ChannelReady(msgs::ChannelReady),
        Shutdown(msgs::Shutdown),
        ClosingSigned(msgs::ClosingSigned),
+       OnionMessage(msgs::OnionMessage),
        UpdateAddHTLC(msgs::UpdateAddHTLC),
        UpdateFulfillHTLC(msgs::UpdateFulfillHTLC),
        UpdateFailHTLC(msgs::UpdateFailHTLC),
@@ -80,7 +81,7 @@ pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
        /// A message that could not be decoded because its type is unknown.
        Unknown(u16),
        /// A message that was produced by a [`CustomMessageReader`] and is to be handled by a
-       /// [`::ln::peer_handler::CustomMessageHandler`].
+       /// [`crate::ln::peer_handler::CustomMessageHandler`].
        Custom(T),
 }
 
@@ -100,6 +101,7 @@ impl<T> Message<T> where T: core::fmt::Debug + Type + TestEq {
                        &Message::ChannelReady(ref msg) => msg.type_id(),
                        &Message::Shutdown(ref msg) => msg.type_id(),
                        &Message::ClosingSigned(ref msg) => msg.type_id(),
+                       &Message::OnionMessage(ref msg) => msg.type_id(),
                        &Message::UpdateAddHTLC(ref msg) => msg.type_id(),
                        &Message::UpdateFulfillHTLC(ref msg) => msg.type_id(),
                        &Message::UpdateFailHTLC(ref msg) => msg.type_id(),
@@ -185,6 +187,9 @@ fn do_read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, message_type: u1
                msgs::ClosingSigned::TYPE => {
                        Ok(Message::ClosingSigned(Readable::read(buffer)?))
                },
+               msgs::OnionMessage::TYPE => {
+                       Ok(Message::OnionMessage(Readable::read(buffer)?))
+               },
                msgs::UpdateAddHTLC::TYPE => {
                        Ok(Message::UpdateAddHTLC(Readable::read(buffer)?))
                },
@@ -344,6 +349,54 @@ impl Encode for msgs::ClosingSigned {
        const TYPE: u16 = 39;
 }
 
+impl Encode for msgs::OpenChannelV2 {
+       const TYPE: u16 = 64;
+}
+
+impl Encode for msgs::AcceptChannelV2 {
+       const TYPE: u16 = 65;
+}
+
+impl Encode for msgs::TxAddInput {
+       const TYPE: u16 = 66;
+}
+
+impl Encode for msgs::TxAddOutput {
+       const TYPE: u16 = 67;
+}
+
+impl Encode for msgs::TxRemoveInput {
+       const TYPE: u16 = 68;
+}
+
+impl Encode for msgs::TxRemoveOutput {
+       const TYPE: u16 = 69;
+}
+
+impl Encode for msgs::TxComplete {
+       const TYPE: u16 = 70;
+}
+
+impl Encode for msgs::TxSignatures {
+       const TYPE: u16 = 71;
+}
+
+impl Encode for msgs::TxInitRbf {
+       const TYPE: u16 = 72;
+}
+
+impl Encode for msgs::TxAckRbf {
+       const TYPE: u16 = 73;
+}
+
+impl Encode for msgs::TxAbort {
+       const TYPE: u16 = 74;
+}
+
+impl Encode for msgs::OnionMessage {
+       const TYPE: u16 = 513;
+}
+
 impl Encode for msgs::UpdateAddHTLC {
        const TYPE: u16 = 128;
 }
@@ -415,9 +468,9 @@ impl Encode for msgs::GossipTimestampFilter {
 #[cfg(test)]
 mod tests {
        use super::*;
-       use prelude::*;
+       use crate::prelude::*;
        use core::convert::TryInto;
-       use ::ln::peer_handler::IgnoringMessageHandler;
+       use crate::ln::peer_handler::IgnoringMessageHandler;
 
        // Big-endian wire encoding of Pong message (type = 19, byteslen = 2).
        const ENCODED_PONG: [u8; 6] = [0u8, 19u8, 0u8, 2u8, 0u8, 0u8];