2019-12-09 22:37:52 +00:00
|
|
|
// Rust Bitcoin Library
|
|
|
|
// Written in 2014 by
|
|
|
|
// Andrew Poelstra <apoelstra@wpsoftware.net>
|
|
|
|
//
|
|
|
|
// To the extent possible under law, the author(s) have dedicated all
|
|
|
|
// copyright and related and neighboring rights to this software to
|
|
|
|
// the public domain worldwide. This software is distributed without
|
|
|
|
// any warranty.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the CC0 Public Domain Dedication
|
|
|
|
// along with this software.
|
|
|
|
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
//! File defines types for hashes used throughout the library. These types are needed in order
|
|
|
|
//! to avoid mixing data of the same hash format (like SHA256d) but of different meaning
|
|
|
|
//! (transaction id, block hash etc).
|
|
|
|
|
2020-09-14 14:57:42 +00:00
|
|
|
use hashes::{Hash, sha256, sha256d, hash160};
|
2019-12-09 22:37:52 +00:00
|
|
|
|
|
|
|
macro_rules! impl_hashencode {
|
|
|
|
($hashtype:ident) => {
|
2020-01-22 10:28:11 +00:00
|
|
|
impl $crate::consensus::Encodable for $hashtype {
|
2020-10-09 15:04:10 +00:00
|
|
|
fn consensus_encode<S: ::std::io::Write>(&self, s: S) -> Result<usize, ::std::io::Error> {
|
2019-12-09 22:37:52 +00:00
|
|
|
self.0.consensus_encode(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 10:28:11 +00:00
|
|
|
impl $crate::consensus::Decodable for $hashtype {
|
|
|
|
fn consensus_decode<D: ::std::io::Read>(d: D) -> Result<Self, $crate::consensus::encode::Error> {
|
|
|
|
use $crate::hashes::Hash;
|
|
|
|
Ok(Self::from_inner(<<$hashtype as $crate::hashes::Hash>::Inner>::consensus_decode(d)?))
|
2019-12-09 22:37:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hash_newtype!(Txid, sha256d::Hash, 32, doc="A bitcoin transaction hash/transaction ID.");
|
|
|
|
hash_newtype!(Wtxid, sha256d::Hash, 32, doc="A bitcoin witness transaction ID.");
|
|
|
|
hash_newtype!(BlockHash, sha256d::Hash, 32, doc="A bitcoin block hash.");
|
2019-12-06 09:01:15 +00:00
|
|
|
hash_newtype!(SigHash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
|
|
|
|
|
2019-12-09 22:37:52 +00:00
|
|
|
hash_newtype!(PubkeyHash, hash160::Hash, 20, doc="A hash of a public key.");
|
|
|
|
hash_newtype!(ScriptHash, hash160::Hash, 20, doc="A hash of Bitcoin Script bytecode.");
|
|
|
|
hash_newtype!(WPubkeyHash, hash160::Hash, 20, doc="SegWit version of a public key hash.");
|
|
|
|
hash_newtype!(WScriptHash, sha256::Hash, 32, doc="SegWit version of a Bitcoin Script bytecode hash.");
|
2019-12-06 09:01:15 +00:00
|
|
|
|
2019-12-18 11:40:46 +00:00
|
|
|
hash_newtype!(TxMerkleNode, sha256d::Hash, 32, doc="A hash of the Merkle tree branch or root for transactions");
|
|
|
|
hash_newtype!(WitnessMerkleNode, sha256d::Hash, 32, doc="A hash corresponding to the Merkle tree root for witness data");
|
2019-12-06 09:01:15 +00:00
|
|
|
hash_newtype!(WitnessCommitment, sha256d::Hash, 32, doc="A hash corresponding to the witness structure commitment in the coinbase transaction");
|
2019-12-09 22:37:52 +00:00
|
|
|
hash_newtype!(XpubIdentifier, hash160::Hash, 20, doc="XpubIdentifier as defined in BIP-32.");
|
|
|
|
|
2020-08-07 12:23:35 +00:00
|
|
|
hash_newtype!(FilterHash, sha256d::Hash, 32, doc="Filter hash, as defined in BIP-157");
|
|
|
|
hash_newtype!(FilterHeader, sha256d::Hash, 32, doc="Filter header, as defined in BIP-157");
|
2019-12-06 09:01:15 +00:00
|
|
|
|
|
|
|
|
2019-12-09 22:37:52 +00:00
|
|
|
impl_hashencode!(Txid);
|
2019-11-30 16:00:17 +00:00
|
|
|
impl_hashencode!(Wtxid);
|
2019-12-06 09:01:15 +00:00
|
|
|
impl_hashencode!(SigHash);
|
2019-11-30 16:00:17 +00:00
|
|
|
impl_hashencode!(BlockHash);
|
2019-12-18 11:40:46 +00:00
|
|
|
impl_hashencode!(TxMerkleNode);
|
|
|
|
impl_hashencode!(WitnessMerkleNode);
|
2019-12-06 09:01:15 +00:00
|
|
|
impl_hashencode!(FilterHash);
|
2020-08-07 12:23:35 +00:00
|
|
|
impl_hashencode!(FilterHeader);
|