Skip to content

Commit 07059ec

Browse files
authored
Merge pull request #2926 from tnull/2024-03-derive-eq-for-offer-refund
Impl `PartialEq`/`Eq` for `Offer`/`Refund`
2 parents aa3dbe8 + 47954e9 commit 07059ec

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Diff for: lightning/src/offers/offer.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ use bitcoin::blockdata::constants::ChainHash;
8080
use bitcoin::network::constants::Network;
8181
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self};
8282
use core::convert::TryFrom;
83+
use core::hash::{Hash, Hasher};
8384
use core::num::NonZeroU64;
8485
use core::ops::Deref;
8586
use core::str::FromStr;
@@ -363,7 +364,6 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
363364
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
364365
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
365366
#[derive(Clone, Debug)]
366-
#[cfg_attr(test, derive(PartialEq))]
367367
pub struct Offer {
368368
// The serialized offer. Needed when creating an `InvoiceRequest` if the offer contains unknown
369369
// fields.
@@ -584,6 +584,20 @@ impl AsRef<[u8]> for Offer {
584584
}
585585
}
586586

587+
impl PartialEq for Offer {
588+
fn eq(&self, other: &Self) -> bool {
589+
self.bytes.eq(&other.bytes)
590+
}
591+
}
592+
593+
impl Eq for Offer {}
594+
595+
impl Hash for Offer {
596+
fn hash<H: Hasher>(&self, state: &mut H) {
597+
self.bytes.hash(state);
598+
}
599+
}
600+
587601
impl OfferContents {
588602
pub fn chains(&self) -> Vec<ChainHash> {
589603
self.chains.as_ref().cloned().unwrap_or_else(|| vec![self.implied_chain()])

Diff for: lightning/src/offers/refund.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ use bitcoin::blockdata::constants::ChainHash;
8585
use bitcoin::network::constants::Network;
8686
use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
8787
use core::convert::TryFrom;
88+
use core::hash::{Hash, Hasher};
8889
use core::ops::Deref;
8990
use core::str::FromStr;
9091
use core::time::Duration;
@@ -317,7 +318,6 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
317318
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
318319
/// [`Offer`]: crate::offers::offer::Offer
319320
#[derive(Clone, Debug)]
320-
#[cfg_attr(test, derive(PartialEq))]
321321
pub struct Refund {
322322
pub(super) bytes: Vec<u8>,
323323
pub(super) contents: RefundContents,
@@ -539,6 +539,20 @@ impl AsRef<[u8]> for Refund {
539539
}
540540
}
541541

542+
impl PartialEq for Refund {
543+
fn eq(&self, other: &Self) -> bool {
544+
self.bytes.eq(&other.bytes)
545+
}
546+
}
547+
548+
impl Eq for Refund {}
549+
550+
impl Hash for Refund {
551+
fn hash<H: Hasher>(&self, state: &mut H) {
552+
self.bytes.hash(state);
553+
}
554+
}
555+
542556
impl RefundContents {
543557
pub fn description(&self) -> PrintableString {
544558
PrintableString(&self.description)

0 commit comments

Comments
 (0)