chain: add Transaction::hash() method.
This makes Transaction and Block have a consistent API.
This commit is contained in:
parent
a9029beb87
commit
ca4a5ce30c
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -17,8 +17,8 @@ use super::Transaction;
|
|||
#[cfg_attr(test, derive(Arbitrary))]
|
||||
pub struct Hash(pub [u8; 32]);
|
||||
|
||||
impl From<Transaction> 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)
|
||||
|
|
Loading…
Reference in New Issue