Implement `Hash` for `Offer` and `Refund`
[rust-lightning] / lightning / src / offers / refund.rs
index ce39841df8c9750d9f4e7b717d1e3fb50e967d1a..5107e31d8d0a07e6527d7838d7a19439c86e54c1 100644 (file)
@@ -85,6 +85,7 @@ use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
 use core::convert::TryFrom;
+use core::hash::{Hash, Hasher};
 use core::ops::Deref;
 use core::str::FromStr;
 use core::time::Duration;
@@ -297,6 +298,11 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
 
 #[cfg(test)]
 impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
+       pub(crate) fn clear_paths(mut self) -> Self {
+               self.refund.paths = None;
+               self
+       }
+
        fn features_unchecked(mut self, features: InvoiceRequestFeatures) -> Self {
                self.refund.features = features;
                self
@@ -312,7 +318,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<u8>,
        pub(super) contents: RefundContents,
@@ -534,6 +539,20 @@ 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 Hash for Refund {
+       fn hash<H: Hasher>(&self, state: &mut H) {
+               self.bytes.hash(state);
+       }
+}
+
 impl RefundContents {
        pub fn description(&self) -> PrintableString {
                PrintableString(&self.description)