From: Elias Rohrer Date: Fri, 8 Mar 2024 09:24:50 +0000 (+0100) Subject: Impl `PartialEq`/`Eq` for `Offer`/`Refund` X-Git-Tag: v0.0.123-beta~47^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=3eeb8b82a52957ec3849255c11d8b675996b39fd;p=rust-lightning 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. --- diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 802813fd1..d2be5b056 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -363,7 +363,6 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> { /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice #[derive(Clone, Debug)] -#[cfg_attr(test, derive(PartialEq))] pub struct Offer { // The serialized offer. Needed when creating an `InvoiceRequest` if the offer contains unknown // fields. @@ -584,6 +583,14 @@ impl AsRef<[u8]> for Offer { } } +impl PartialEq for Offer { + fn eq(&self, other: &Self) -> bool { + self.bytes.eq(&other.bytes) + } +} + +impl Eq for Offer {} + impl OfferContents { pub fn chains(&self) -> Vec { self.chains.as_ref().cloned().unwrap_or_else(|| vec![self.implied_chain()]) diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index ba3ab1d1e..db42c7457 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -317,7 +317,6 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> { /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice /// [`Offer`]: crate::offers::offer::Offer #[derive(Clone, Debug)] -#[cfg_attr(test, derive(PartialEq))] pub struct Refund { pub(super) bytes: Vec, pub(super) contents: RefundContents, @@ -539,6 +538,14 @@ impl AsRef<[u8]> for Refund { } } +impl PartialEq for Refund { + fn eq(&self, other: &Self) -> bool { + self.bytes.eq(&other.bytes) + } +} + +impl Eq for Refund {} + impl RefundContents { pub fn description(&self) -> PrintableString { PrintableString(&self.description)