From 4746ccb88ed662d1dc610b4917310c1da34a9671 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 9 Dec 2019 23:43:33 +0100 Subject: [PATCH] Final work on Txid and other hashes Fixing issue with external dependency and hash_newtype macro implementation Reverting back to the bitcoin_hashes crate after new version release --- src/blockdata/transaction.rs | 4 ++-- src/hash_types.rs | 3 +++ src/network/message.rs | 4 ++-- src/network/message_filter.rs | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 3efb5652..9a1cd587 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -295,7 +295,7 @@ impl Transaction { /// this will give the correct txid (not including witnesses) while `bitcoin_hash` /// will also hash witnesses. pub fn txid(&self) -> Txid { - let mut enc = sha256d::Hash::engine(); + let mut enc = Txid::engine(); self.version.consensus_encode(&mut enc).unwrap(); self.input.consensus_encode(&mut enc).unwrap(); self.output.consensus_encode(&mut enc).unwrap(); @@ -440,7 +440,7 @@ impl Transaction { impl BitcoinHash for Transaction { fn bitcoin_hash(&self) -> Txid { - let mut enc = sha256d::Hash::engine(); + let mut enc = Txid::engine(); self.consensus_encode(&mut enc).unwrap(); Txid::from_engine(enc) } diff --git a/src/hash_types.rs b/src/hash_types.rs index 6d0af918..3bfa8a69 100644 --- a/src/hash_types.rs +++ b/src/hash_types.rs @@ -20,6 +20,9 @@ use std::io; use consensus::encode::{Encodable, Decodable, Error}; use hashes::{sha256, sha256d, hash160, Hash}; + +// Do not remove: required in order to get hash types implementation macros to work correctly +#[allow(unused_imports)] use hashes::hex::{ToHex, FromHex}; macro_rules! impl_hashencode { diff --git a/src/network/message.rs b/src/network/message.rs index 88187495..f1bd95ef 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -375,8 +375,8 @@ mod test { NetworkMessage::GetAddr, NetworkMessage::Ping(15), NetworkMessage::Pong(23), - NetworkMessage::GetCFilters(GetCFilters{filter_type: 2, start_height: 52, stop_hash: hash([42u8; 32])}), - NetworkMessage::CFilter(CFilter{filter_type: 7, block_hash: hash([25u8; 32]), filter: vec![1,2,3]}), + NetworkMessage::GetCFilters(GetCFilters{filter_type: 2, start_height: 52, stop_hash: hash([42u8; 32]).into()}), + NetworkMessage::CFilter(CFilter{filter_type: 7, block_hash: hash([25u8; 32]).into(), filter: vec![1,2,3]}), NetworkMessage::GetCFHeaders(GetCFHeaders{filter_type: 4, start_height: 102, stop_hash: hash([47u8; 32])}), NetworkMessage::CFHeaders(CFHeaders{filter_type: 13, stop_hash: hash([53u8; 32]), previous_filter: hash([12u8; 32]), filter_hashes: vec![hash([4u8; 32]), hash([12u8; 32])]}), NetworkMessage::GetCFCheckpt(GetCFCheckpt{filter_type: 17, stop_hash: hash([25u8; 32])}), diff --git a/src/network/message_filter.rs b/src/network/message_filter.rs index 20076c8a..567e5b16 100644 --- a/src/network/message_filter.rs +++ b/src/network/message_filter.rs @@ -1,6 +1,8 @@ //! //! BIP157 Client Side Block Filtering network messages //! + +use hash_types::BlockHash; use hashes::sha256d; #[derive(PartialEq, Eq, Clone, Debug)] @@ -11,7 +13,7 @@ pub struct GetCFilters { /// The height of the first block in the requested range pub start_height: u32, /// The hash of the last block in the requested range - pub stop_hash: sha256d::Hash, + pub stop_hash: BlockHash, } impl_consensus_encoding!(GetCFilters, filter_type, start_height, stop_hash); @@ -21,7 +23,7 @@ pub struct CFilter { /// Byte identifying the type of filter being returned pub filter_type: u8, /// Block hash of the Bitcoin block for which the filter is being returned - pub block_hash: sha256d::Hash, + pub block_hash: BlockHash, /// The serialized compact filter for this block pub filter: Vec, }