parent
762617b917
commit
51b888c0ff
|
|
@ -1,6 +1,8 @@
|
|||
//! Transaction types.
|
||||
|
||||
use std::io;
|
||||
use std::{fmt, io};
|
||||
|
||||
use hex;
|
||||
|
||||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
use crate::sha256d_writer::Sha256dWriter;
|
||||
|
|
@ -9,9 +11,17 @@ use crate::sha256d_writer::Sha256dWriter;
|
|||
///
|
||||
/// TODO: I'm pretty sure this is also a SHA256d hash but I haven't
|
||||
/// confirmed it yet.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub struct TransactionHash(pub [u8; 32]);
|
||||
|
||||
impl fmt::Debug for TransactionHash {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("TransactionHash")
|
||||
.field(&hex::encode(&self.0))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Transaction> for TransactionHash {
|
||||
fn from(transaction: Transaction) -> Self {
|
||||
let mut hash_writer = Sha256dWriter::default();
|
||||
|
|
@ -122,3 +132,27 @@ impl ZcashDeserialize for Transaction {
|
|||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use super::TransactionHash;
|
||||
|
||||
use crate::sha256d_writer::Sha256dWriter;
|
||||
|
||||
#[test]
|
||||
fn transactionhash_debug() {
|
||||
let preimage = b"foo bar baz";
|
||||
let mut sha_writer = Sha256dWriter::default();
|
||||
let _ = sha_writer.write_all(preimage);
|
||||
|
||||
let hash = TransactionHash(sha_writer.finish());
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", hash),
|
||||
"TransactionHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue