Make the custom message traits cloneable as they're deep in nested structs 2023-09-0.0.117-java-bindings
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:44:32 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 3 Oct 2023 23:37:41 +0000 (23:37 +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 88e2ad7c1daee03ef245c795f0119eb229a10520..e982a2aec0da3b504a32dbc10b9b5f9662cfb229 100644 (file)
@@ -45,9 +45,9 @@ impl<T> TestEq for T {}
 /// 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)]
+#[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
-pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
+pub(crate) enum Message<T> where T: Clone + core::fmt::Debug + Type + TestEq {
        Init(msgs::Init),
        Error(msgs::ErrorMessage),
        Warning(msgs::WarningMessage),
@@ -383,13 +383,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;
 }
 
@@ -399,12 +399,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 }
 }
 
@@ -734,7 +734,7 @@ mod tests {
                }
        }
 
-       #[derive(Eq, PartialEq, Debug)]
+       #[derive(Clone, Eq, PartialEq, Debug)]
        struct TestCustomMessage {}
 
        const CUSTOM_MESSAGE_TYPE : u16 = 9000;
index c2d90ad60f91e250790e040020209e6682c0d231..1fc96d05185d90170552c713edc8b09f7f8f012d 100644 (file)
@@ -373,6 +373,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 0fe4120d96f59c11ec1ea86f2cdc3603ea225cad..283355ae79eef2bd9d890c2c5944758de0e18ff2 100644 (file)
@@ -83,6 +83,7 @@ use crate::prelude::*;
 ///     &custom_message_handler
 /// );
 ///
+/// # #[derive(Clone)]
 /// # struct YourCustomMessage {}
 /// impl Writeable for YourCustomMessage {
 ///    fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
index d19bd30edd212be4b19286d5ef5f0bf0f1870a8f..99d5bc04a9cb409c87149d9351063cf1d3d22018 100644 (file)
@@ -114,7 +114,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> {
@@ -147,7 +147,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;
 }