Wrap Transaction in Arc

This commit is contained in:
Jane Lusby 2020-06-05 10:58:01 -07:00 committed by Deirdre Connolly
parent b263489af6
commit 9f802cd8dd
4 changed files with 27 additions and 4 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
.firebase/
# Emacs detritus
*~
# Vscode detrius
.vscode/

View File

@ -6,7 +6,7 @@ mod tests;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use chrono::{DateTime, TimeZone, Utc};
use std::{fmt, io};
use std::{fmt, io, sync::Arc};
#[cfg(test)]
use proptest_derive::Arbitrary;
@ -205,7 +205,7 @@ pub struct Block {
/// The block header, containing block metadata.
pub header: BlockHeader,
/// The block transactions.
pub transactions: Vec<Transaction>,
pub transactions: Vec<Arc<Transaction>>,
}
impl Block {

View File

@ -2,7 +2,10 @@
//! transaction types, so that all of the serialization logic is in one place.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::io::{self, Read};
use std::{
io::{self, Read},
sync::Arc,
};
use crate::notes;
use crate::proofs::ZkSnarkProof;
@ -564,3 +567,21 @@ impl ZcashDeserialize for Transaction {
}
}
}
impl<T> ZcashDeserialize for Arc<T>
where
T: ZcashDeserialize,
{
fn zcash_deserialize<R: io::Read>(reader: R) -> Result<Self, SerializationError> {
Ok(Arc::new(T::zcash_deserialize(reader)?))
}
}
impl<T> ZcashSerialize for Arc<T>
where
T: ZcashSerialize,
{
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), io::Error> {
T::zcash_serialize(self, writer)
}
}

View File

@ -236,7 +236,7 @@ pub enum Message {
/// A `tx` message.
///
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#tx)
Tx(Box<Transaction>),
Tx(Arc<Transaction>),
/// A `mempool` message.
///