Skip to content

Commit 3eeb8b8

Browse files
committed
Impl PartialEq/Eq for Offer/Refund
We add custom implementations based on comparing the `bytes` for `Offer`/`Refund` themselves as this is sufficient and should be faster than comapring all fields in the worst case.
1 parent aa3dbe8 commit 3eeb8b8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lightning/src/offers/offer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
363363
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
364364
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
365365
#[derive(Clone, Debug)]
366-
#[cfg_attr(test, derive(PartialEq))]
367366
pub struct Offer {
368367
// The serialized offer. Needed when creating an `InvoiceRequest` if the offer contains unknown
369368
// fields.
@@ -584,6 +583,14 @@ impl AsRef<[u8]> for Offer {
584583
}
585584
}
586585

586+
impl PartialEq for Offer {
587+
fn eq(&self, other: &Self) -> bool {
588+
self.bytes.eq(&other.bytes)
589+
}
590+
}
591+
592+
impl Eq for Offer {}
593+
587594
impl OfferContents {
588595
pub fn chains(&self) -> Vec<ChainHash> {
589596
self.chains.as_ref().cloned().unwrap_or_else(|| vec![self.implied_chain()])

lightning/src/offers/refund.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
317317
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
318318
/// [`Offer`]: crate::offers::offer::Offer
319319
#[derive(Clone, Debug)]
320-
#[cfg_attr(test, derive(PartialEq))]
321320
pub struct Refund {
322321
pub(super) bytes: Vec<u8>,
323322
pub(super) contents: RefundContents,
@@ -539,6 +538,14 @@ impl AsRef<[u8]> for Refund {
539538
}
540539
}
541540

541+
impl PartialEq for Refund {
542+
fn eq(&self, other: &Self) -> bool {
543+
self.bytes.eq(&other.bytes)
544+
}
545+
}
546+
547+
impl Eq for Refund {}
548+
542549
impl RefundContents {
543550
pub fn description(&self) -> PrintableString {
544551
PrintableString(&self.description)

0 commit comments

Comments
 (0)