From fd1eea561eefaad0282bb66aaeb3cde97f4db12e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 23 Aug 2018 15:20:10 +1000 Subject: [PATCH] Move boolean_bitfield into own crate --- Cargo.toml | 1 + boolean-bitfield/Cargo.toml | 6 +++++ boolean-bitfield/README.md | 7 ++++++ .../src/lib.rs | 23 ------------------- lighthouse/utils/mod.rs | 2 +- lighthouse/utils/types.rs | 4 +++- 6 files changed, 18 insertions(+), 25 deletions(-) create mode 100644 boolean-bitfield/Cargo.toml create mode 100644 boolean-bitfield/README.md rename lighthouse/utils/boolean_bitfield.rs => boolean-bitfield/src/lib.rs (86%) diff --git a/Cargo.toml b/Cargo.toml index b3ece7de5..ae9194004 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ authors = ["Paul Hauner "] blake2 = "^0.7.1" blake2-rfc = "0.2.18" bls = { git = "https://github.com/sigp/bls" } +boolean-bitfield = { path = "boolean-bitfield" } bytes = "" crypto-mac = "^0.6.2" clap = "2.32.0" diff --git a/boolean-bitfield/Cargo.toml b/boolean-bitfield/Cargo.toml new file mode 100644 index 000000000..6e790ea23 --- /dev/null +++ b/boolean-bitfield/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "boolean-bitfield" +version = "0.1.0" +authors = ["Paul Hauner "] + +[dependencies] diff --git a/boolean-bitfield/README.md b/boolean-bitfield/README.md new file mode 100644 index 000000000..749ccdb51 --- /dev/null +++ b/boolean-bitfield/README.md @@ -0,0 +1,7 @@ +# Boolean Bitfield + +A work-in-progress implementation of an unbounded boolean bitfield. + +Based upon a `Vec` + +Documentation TBC... diff --git a/lighthouse/utils/boolean_bitfield.rs b/boolean-bitfield/src/lib.rs similarity index 86% rename from lighthouse/utils/boolean_bitfield.rs rename to boolean-bitfield/src/lib.rs index bb7fa79bc..da789c476 100644 --- a/lighthouse/utils/boolean_bitfield.rs +++ b/boolean-bitfield/src/lib.rs @@ -6,9 +6,7 @@ * A future implementation should be more efficient, * this is just to get the job done for now. */ -extern crate rlp; use std::cmp::max; -use self::rlp::{ RlpStream, Encodable }; #[derive(Eq)] pub struct BooleanBitfield{ @@ -100,17 +98,6 @@ impl Clone for BooleanBitfield { } -impl Encodable for BooleanBitfield { - // TODO: ensure this is a sensible method of encoding - // the bitfield. Currently, it is treated as a list of - // bytes not as a string. I do not have any guidance as - // to which method is correct -- don't follow my lead - // without seeking authoritative advice. - fn rlp_append(&self, s: &mut RlpStream) { - s.append(&self.to_be_vec()); - } -} - #[cfg(test)] mod tests { use super::*; @@ -172,16 +159,6 @@ mod tests { } } - #[test] - fn test_bitfield_rlp_serialization() { - let mut b = BooleanBitfield::new(); - b.set_bit(&15, &true); - let e = rlp::encode(&b); - assert_eq!(e[0], 130); - assert_eq!(e[1], 128); - assert_eq!(e[2], 0); - } - #[test] fn test_bitfield_num_true_bits() { let mut b = BooleanBitfield::new(); diff --git a/lighthouse/utils/mod.rs b/lighthouse/utils/mod.rs index 833dc2507..d116422be 100644 --- a/lighthouse/utils/mod.rs +++ b/lighthouse/utils/mod.rs @@ -1,9 +1,9 @@ extern crate ethereum_types; extern crate blake2; extern crate crypto_mac; +extern crate boolean_bitfield; pub mod types; pub mod bls; pub mod test_helpers; -pub mod boolean_bitfield; pub mod logging; diff --git a/lighthouse/utils/types.rs b/lighthouse/utils/types.rs index 4ff6ad2ad..8e9bf2006 100644 --- a/lighthouse/utils/types.rs +++ b/lighthouse/utils/types.rs @@ -1,5 +1,7 @@ +extern crate boolean_bitfield; + use super::ethereum_types::{ H256, H160 }; -use super::boolean_bitfield::BooleanBitfield; +use self::boolean_bitfield::BooleanBitfield; pub use super::blake2::Blake2s; pub use super::ethereum_types::U256;