Move around MerkleTree* structs
This commit is contained in:
parent
677d53897f
commit
3f2a1b4f2c
|
|
@ -3,7 +3,7 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use std::io;
|
||||
|
||||
use crate::merkle_tree::MerkleTree;
|
||||
use crate::merkle_tree::MerkleTreeRootHash;
|
||||
use crate::note_commitment_tree::SaplingNoteTreeRootHash;
|
||||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
use crate::sha256d_writer::Sha256dWriter;
|
||||
|
|
@ -26,33 +26,6 @@ impl From<BlockHeader> for BlockHeaderHash {
|
|||
}
|
||||
}
|
||||
|
||||
/// A SHA-256d hash of the root node of a merkle tree of SHA256-d
|
||||
/// hashed transactions in a block.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MerkleRootHash([u8; 32]);
|
||||
|
||||
impl<Transaction> ZcashSerialize for MerkleTree<Transaction> {
|
||||
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<Transaction> ZcashDeserialize for MerkleTree<Transaction> {
|
||||
fn zcash_deserialize<R: io::Read>(reader: R) -> Result<Self, SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MerkleTree<Transaction>> for MerkleRootHash {
|
||||
fn from(merkle_tree: MerkleTree<Transaction>) -> Self {
|
||||
let mut hash_writer = Sha256dWriter::default();
|
||||
merkle_tree
|
||||
.zcash_serialize(&mut hash_writer)
|
||||
.expect("The merkle tree of transactions must serialize.");
|
||||
Self(hash_writer.finish())
|
||||
}
|
||||
}
|
||||
|
||||
/// Block header.
|
||||
///
|
||||
/// How are blocks chained together? They are chained together via the
|
||||
|
|
@ -78,7 +51,7 @@ pub struct BlockHeader {
|
|||
/// in this block as assembled in a binary tree, ensuring that
|
||||
/// none of those transactions can be modied without modifying the
|
||||
/// header.
|
||||
merkle_root_hash: MerkleRootHash,
|
||||
merkle_root_hash: MerkleTreeRootHash,
|
||||
|
||||
/// [Sapling onward] The root LEBS2OSP256(rt) of the Sapling note
|
||||
/// commitment tree corresponding to the finnal Sapling treestate of
|
||||
|
|
@ -114,13 +87,6 @@ pub struct BlockHeader {
|
|||
solution: Vec<u8>,
|
||||
}
|
||||
|
||||
impl BlockHeader {
|
||||
/// Get the SHA-256d hash in internal byte order of this block header.
|
||||
pub fn hash(&self) -> [u8; 32] {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashSerialize for BlockHeader {
|
||||
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), SerializationError> {
|
||||
unimplemented!();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
//! Equihash Solution and related items.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use hex::ToHex;
|
||||
|
||||
/// The size of an Equihash solution in bytes (always 1344).
|
||||
const EQUIHASH_SOLUTION_SIZE = 1344;
|
||||
|
||||
/// Equihash Solution.
|
||||
///
|
||||
/// A wrapper around [u8; 1344] because Rust doesn't implement common
|
||||
/// traits like `Debug`, `Clone`, etc for collections like array
|
||||
/// beyond lengths 0 to 32.
|
||||
///
|
||||
/// The size of an Equihash solution in bytes is always 1344 so the
|
||||
/// length of this type is fixed.
|
||||
#[derive(Clone)]
|
||||
pub struct EquihashSolution([u8; EQUIHASH_SOLUTION_SIZE]);
|
||||
|
||||
impl Default for EquihashSolution {
|
||||
fn default() -> Self {
|
||||
EquihashSolution([0; EQUIHASH_SOLUTION_SIZE])
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for EquihashSolution {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(&self.0.encode_hex::<String>())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,14 @@
|
|||
//! A binary hash tree of SHA256d (two rounds of SHA256) hashes for
|
||||
//! node values.
|
||||
|
||||
use std::io;
|
||||
|
||||
use sha2::Sha256;
|
||||
|
||||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
use crate::sha256d_writer::Sha256dWriter;
|
||||
use crate::transaction::Transaction;
|
||||
|
||||
/// A binary hash tree of SHA256d (two rounds of SHA256) hashes for
|
||||
/// node values.
|
||||
#[derive(Default)]
|
||||
|
|
@ -15,3 +21,30 @@ impl<T> MerkleTree<T> {
|
|||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<Transaction> ZcashSerialize for MerkleTree<Transaction> {
|
||||
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<Transaction> ZcashDeserialize for MerkleTree<Transaction> {
|
||||
fn zcash_deserialize<R: io::Read>(reader: R) -> Result<Self, SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
/// A SHA-256d hash of the root node of a merkle tree of SHA256-d
|
||||
/// hashed transactions in a block.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MerkleTreeRootHash([u8; 32]);
|
||||
|
||||
impl From<MerkleTree<Transaction>> for MerkleTreeRootHash {
|
||||
fn from(merkle_tree: MerkleTree<Transaction>) -> Self {
|
||||
let mut hash_writer = Sha256dWriter::default();
|
||||
merkle_tree
|
||||
.zcash_serialize(&mut hash_writer)
|
||||
.expect("The merkle tree of transactions must serialize.");
|
||||
Self(hash_writer.finish())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::net;
|
|||
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
use zebra_chain::block::{BlockHeaderHash, MerkleRootHash};
|
||||
use zebra_chain::block::Block;
|
||||
use zebra_chain::{transaction::Transaction, types::BlockHeight};
|
||||
|
||||
use crate::meta_addr::MetaAddr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue