Skip to content

Commit 29b1710

Browse files
committed
Make the custom message traits cloneable as they're deep in nested structs
1 parent bc9d0e0 commit 29b1710

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

lightning/src/ln/wire.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<T> TestEq for T {}
4545
/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
4646
/// variant contains a message from [`msgs`] or otherwise the message type if unknown.
4747
#[allow(missing_docs)]
48-
#[derive(Debug)]
48+
#[derive(Clone, Debug)]
4949
#[cfg_attr(test, derive(PartialEq))]
50-
pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
50+
pub(crate) enum Message<T> where T: Clone + core::fmt::Debug + Type + TestEq {
5151
Init(msgs::Init),
5252
Error(msgs::ErrorMessage),
5353
Warning(msgs::WarningMessage),
@@ -383,13 +383,13 @@ pub(crate) use self::encode::Encode;
383383
/// Defines a type identifier for sending messages over the wire.
384384
///
385385
/// Messages implementing this trait specify a type and must be [`Writeable`].
386-
pub trait Type: core::fmt::Debug + Writeable {
386+
pub trait Type: core::fmt::Debug + Writeable + Clone {
387387
/// Returns the type identifying the message payload.
388388
fn type_id(&self) -> u16;
389389
}
390390

391391
#[cfg(test)]
392-
pub trait Type: core::fmt::Debug + Writeable + PartialEq {
392+
pub trait Type: core::fmt::Debug + Writeable + Clone + PartialEq {
393393
fn type_id(&self) -> u16;
394394
}
395395

@@ -399,12 +399,12 @@ impl Type for () {
399399
}
400400

401401
#[cfg(test)]
402-
impl<T: core::fmt::Debug + Writeable + PartialEq> Type for T where T: Encode {
402+
impl<T: core::fmt::Debug + Writeable + Clone + PartialEq> Type for T where T: Encode {
403403
fn type_id(&self) -> u16 { T::TYPE }
404404
}
405405

406406
#[cfg(not(test))]
407-
impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
407+
impl<T: core::fmt::Debug + Writeable + Clone> Type for T where T: Encode {
408408
fn type_id(&self) -> u16 { T::TYPE }
409409
}
410410

@@ -734,7 +734,7 @@ mod tests {
734734
}
735735
}
736736

737-
#[derive(Eq, PartialEq, Debug)]
737+
#[derive(Clone, Eq, PartialEq, Debug)]
738738
struct TestCustomMessage {}
739739

740740
const CUSTOM_MESSAGE_TYPE : u16 = 9000;

lightning/src/onion_message/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ fn reply_path() {
373373
fn invalid_custom_message_type() {
374374
let nodes = create_nodes(2);
375375

376+
#[derive(Clone)]
376377
struct InvalidCustomMessage{}
377378
impl CustomOnionMessageContents for InvalidCustomMessage {
378379
fn tlv_type(&self) -> u64 {

lightning/src/onion_message/messenger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use crate::prelude::*;
8383
/// &custom_message_handler
8484
/// );
8585
///
86+
/// # #[derive(Clone)]
8687
/// # struct YourCustomMessage {}
8788
/// impl Writeable for YourCustomMessage {
8889
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {

lightning/src/onion_message/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub(super) enum Payload<T: CustomOnionMessageContents> {
114114
}
115115
}
116116

117-
#[derive(Debug)]
117+
#[derive(Clone, Debug)]
118118
/// The contents of an onion message. In the context of offers, this would be the invoice, invoice
119119
/// request, or invoice error.
120120
pub enum OnionMessageContents<T: CustomOnionMessageContents> {
@@ -147,7 +147,7 @@ impl<T: CustomOnionMessageContents> Writeable for OnionMessageContents<T> {
147147
}
148148

149149
/// The contents of a custom onion message.
150-
pub trait CustomOnionMessageContents: Writeable {
150+
pub trait CustomOnionMessageContents: Writeable + Clone {
151151
/// Returns the TLV type identifying the message contents. MUST be >= 64.
152152
fn tlv_type(&self) -> u64;
153153
}

0 commit comments

Comments
 (0)