chain: rename TransactionHash to transaction::Hash

This commit is contained in:
Henry de Valence 2020-08-17 02:26:33 -07:00
parent d49d3d2b30
commit ebdceb5197
5 changed files with 20 additions and 21 deletions

View File

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

View File

@ -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<Transaction> for TransactionHash {
impl From<Transaction> for Hash {
fn from(transaction: Transaction) -> Self {
let mut hash_writer = sha256d::Writer::default();
transaction
@ -27,7 +27,7 @@ impl From<Transaction> 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<Self, Self::Err> {
@ -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")"#

View File

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

View File

@ -37,7 +37,7 @@ impl ZcashSerialize for OutPoint {
impl ZcashDeserialize for OutPoint {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
Ok(OutPoint {
hash: transaction::TransactionHash(reader.read_32_bytes()?),
hash: transaction::Hash(reader.read_32_bytes()?),
index: reader.read_u32::<LittleEndian>()?,
})
}
@ -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::<LittleEndian>()?,
},
unlock_script: Script::zcash_deserialize(&mut reader)?,

View File

@ -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<TransactionHash> for InventoryHash {
fn from(tx: TransactionHash) -> InventoryHash {
impl From<transaction::Hash> 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")),