Add prevHash field to CompactBlock

This enables basic verification of chain validity when CompactBlocks are
received without the full header.
This commit is contained in:
Jack Grigg
2019-05-01 13:21:48 +01:00
parent fd87121244
commit 2774d2730f
3 changed files with 69 additions and 3 deletions

View File

@@ -18,6 +18,20 @@ impl fmt::Display for BlockHash {
}
}
impl BlockHash {
/// Constructs a [`BlockHash`] from the given slice.
///
/// # Panics
///
/// This function will panic if the slice is not exactly 32 bytes.
pub fn from_slice(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), 32);
let mut hash = [0; 32];
hash.copy_from_slice(&bytes);
BlockHash(hash)
}
}
/// A Zcash block header.
pub struct BlockHeader {
hash: BlockHash,