From 663f9d619d751eed091577c2ec00ee1d0a8b5756 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 2 Apr 2019 01:29:22 +0100 Subject: [PATCH] Use named fields in Transaction struct --- zcash_primitives/src/transaction/mod.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index b1a877b..93c741d 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -36,13 +36,16 @@ impl fmt::Display for TxId { /// A Zcash transaction. #[derive(Debug)] -pub struct Transaction(TransactionData, TxId); +pub struct Transaction { + txid: TxId, + data: TransactionData, +} impl Deref for Transaction { type Target = TransactionData; fn deref(&self) -> &TransactionData { - &self.0 + &self.data } } @@ -133,17 +136,20 @@ impl TransactionData { impl Transaction { fn from_data(data: TransactionData) -> io::Result { - let mut tx = Transaction(data, TxId([0; 32])); + let mut tx = Transaction { + txid: TxId([0; 32]), + data, + }; let mut raw = vec![]; tx.write(&mut raw)?; - (tx.1) + tx.txid .0 .copy_from_slice(&Sha256::digest(&Sha256::digest(&raw))); Ok(tx) } pub fn txid(&self) -> TxId { - self.1 + self.txid } pub fn read(mut reader: R) -> io::Result {