chain: rename to block::merkle::{Root, Tree}.
This commit is contained in:
parent
2712c4b72a
commit
94d6d448bb
|
@ -3,7 +3,7 @@ use chrono::{DateTime, Duration, Utc};
|
|||
use crate::serialization::ZcashSerialize;
|
||||
use crate::work::{difficulty::CompactDifficulty, equihash::Solution};
|
||||
|
||||
use super::{merkle::MerkleTreeRootHash, Error, Hash};
|
||||
use super::{merkle, Error, Hash};
|
||||
|
||||
/// Block header.
|
||||
///
|
||||
|
@ -33,7 +33,7 @@ pub struct Header {
|
|||
/// in this block as assembled in a binary tree, ensuring that
|
||||
/// none of those transactions can be modied without modifying the
|
||||
/// header.
|
||||
pub merkle_root_hash: MerkleTreeRootHash,
|
||||
pub merkle_root: merkle::Root,
|
||||
|
||||
/// Some kind of root hash.
|
||||
///
|
||||
|
|
|
@ -13,17 +13,17 @@ use crate::transaction::Transaction;
|
|||
/// A binary hash tree of SHA256d (two rounds of SHA256) hashes for
|
||||
/// node values.
|
||||
#[derive(Default)]
|
||||
pub struct MerkleTree<T> {
|
||||
pub struct Tree<T> {
|
||||
_leaves: Vec<T>,
|
||||
}
|
||||
|
||||
impl<Transaction> ZcashSerialize for MerkleTree<Transaction> {
|
||||
impl<Transaction> ZcashSerialize for Tree<Transaction> {
|
||||
fn zcash_serialize<W: io::Write>(&self, _writer: W) -> Result<(), io::Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<Transaction> ZcashDeserialize for MerkleTree<Transaction> {
|
||||
impl<Transaction> ZcashDeserialize for Tree<Transaction> {
|
||||
fn zcash_deserialize<R: io::Read>(_reader: R) -> Result<Self, SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ impl<Transaction> ZcashDeserialize for MerkleTree<Transaction> {
|
|||
/// hashed transactions in a block.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Arbitrary))]
|
||||
pub struct MerkleTreeRootHash(pub [u8; 32]);
|
||||
pub struct Root(pub [u8; 32]);
|
||||
|
||||
impl From<MerkleTree<Transaction>> for MerkleTreeRootHash {
|
||||
fn from(merkle_tree: MerkleTree<Transaction>) -> Self {
|
||||
impl From<Tree<Transaction>> for Root {
|
||||
fn from(merkle_tree: Tree<Transaction>) -> Self {
|
||||
let mut hash_writer = sha256d::Writer::default();
|
||||
merkle_tree
|
||||
.zcash_serialize(&mut hash_writer)
|
||||
|
@ -45,10 +45,8 @@ impl From<MerkleTree<Transaction>> for MerkleTreeRootHash {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for MerkleTreeRootHash {
|
||||
impl fmt::Debug for Root {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("MerkleTreeRootHash")
|
||||
.field(&hex::encode(&self.0))
|
||||
.finish()
|
||||
f.debug_tuple("Root").field(&hex::encode(&self.0)).finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@ use crate::serialization::ZcashDeserializeInto;
|
|||
use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
use crate::work::{difficulty::CompactDifficulty, equihash};
|
||||
|
||||
use super::merkle::MerkleTreeRootHash;
|
||||
use super::Block;
|
||||
use super::Hash;
|
||||
use super::Header;
|
||||
use super::{merkle, Block, Hash, Header};
|
||||
|
||||
/// The maximum size of a Zcash block, in bytes.
|
||||
///
|
||||
|
@ -23,7 +20,7 @@ impl ZcashSerialize for Header {
|
|||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_u32::<LittleEndian>(self.version)?;
|
||||
self.previous_block_hash.zcash_serialize(&mut writer)?;
|
||||
writer.write_all(&self.merkle_root_hash.0[..])?;
|
||||
writer.write_all(&self.merkle_root.0[..])?;
|
||||
writer.write_all(&self.root_bytes[..])?;
|
||||
// this is a truncating cast, rather than a saturating cast
|
||||
// but u32 times are valid until 2106, and our block verification time
|
||||
|
@ -71,7 +68,7 @@ impl ZcashDeserialize for Header {
|
|||
Ok(Header {
|
||||
version,
|
||||
previous_block_hash: Hash::zcash_deserialize(&mut reader)?,
|
||||
merkle_root_hash: MerkleTreeRootHash(reader.read_32_bytes()?),
|
||||
merkle_root: merkle::Root(reader.read_32_bytes()?),
|
||||
root_bytes: reader.read_32_bytes()?,
|
||||
// This can't panic, because all u32 values are valid `Utc.timestamp`s
|
||||
time: Utc.timestamp(reader.read_u32::<LittleEndian>()? as i64, 0),
|
||||
|
|
|
@ -31,7 +31,7 @@ impl Arbitrary for Header {
|
|||
// version is interpreted as i32 in the spec, so we are limited to i32::MAX here
|
||||
(4u32..(i32::MAX as u32)),
|
||||
any::<Hash>(),
|
||||
any::<merkle::MerkleTreeRootHash>(),
|
||||
any::<merkle::Root>(),
|
||||
any::<[u8; 32]>(),
|
||||
// time is interpreted as u32 in the spec, but rust timestamps are i64
|
||||
(0i64..(u32::MAX as i64)),
|
||||
|
@ -52,7 +52,7 @@ impl Arbitrary for Header {
|
|||
)| Header {
|
||||
version,
|
||||
previous_block_hash,
|
||||
merkle_root_hash,
|
||||
merkle_root: merkle_root_hash,
|
||||
root_bytes,
|
||||
time: Utc.timestamp(timestamp, 0),
|
||||
difficulty_threshold,
|
||||
|
|
Loading…
Reference in New Issue