diff --git a/examples/producer.rs b/examples/producer.rs index 2ef7598..7d93cba 100644 --- a/examples/producer.rs +++ b/examples/producer.rs @@ -204,5 +204,4 @@ fn main() { let tree = prepare_tree(initial_tree_vec); println!("root: {}", tree.root()); - } \ No newline at end of file diff --git a/src/entry.rs b/src/entry.rs index 3ed1c71..485b364 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -1,6 +1,8 @@ use byteorder::{LittleEndian, ReadBytesExt}; -use crate::{EntryKind, NodeData, Error, EntryLink}; +use crate::{EntryKind, NodeData, Error, EntryLink, MAX_NODE_DATA_SIZE}; + +pub const MAX_ENTRY_SIZE: usize = MAX_NODE_DATA_SIZE + 9; #[derive(Debug)] pub struct Entry { diff --git a/src/lib.rs b/src/lib.rs index 552dee2..f0eb3f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,8 @@ mod node_data; mod entry; pub use tree::Tree; -pub use node_data::NodeData; -pub use entry::Entry; +pub use node_data::{NodeData, MAX_NODE_DATA_SIZE}; +pub use entry::{Entry, MAX_ENTRY_SIZE}; #[derive(Debug, derive_more::Display)] pub enum Error { diff --git a/src/node_data.rs b/src/node_data.rs index b95f643..59591e5 100644 --- a/src/node_data.rs +++ b/src/node_data.rs @@ -2,6 +2,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt, ByteOrder}; use bigint::U256; use blake2::blake2b::Blake2b; +pub const MAX_NODE_DATA_SIZE: usize = 32 + 4 + 4 + 4 + 4 + 32 + 32 + 32 + 9 + 9 + 9; // 171 + /// Node metadata. #[repr(C)] #[derive(Debug, Clone, Default)] @@ -36,12 +38,10 @@ fn personalization(branch_id: u32) -> [u8; 16] { } impl NodeData { - pub const MAX_SERIALIZED_SIZE: usize = 32 + 4 + 4 + 4 + 4 + 32 + 32 + 32 + 9 + 9 + 9; // =171; - pub fn combine(left: &NodeData, right: &NodeData) -> NodeData { assert_eq!(left.consensus_branch_id, right.consensus_branch_id); - let mut hash_buf = [0u8; Self::MAX_SERIALIZED_SIZE * 2]; + let mut hash_buf = [0u8; MAX_NODE_DATA_SIZE * 2]; let size = { let mut cursor = ::std::io::Cursor::new(&mut hash_buf[..]); left.write(&mut cursor).expect("Writing to memory buf with enough length cannot fail; qed"); @@ -144,7 +144,7 @@ impl NodeData { } pub fn to_bytes(&self) -> Vec { - let mut buf = [0u8; Self::MAX_SERIALIZED_SIZE]; + let mut buf = [0u8; MAX_NODE_DATA_SIZE]; let pos = { let mut cursor = std::io::Cursor::new(&mut buf[..]); self.write(&mut cursor).expect("Cursor cannot fail");