Merge branch 'master' of github.com:gavofyork/ethcore-util
This commit is contained in:
commit
cfd858668f
@ -16,7 +16,6 @@ rand = "0.3.12"
|
||||
time = "0.1.34"
|
||||
tiny-keccak = "1.0"
|
||||
rocksdb = "0.2.1"
|
||||
num = "0.1"
|
||||
lazy_static = "0.1.*"
|
||||
secp256k1 = "0.5.1"
|
||||
rust-crypto = "0.2.34"
|
||||
|
@ -41,7 +41,6 @@
|
||||
use std::collections::{HashMap};
|
||||
use hash::*;
|
||||
use sha3::*;
|
||||
use num::pow;
|
||||
|
||||
/// Represents bloom index in cache
|
||||
///
|
||||
@ -119,13 +118,21 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
|
||||
let mut filter = ChainFilter {
|
||||
data_source: data_source,
|
||||
index_size: index_size,
|
||||
level_sizes: vec![]
|
||||
// 0 level has always a size of 1
|
||||
level_sizes: vec![1]
|
||||
};
|
||||
|
||||
// cache level sizes, so we do not have to calculate them all the time
|
||||
for i in 0..levels {
|
||||
filter.level_sizes.push(pow(index_size, i as usize));
|
||||
}
|
||||
// eg. if levels == 3, index_size = 16
|
||||
// level_sizes = [1, 16, 256]
|
||||
let additional: Vec<usize> = (1..).into_iter()
|
||||
.scan(1, |acc, _| {
|
||||
*acc = *acc * index_size;
|
||||
Some(*acc)
|
||||
})
|
||||
.take(levels as usize - 1)
|
||||
.collect();
|
||||
filter.level_sizes.extend(additional);
|
||||
|
||||
filter
|
||||
}
|
||||
|
15
src/hash.rs
15
src/hash.rs
@ -9,6 +9,7 @@ use rand::Rng;
|
||||
use rand::os::OsRng;
|
||||
use bytes::BytesConvertable;
|
||||
use math::log2;
|
||||
use uint::U256;
|
||||
|
||||
/// types implementing FixedHash must be also BytesConvertable
|
||||
pub trait FixedHash: Sized + BytesConvertable {
|
||||
@ -307,6 +308,16 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a U256> for H256 {
|
||||
fn from(value: &'a U256) -> H256 {
|
||||
unsafe {
|
||||
let mut ret: H256 = ::std::mem::uninitialized();
|
||||
value.to_bytes(&mut ret);
|
||||
ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_hash!(H32, 4);
|
||||
impl_hash!(H64, 8);
|
||||
impl_hash!(H128, 16);
|
||||
@ -350,7 +361,7 @@ mod tests {
|
||||
#[test]
|
||||
fn shift_bloom() {
|
||||
use sha3::Hashable;
|
||||
|
||||
|
||||
let bloom = H2048::from_str("00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||
let address = Address::from_str("ef2d6d194084c2de36e0dabfce45d046b37d1106").unwrap();
|
||||
let topic = H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap();
|
||||
@ -362,7 +373,7 @@ mod tests {
|
||||
my_bloom.shift_bloom(&address.sha3());
|
||||
assert!(my_bloom.contains_bloom(&address.sha3()));
|
||||
assert!(!my_bloom.contains_bloom(&topic.sha3()));
|
||||
|
||||
|
||||
my_bloom.shift_bloom(&topic.sha3());
|
||||
assert_eq!(my_bloom, bloom);
|
||||
assert!(my_bloom.contains_bloom(&address.sha3()));
|
||||
|
37
src/lib.rs
37
src/lib.rs
@ -1,13 +1,37 @@
|
||||
//! Ethcore-util library
|
||||
//!
|
||||
//! ### Rust version:
|
||||
//! - beta
|
||||
//! - nightly
|
||||
//!
|
||||
//! TODO: check reexports
|
||||
//! ### Supported platforms:
|
||||
//! - OSX
|
||||
//! - Linux
|
||||
//!
|
||||
//! ### Dependencies:
|
||||
//! - RocksDB 3.13
|
||||
//!
|
||||
//! ### Dependencies Installation:
|
||||
//!
|
||||
//! - OSX:
|
||||
//!
|
||||
//! ```bash
|
||||
//! brew install rocksdb
|
||||
//! ```
|
||||
//!
|
||||
//! - From source:
|
||||
//!
|
||||
//! ```bash
|
||||
//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz
|
||||
//! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib
|
||||
//! sudo make install
|
||||
//! ```
|
||||
|
||||
extern crate rustc_serialize;
|
||||
extern crate mio;
|
||||
extern crate rand;
|
||||
extern crate rocksdb;
|
||||
extern crate tiny_keccak;
|
||||
extern crate num;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
@ -39,12 +63,3 @@ pub mod trie;
|
||||
pub mod nibbleslice;
|
||||
|
||||
//pub mod network;
|
||||
|
||||
// reexports
|
||||
pub use std::str::FromStr;
|
||||
pub use hash::*;
|
||||
pub use sha3::*;
|
||||
pub use bytes::*;
|
||||
pub use hashdb::*;
|
||||
pub use memorydb::*;
|
||||
|
||||
|
936
src/uint.rs
936
src/uint.rs
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user