Merge rust-bitcoin/rust-bitcoin#3221: feat(bip158): compute canonical filter hash

96e0e720fd feat(bip158): compute canonical filter hash (Rob N)

Pull request description:

  From [BIP-157](https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#filter-headers)

  > The canonical hash of a block filter is the double-SHA256 of the serialized filter.

  If a user forgets the "double" in double-SHA256 they will be computing a nonsensical filter hash when this is easily handled by the API.

ACKs for top commit:
  Kixunil:
    ACK 96e0e720fd
  tcharding:
    ACK 96e0e720fd

Tree-SHA512: 5fc0b1632e2327adacbd0ab56b4cd7edce0774f8be2f819782519c51b9691a748f4b3c01887f3bf1146dee49a35f9dfac833f53ae69ee7a53858bd2cedcec01a
This commit is contained in:
merge-script 2024-08-23 13:57:22 +00:00
commit b4bda00141
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 6 additions and 0 deletions

View File

@ -149,6 +149,12 @@ impl BlockFilter {
FilterHash(sha256d::Hash::hash(&self.content)).filter_header(previous_filter_header) FilterHash(sha256d::Hash::hash(&self.content)).filter_header(previous_filter_header)
} }
/// Computes the canonical hash for the given filter.
pub fn filter_hash(&self) -> FilterHash {
let hash = sha256d::Hash::hash(&self.content);
FilterHash(hash)
}
/// Returns true if any query matches against this [`BlockFilter`]. /// Returns true if any query matches against this [`BlockFilter`].
pub fn match_any<I>(&self, block_hash: BlockHash, query: I) -> Result<bool, Error> pub fn match_any<I>(&self, block_hash: BlockHash, query: I) -> Result<bool, Error>
where where