diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 6ce2fb24..9215a484 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -50,7 +50,7 @@ impl Block { }) } - /// Get the hash for the current block + /// Compute the hash of this block. pub fn hash(&self) -> Hash { Hash::from(self) } diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 5bd13f92..28d03616 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -97,6 +97,11 @@ pub enum Transaction { } impl Transaction { + /// Compute the hash of this transaction. + pub fn hash(&self) -> Hash { + Hash::from(self) + } + /// Access the transparent inputs of this transaction, regardless of version. pub fn inputs(&self) -> &[transparent::Input] { match self { diff --git a/zebra-chain/src/transaction/hash.rs b/zebra-chain/src/transaction/hash.rs index 322bf40b..af6dc8c2 100644 --- a/zebra-chain/src/transaction/hash.rs +++ b/zebra-chain/src/transaction/hash.rs @@ -17,8 +17,8 @@ use super::Transaction; #[cfg_attr(test, derive(Arbitrary))] pub struct Hash(pub [u8; 32]); -impl From for Hash { - fn from(transaction: Transaction) -> Self { +impl<'a> From<&'a Transaction> for Hash { + fn from(transaction: &'a Transaction) -> Self { let mut hash_writer = sha256d::Writer::default(); transaction .zcash_serialize(&mut hash_writer)