Move boolean_bitfield into own crate

This commit is contained in:
Paul Hauner 2018-08-23 15:20:10 +10:00
parent 9808d5c209
commit fd1eea561e
6 changed files with 18 additions and 25 deletions

View File

@ -8,6 +8,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
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"

View File

@ -0,0 +1,6 @@
[package]
name = "boolean-bitfield"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
[dependencies]

View File

@ -0,0 +1,7 @@
# Boolean Bitfield
A work-in-progress implementation of an unbounded boolean bitfield.
Based upon a `Vec<u8>`
Documentation TBC...

View File

@ -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();

View File

@ -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;

View File

@ -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;