Use named fields in Transaction struct
This commit is contained in:
@@ -36,13 +36,16 @@ impl fmt::Display for TxId {
|
|||||||
|
|
||||||
/// A Zcash transaction.
|
/// A Zcash transaction.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Transaction(TransactionData, TxId);
|
pub struct Transaction {
|
||||||
|
txid: TxId,
|
||||||
|
data: TransactionData,
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for Transaction {
|
impl Deref for Transaction {
|
||||||
type Target = TransactionData;
|
type Target = TransactionData;
|
||||||
|
|
||||||
fn deref(&self) -> &TransactionData {
|
fn deref(&self) -> &TransactionData {
|
||||||
&self.0
|
&self.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,17 +136,20 @@ impl TransactionData {
|
|||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
fn from_data(data: TransactionData) -> io::Result<Self> {
|
fn from_data(data: TransactionData) -> io::Result<Self> {
|
||||||
let mut tx = Transaction(data, TxId([0; 32]));
|
let mut tx = Transaction {
|
||||||
|
txid: TxId([0; 32]),
|
||||||
|
data,
|
||||||
|
};
|
||||||
let mut raw = vec![];
|
let mut raw = vec![];
|
||||||
tx.write(&mut raw)?;
|
tx.write(&mut raw)?;
|
||||||
(tx.1)
|
tx.txid
|
||||||
.0
|
.0
|
||||||
.copy_from_slice(&Sha256::digest(&Sha256::digest(&raw)));
|
.copy_from_slice(&Sha256::digest(&Sha256::digest(&raw)));
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn txid(&self) -> TxId {
|
pub fn txid(&self) -> TxId {
|
||||||
self.1
|
self.txid
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||||
|
|||||||
Reference in New Issue
Block a user