From c1280117f567bde495771ab97c0815b6bcf335dd Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 17 May 2024 23:00:12 +1000 Subject: [PATCH] Begin stable container impl --- Cargo.toml | 6 +++--- src/bitfield.rs | 14 ++++++++++++++ src/fixed_vector.rs | 1 + src/tree_hash.rs | 5 ++++- src/variable_list.rs | 1 + 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b311f6..86cf94e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,8 @@ keywords = ["ethereum"] categories = ["cryptography::cryptocurrencies"] [dependencies] -tree_hash = "0.5.0" -ethereum_ssz = "0.5.0" +tree_hash = { git = "https://github.com/macladson/tree_hash", branch = "stable-container" } +ethereum_ssz = { git = "https://github.com/macladson/ethereum_ssz", branch = "stable-container" } ethereum_serde_utils = "0.5.0" serde = "1.0.0" serde_derive = "1.0.0" @@ -24,4 +24,4 @@ itertools = "0.10.0" [dev-dependencies] serde_json = "1.0.0" -tree_hash_derive = "0.5.0" +tree_hash_derive = { git = "https://github.com/macladson/tree_hash", branch = "stable-container" } diff --git a/src/bitfield.rs b/src/bitfield.rs index d090833..7191207 100644 --- a/src/bitfield.rs +++ b/src/bitfield.rs @@ -316,6 +316,20 @@ impl Bitfield> { } } +impl std::fmt::Display for Bitfield> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut field: String = "".to_string(); + for i in self.iter() { + if i { + field.push('1') + } else { + field.push('0') + } + } + write!(f, "{field}") + } +} + impl Default for Bitfield> { fn default() -> Self { Self::new() diff --git a/src/fixed_vector.rs b/src/fixed_vector.rs index bfabac6..b68f6d0 100644 --- a/src/fixed_vector.rs +++ b/src/fixed_vector.rs @@ -435,6 +435,7 @@ mod test { } #[derive(Clone, Copy, TreeHash, Default)] + #[tree_hash(struct_behaviour = "container")] struct A { a: u32, b: u32, diff --git a/src/tree_hash.rs b/src/tree_hash.rs index e08c1d6..78a731c 100644 --- a/src/tree_hash.rs +++ b/src/tree_hash.rs @@ -24,7 +24,10 @@ where .finish() .expect("ssz_types variable vec should not have a remaining buffer") } - TreeHashType::Container | TreeHashType::List | TreeHashType::Vector => { + TreeHashType::Container + | TreeHashType::StableContainer + | TreeHashType::List + | TreeHashType::Vector => { let mut hasher = MerkleHasher::with_leaves(N::to_usize()); for item in vec { diff --git a/src/variable_list.rs b/src/variable_list.rs index 4ffd0a1..beac7d1 100644 --- a/src/variable_list.rs +++ b/src/variable_list.rs @@ -435,6 +435,7 @@ mod test { } #[derive(Clone, Copy, TreeHash, Default)] + #[tree_hash(struct_behaviour = "container")] struct A { a: u32, b: u32,