Skip to content

Commit

Permalink
Make the custom message traits cloneable as they're deep in nested st…
Browse files Browse the repository at this point in the history
…ructs
  • Loading branch information
TheBlueMatt committed Jul 25, 2023
1 parent 03d8939 commit e794e9e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lightning/src/ln/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 }
}

Expand Down Expand Up @@ -734,7 +734,7 @@ mod tests {
}
}

#[derive(Eq, PartialEq, Debug)]
#[derive(Clone, Eq, PartialEq, Debug)]
struct TestCustomMessage {}

const CUSTOM_MESSAGE_TYPE : u16 = 9000;
Expand Down
1 change: 1 addition & 0 deletions lightning/src/onion_message/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,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 {
Expand Down
1 change: 1 addition & 0 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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> {
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/onion_message/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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> {
Expand Down Expand Up @@ -139,7 +139,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;
}
Expand Down

0 comments on commit e794e9e

Please sign in to comment.