Skip to content

Commit

Permalink
Final work on Txid and other hashes
Browse files Browse the repository at this point in the history
Fixing issue with external dependency and hash_newtype macro implementation

Reverting back to the bitcoin_hashes crate after new version release
  • Loading branch information
dr-orlovsky committed Jan 1, 2020
1 parent d20ab1d commit 4746ccb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions src/hash_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])}),
Expand Down
6 changes: 4 additions & 2 deletions src/network/message_filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//!
//! BIP157 Client Side Block Filtering network messages
//!
use hash_types::BlockHash;
use hashes::sha256d;

#[derive(PartialEq, Eq, Clone, Debug)]
Expand All @@ -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);

Expand All @@ -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>,
}
Expand Down

0 comments on commit 4746ccb

Please sign in to comment.