use crate::hashes::{hash160, hash_newtype, sha256, sha256d, Hash};
macro_rules! impl_hashencode {
($hashtype:ident) => {
impl $crate::encode::Encodable for $hashtype {
fn consensus_encode<W: std::io::Write>(
&self,
w: W,
) -> Result<usize, crate::encode::Error> {
self.0.consensus_encode(w)
}
}
impl $crate::encode::Decodable for $hashtype {
fn consensus_decode<R: std::io::Read>(r: R) -> Result<Self, $crate::encode::Error> {
Ok(Self::from_byte_array(
<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?,
))
}
}
};
}
hash_newtype! {
pub struct Txid(sha256d::Hash);
pub struct Wtxid(sha256d::Hash);
pub struct BlockHash(sha256d::Hash);
pub struct Sighash(sha256d::Hash);
pub struct PubkeyHash(hash160::Hash);
pub struct ScriptHash(hash160::Hash);
pub struct WPubkeyHash(hash160::Hash);
pub struct WScriptHash(sha256::Hash);
pub struct TxMerkleNode(sha256d::Hash);
}
impl_hashencode!(Txid);
impl_hashencode!(Wtxid);
impl_hashencode!(Sighash);
impl_hashencode!(BlockHash);
impl_hashencode!(TxMerkleNode);