-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding BlockHeader, BlockHash, MerkleRootHash, Sha256dWriter
- Loading branch information
Showing
6 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! A binary hash tree of SHA256d (two rounds of SHA256) hashes for | ||
//! node values. | ||
use std::io; | ||
use std::io::prelude::*; | ||
|
||
use sha2::{Digest, Sha256}; | ||
|
||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; | ||
|
||
/// A binary hash tree of SHA256d (two rounds of SHA256) hashes for | ||
/// node values. | ||
#[derive(Default)] | ||
pub struct MerkleTree<T> { | ||
leaves: Vec<T>, | ||
} | ||
|
||
impl<T> MerkleTree<T> { | ||
pub fn get_root(&self) -> Sha256 { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
impl<T> ZcashSerialize for MerkleTree<T> { | ||
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), SerializationError> { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
impl<T> ZcashDeserialize for MerkleTree<T> { | ||
fn zcash_deserialize<R: io::Read>(reader: R) -> Result<Self, SerializationError> { | ||
unimplemented!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! A Writer for Sha256d-related (two rounds of SHA256) types. | ||
use std::io::prelude::*; | ||
|
||
use sha2::{Digest, Sha256}; | ||
|
||
/// A type that lets you write out SHA256d (double-SHA256, as in two rounds). | ||
#[derive(Default)] | ||
pub struct Sha256dWriter { | ||
hash: Sha256, | ||
} | ||
|
||
impl Sha256dWriter { | ||
/// Consume the Writer and produce the hash result. | ||
pub fn finish(self) -> [u8; 32] { | ||
let result1 = self.hash.result(); | ||
let result2 = Sha256::digest(&result1); | ||
let mut buffer = [0u8; 32]; | ||
buffer[0..32].copy_from_slice(&result2[0..32]); | ||
buffer | ||
} | ||
} | ||
|
||
impl Write for Sha256dWriter { | ||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { | ||
self.hash.input(buf); | ||
Ok(buf.len()) | ||
} | ||
|
||
fn flush(&mut self) -> std::io::Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters