Merge rust-bitcoin/rust-bitcoin#1757: Add implementation of PartialEq trait for Address with NetworkUnchecked

046bda321b comparing NetworkUncheck addresses (Harshil Jani)

Pull request description:

  Closes #1754

  This PR adds an implementation of the PartialEq trait for the `Address` struct with NetworkUnchecked. The newly implemented function checks if two addresses are equal based on their network and payload. This implementation is useful when comparing an Address with NetworkUnchecked to another Address with NetworkUnchecked

ACKs for top commit:
  Kixunil:
    ACK 046bda321b
  apoelstra:
    ACK 046bda321b

Tree-SHA512: 9db28bd9fe6721c754515812bf8b7ca6a2a1285501e3e998298bb430cc129971dc03b9b9ed4a764aa1ebd9d3cb0b06cc5e7fdb9196682410e795c57211672b87
This commit is contained in:
Andrew Poelstra 2023-03-29 13:47:16 +00:00
commit 5984818f87
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 11 additions and 0 deletions

View File

@ -1057,6 +1057,17 @@ impl Address<NetworkUnchecked> {
pub fn assume_checked(self) -> Address { Address::new(self.network, self.payload) }
}
// For NetworkUnchecked , it compare Addresses and if network and payload matches then return true.
impl PartialEq<Address<NetworkUnchecked>> for Address {
fn eq(&self, other: &Address<NetworkUnchecked>) -> bool {
self.network == other.network && self.payload == other.payload
}
}
impl PartialEq<Address> for Address<NetworkUnchecked> {
fn eq(&self, other: &Address) -> bool { other == self }
}
impl From<Address> for script::ScriptBuf {
fn from(a: Address) -> Self { a.script_pubkey() }
}