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
This commit is contained in:
Dr Maxim Orlovsky 2019-12-09 23:43:33 +01:00
parent d20ab1dbc4
commit 4746ccb88e
4 changed files with 11 additions and 6 deletions

View File

@ -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<Txid> 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)
}

View File

@ -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 {

View File

@ -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])}),

View File

@ -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<u8>,
}