Make the custom message traits cloneable as they're deep in nested structs 2023-04-0.0.115-java-bindings
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:44:32 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Apr 2023 17:51:18 +0000 (17:51 +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 532eb00b871034ebbc4913b7f0b3ffc75035f145..04437ac4a11ee90a7c0f4f122646ef4cba0949f2 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 991b4e9e7df7666eabca6273926702ea435d2a9b..286a5beeb49885c74c589e4703b23d7509e6c21c 100644 (file)
@@ -237,6 +237,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 4cd167ecf3dd5cc39e8dd8d16e49956fea1a0e3e..fecb2980bbb018811a3c1441f63142990e41aeae 100644 (file)
@@ -69,6 +69,7 @@ use crate::prelude::*;
 /// // ChannelManager.
 /// let onion_messenger = OnionMessenger::new(&keys_manager, &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 2fb2407dbdd093bdbe4ae260e31f12fbe4722d8a..4cbb30c0cde5cfa9147736eb685c86e49ffd3539 100644 (file)
@@ -104,7 +104,7 @@ pub(super) enum Payload<T: CustomOnionMessageContents> {
        }
 }
 
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 /// The contents of an onion message. In the context of offers, this would be the invoice, invoice
 /// request, or invoice error.
 pub enum OnionMessageContents<T: CustomOnionMessageContents> {
@@ -137,7 +137,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;
 }