From ebdceb519765e12e2969be670faf085e1c4702bb Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 17 Aug 2020 02:26:33 -0700 Subject: [PATCH] chain: rename TransactionHash to transaction::Hash --- zebra-chain/src/transaction.rs | 2 +- zebra-chain/src/transaction/hash.rs | 17 ++++++++--------- zebra-chain/src/transparent.rs | 2 +- zebra-chain/src/transparent/serialize.rs | 4 ++-- zebra-network/src/protocol/external/inv.rs | 16 ++++++++-------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 8fa40a519..5bd13f92a 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -12,7 +12,7 @@ mod shielded_data; #[cfg(test)] mod tests; -pub use hash::TransactionHash; +pub use hash::Hash; pub use joinsplit::JoinSplitData; pub use lock_time::LockTime; pub use memo::Memo; diff --git a/zebra-chain/src/transaction/hash.rs b/zebra-chain/src/transaction/hash.rs index 94b50df3f..9aa85e4b1 100644 --- a/zebra-chain/src/transaction/hash.rs +++ b/zebra-chain/src/transaction/hash.rs @@ -15,9 +15,9 @@ use super::Transaction; /// confirmed it yet. #[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] -pub struct TransactionHash(pub [u8; 32]); +pub struct Hash(pub [u8; 32]); -impl From for TransactionHash { +impl From for Hash { fn from(transaction: Transaction) -> Self { let mut hash_writer = sha256d::Writer::default(); transaction @@ -27,7 +27,7 @@ impl From for TransactionHash { } } -impl fmt::Debug for TransactionHash { +impl fmt::Debug for Hash { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("TransactionHash") .field(&hex::encode(&self.0)) @@ -35,7 +35,7 @@ impl fmt::Debug for TransactionHash { } } -impl std::str::FromStr for TransactionHash { +impl std::str::FromStr for Hash { type Err = SerializationError; fn from_str(s: &str) -> Result { @@ -43,7 +43,7 @@ impl std::str::FromStr for TransactionHash { if hex::decode_to_slice(s, &mut bytes[..]).is_err() { Err(SerializationError::Parse("hex decoding error")) } else { - Ok(TransactionHash(bytes)) + Ok(Hash(bytes)) } } } @@ -54,10 +54,9 @@ mod tests { #[test] fn transactionhash_from_str() { - let hash: TransactionHash = - "bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631" - .parse() - .unwrap(); + let hash: Hash = "bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631" + .parse() + .unwrap(); assert_eq!( format!("{:?}", hash), r#"TransactionHash("bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631")"# diff --git a/zebra-chain/src/transparent.rs b/zebra-chain/src/transparent.rs index 2936a31bc..f2245e2ca 100644 --- a/zebra-chain/src/transparent.rs +++ b/zebra-chain/src/transparent.rs @@ -44,7 +44,7 @@ impl AsRef<[u8]> for CoinbaseData { #[cfg_attr(test, derive(Arbitrary))] pub struct OutPoint { /// References the transaction that contains the UTXO being spent. - pub hash: transaction::TransactionHash, + pub hash: transaction::Hash, /// Identifies which UTXO from that transaction is referenced; the /// first output is 0, etc. diff --git a/zebra-chain/src/transparent/serialize.rs b/zebra-chain/src/transparent/serialize.rs index cbc091fc1..64595feef 100644 --- a/zebra-chain/src/transparent/serialize.rs +++ b/zebra-chain/src/transparent/serialize.rs @@ -37,7 +37,7 @@ impl ZcashSerialize for OutPoint { impl ZcashDeserialize for OutPoint { fn zcash_deserialize(mut reader: R) -> Result { Ok(OutPoint { - hash: transaction::TransactionHash(reader.read_32_bytes()?), + hash: transaction::Hash(reader.read_32_bytes()?), index: reader.read_u32::()?, }) } @@ -204,7 +204,7 @@ impl ZcashDeserialize for Input { } else { Ok(Input::PrevOut { outpoint: OutPoint { - hash: transaction::TransactionHash(bytes), + hash: transaction::Hash(bytes), index: reader.read_u32::()?, }, unlock_script: Script::zcash_deserialize(&mut reader)?, diff --git a/zebra-network/src/protocol/external/inv.rs b/zebra-network/src/protocol/external/inv.rs index 9b7d948d1..d85401a6c 100644 --- a/zebra-network/src/protocol/external/inv.rs +++ b/zebra-network/src/protocol/external/inv.rs @@ -8,11 +8,11 @@ use std::io::{Read, Write}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use zebra_chain::block; -use zebra_chain::serialization::{ - ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize, +use zebra_chain::{ + block, + serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize}, + transaction, }; -use zebra_chain::transaction::TransactionHash; /// An inventory hash which refers to some advertised or requested data. /// @@ -28,7 +28,7 @@ pub enum InventoryHash { /// so we don't include a typed hash. Error, /// A hash of a transaction. - Tx(TransactionHash), + Tx(transaction::Hash), /// A hash of a block. Block(block::Hash), /// A hash of a filtered block. @@ -40,8 +40,8 @@ pub enum InventoryHash { FilteredBlock(block::Hash), } -impl From for InventoryHash { - fn from(tx: TransactionHash) -> InventoryHash { +impl From for InventoryHash { + fn from(tx: transaction::Hash) -> InventoryHash { InventoryHash::Tx(tx) } } @@ -74,7 +74,7 @@ impl ZcashDeserialize for InventoryHash { let bytes = reader.read_32_bytes()?; match code { 0 => Ok(InventoryHash::Error), - 1 => Ok(InventoryHash::Tx(TransactionHash(bytes))), + 1 => Ok(InventoryHash::Tx(transaction::Hash(bytes))), 2 => Ok(InventoryHash::Block(block::Hash(bytes))), 3 => Ok(InventoryHash::FilteredBlock(block::Hash(bytes))), _ => Err(SerializationError::Parse("invalid inventory code")),