Make the custom message traits cloneable as they're deep in nested structs 2022-10-112-java-bindings
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:44:32 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Oct 2022 17:18:00 +0000 (17:18 +0000)
lightning/src/ln/wire.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/onion_message/messenger.rs
lightning/src/onion_message/packet.rs

index deec15a51369e8c31907af564bb0b67453470b8f..1ceb38c7499642128480c1a8d0f4b03912842711 100644 (file)
@@ -276,13 +276,13 @@ pub(crate) use self::encode::Encode;
 /// Defines a type identifier for sending messages over the wire.
 ///
 /// Messages implementing this trait specify a type and must be [`Writeable`].
-pub trait Type: core::fmt::Debug + Writeable {
+pub trait Type: core::fmt::Debug + Writeable + Clone {
        /// Returns the type identifying the message payload.
        fn type_id(&self) -> u16;
 }
 
 #[cfg(test)]
-pub trait Type: core::fmt::Debug + Writeable + PartialEq {
+pub trait Type: core::fmt::Debug + Writeable + Clone + PartialEq {
        fn type_id(&self) -> u16;
 }
 
@@ -292,12 +292,12 @@ impl Type for () {
 }
 
 #[cfg(test)]
-impl<T: core::fmt::Debug + Writeable + PartialEq> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable + Clone + PartialEq> Type for T where T: Encode {
        fn type_id(&self) -> u16 { T::TYPE }
 }
 
 #[cfg(not(test))]
-impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable + Clone> Type for T where T: Encode {
        fn type_id(&self) -> u16 { T::TYPE }
 }
 
@@ -583,7 +583,7 @@ mod tests {
                }
        }
 
-       #[derive(Eq, PartialEq, Debug)]
+       #[derive(Clone, Eq, PartialEq, Debug)]
        struct TestCustomMessage {}
 
        const CUSTOM_MESSAGE_TYPE : u16 = 9000;
index efa6507bd325245185d67e891f0db61a133d3faf..c4faffabdb8129966a75229e7941cd94fdd0a563 100644 (file)
@@ -220,6 +220,7 @@ fn reply_path() {
 fn invalid_custom_message_type() {
        let nodes = create_nodes(2);
 
+       #[derive(Clone)]
        struct InvalidCustomMessage{}
        impl CustomOnionMessageContents for InvalidCustomMessage {
                fn tlv_type(&self) -> u64 {
index 6284c47c8e8f8384fe1b81305e3eedc1cfae6160..78e8ccd1f154387c2a1be272791e13fb171b888f 100644 (file)
@@ -71,6 +71,7 @@ use crate::prelude::*;
 /// // ChannelManager.
 /// let onion_messenger = OnionMessenger::new(&keys_manager, logger, your_custom_message_handler);
 ///
+/// # #[derive(Clone)]
 /// # struct YourCustomMessage {}
 /// impl Writeable for YourCustomMessage {
 ///    fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
index 3bc42f504229e392064c58f38ee13efe3e18bb0f..440d50069f9bcd68eff358500df67678c4e3b7f9 100644 (file)
@@ -134,7 +134,7 @@ impl<T: CustomOnionMessageContents> Writeable for OnionMessageContents<T> {
 }
 
 /// The contents of a custom onion message.
-pub trait CustomOnionMessageContents: Writeable {
+pub trait CustomOnionMessageContents: Writeable + Clone {
        /// Returns the TLV type identifying the message contents. MUST be >= 64.
        fn tlv_type(&self) -> u64;
 }