Skip to content

Commit 1be1630

Browse files
committed
Implement Eq and Hash for Bolt12Invoice
Bolt12Invoice will be added to a new Event::InvoiceGenerated variant. These traits along with PartialEq are required to be implemented for any type used in an Event.
1 parent eec6822 commit 1be1630

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lightning/src/offers/invoice.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@
104104
105105
use bitcoin::blockdata::constants::ChainHash;
106106
use bitcoin::hash_types::{WPubkeyHash, WScriptHash};
107-
use bitcoin::hashes::Hash;
108107
use bitcoin::network::constants::Network;
109108
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self};
110109
use bitcoin::secp256k1::schnorr::Signature;
111110
use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion};
112111
use bitcoin::key::TweakedPublicKey;
113112
use core::convert::{AsRef, TryFrom};
114113
use core::time::Duration;
114+
use core::hash::{Hash, Hasher};
115115
use crate::io;
116116
use crate::blinded_path::BlindedPath;
117117
use crate::ln::PaymentHash;
@@ -390,6 +390,7 @@ macro_rules! invoice_builder_methods { (
390390
/// Successive calls to this method will add another address. Caller is responsible for not
391391
/// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
392392
pub fn fallback_v0_p2wsh($($self_mut)* $self: $self_type, script_hash: &WScriptHash) -> $return_type {
393+
use bitcoin::hashes::Hash;
393394
let address = FallbackAddress {
394395
version: WitnessVersion::V0.to_num(),
395396
program: Vec::from(script_hash.to_byte_array()),
@@ -403,6 +404,7 @@ macro_rules! invoice_builder_methods { (
403404
/// Successive calls to this method will add another address. Caller is responsible for not
404405
/// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
405406
pub fn fallback_v0_p2wpkh($($self_mut)* $self: $self_type, pubkey_hash: &WPubkeyHash) -> $return_type {
407+
use bitcoin::hashes::Hash;
406408
let address = FallbackAddress {
407409
version: WitnessVersion::V0.to_num(),
408410
program: Vec::from(pubkey_hash.to_byte_array()),
@@ -614,7 +616,6 @@ impl AsRef<TaggedHash> for UnsignedBolt12Invoice {
614616
/// [`Refund`]: crate::offers::refund::Refund
615617
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
616618
#[derive(Clone, Debug)]
617-
#[cfg_attr(test, derive(PartialEq))]
618619
pub struct Bolt12Invoice {
619620
bytes: Vec<u8>,
620621
contents: InvoiceContents,
@@ -886,6 +887,20 @@ impl Bolt12Invoice {
886887
}
887888
}
888889

890+
impl PartialEq for Bolt12Invoice {
891+
fn eq(&self, other: &Self) -> bool {
892+
self.bytes.eq(&other.bytes)
893+
}
894+
}
895+
896+
impl Eq for Bolt12Invoice {}
897+
898+
impl Hash for Bolt12Invoice {
899+
fn hash<H: Hasher>(&self, state: &mut H) {
900+
self.bytes.hash(state);
901+
}
902+
}
903+
889904
impl InvoiceContents {
890905
/// Whether the original offer or refund has expired.
891906
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)