Move the bip158 filter hash types

We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move the BIP-158 filter hash types to the `bip158` module.
This commit is contained in:
Tobin C. Harding 2023-11-07 14:01:14 +11:00
parent 3107f80aac
commit 2a0ac1258a
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
5 changed files with 19 additions and 26 deletions

View File

@ -41,7 +41,7 @@
use core::cmp::{self, Ordering}; use core::cmp::{self, Ordering};
use core::fmt::{self, Display, Formatter}; use core::fmt::{self, Display, Formatter};
use hashes::{siphash24, Hash}; use hashes::{sha256d, siphash24, Hash};
use internals::write_err; use internals::write_err;
use crate::blockdata::block::{Block, BlockHash}; use crate::blockdata::block::{Block, BlockHash};
@ -49,13 +49,23 @@ use crate::blockdata::script::Script;
use crate::blockdata::transaction::OutPoint; use crate::blockdata::transaction::OutPoint;
use crate::consensus::encode::VarInt; use crate::consensus::encode::VarInt;
use crate::consensus::{Decodable, Encodable}; use crate::consensus::{Decodable, Encodable};
use crate::hash_types::{FilterHash, FilterHeader}; use crate::hash_types::impl_hashencode;
use crate::prelude::*; use crate::prelude::*;
/// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845 /// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845
const P: u8 = 19; const P: u8 = 19;
const M: u64 = 784931; const M: u64 = 784931;
hashes::hash_newtype! {
/// Filter hash, as defined in BIP-157
pub struct FilterHash(sha256d::Hash);
/// Filter header, as defined in BIP-157
pub struct FilterHeader(sha256d::Hash);
}
impl_hashencode!(FilterHash);
impl_hashencode!(FilterHeader);
/// Errors for blockfilter. /// Errors for blockfilter.
#[derive(Debug)] #[derive(Debug)]
#[non_exhaustive] #[non_exhaustive]

View File

@ -23,9 +23,9 @@ use internals::write_err;
use io::{Cursor, Read}; use io::{Cursor, Read};
use crate::bip152::{PrefilledTransaction, ShortId}; use crate::bip152::{PrefilledTransaction, ShortId};
use crate::bip158::{FilterHash, FilterHeader};
use crate::blockdata::block::{self, BlockHash, TxMerkleNode}; use crate::blockdata::block::{self, BlockHash, TxMerkleNode};
use crate::blockdata::transaction::{Transaction, TxIn, TxOut}; use crate::blockdata::transaction::{Transaction, TxIn, TxOut};
use crate::hash_types::{FilterHash, FilterHeader};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use crate::p2p::{ use crate::p2p::{
address::{AddrV2Message, Address}, address::{AddrV2Message, Address},

View File

@ -49,25 +49,8 @@ macro_rules! impl_asref_push_bytes {
} }
pub(crate) use impl_asref_push_bytes; pub(crate) use impl_asref_push_bytes;
// newtypes module is solely here so we can rustfmt::skip.
#[rustfmt::skip]
#[doc(inline)]
pub use newtypes::*;
#[rustfmt::skip]
mod newtypes {
use hashes::{sha256d, hash_newtype};
hash_newtype! {
/// Filter hash, as defined in BIP-157
pub struct FilterHash(sha256d::Hash);
/// Filter header, as defined in BIP-157
pub struct FilterHeader(sha256d::Hash);
}
impl_hashencode!(FilterHash);
impl_hashencode!(FilterHeader);
}
#[deprecated(since = "0.0.0-NEXT-RELEASE", note = "use crate::T instead")] #[deprecated(since = "0.0.0-NEXT-RELEASE", note = "use crate::T instead")]
pub use crate::{BlockHash, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode, Wtxid}; pub use crate::{
BlockHash, FilterHash, FilterHeader, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode,
Wtxid,
};

View File

@ -121,6 +121,7 @@ pub mod taproot;
pub use crate::{ pub use crate::{
address::{Address, AddressType}, address::{Address, AddressType},
amount::{Amount, Denomination, SignedAmount}, amount::{Amount, Denomination, SignedAmount},
bip158::{FilterHash, FilterHeader},
bip32::XKeyIdentifier, bip32::XKeyIdentifier,
blockdata::block::{self, Block, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment}, blockdata::block::{self, Block, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment},
blockdata::constants, blockdata::constants,
@ -137,7 +138,6 @@ pub use crate::{
crypto::ecdsa, crypto::ecdsa,
crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, WPubkeyHash, XOnlyPublicKey}, crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, WPubkeyHash, XOnlyPublicKey},
crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag}, crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag},
hash_types::{FilterHash, FilterHeader},
merkle_tree::MerkleBlock, merkle_tree::MerkleBlock,
network::Network, network::Network,
pow::{CompactTarget, Target, Work}, pow::{CompactTarget, Target, Work},

View File

@ -5,8 +5,8 @@
//! This module describes BIP157 Client Side Block Filtering network messages. //! This module describes BIP157 Client Side Block Filtering network messages.
//! //!
use crate::bip158::{FilterHash, FilterHeader};
use crate::blockdata::block::BlockHash; use crate::blockdata::block::BlockHash;
use crate::hash_types::{FilterHash, FilterHeader};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
/// getcfilters message /// getcfilters message