Merge branch 'master' of github.com:gavofyork/ethcore-util

This commit is contained in:
Gav Wood 2015-12-04 18:06:18 +01:00
commit cfd858668f
5 changed files with 472 additions and 534 deletions

View File

@ -16,7 +16,6 @@ rand = "0.3.12"
time = "0.1.34" time = "0.1.34"
tiny-keccak = "1.0" tiny-keccak = "1.0"
rocksdb = "0.2.1" rocksdb = "0.2.1"
num = "0.1"
lazy_static = "0.1.*" lazy_static = "0.1.*"
secp256k1 = "0.5.1" secp256k1 = "0.5.1"
rust-crypto = "0.2.34" rust-crypto = "0.2.34"

View File

@ -41,7 +41,6 @@
use std::collections::{HashMap}; use std::collections::{HashMap};
use hash::*; use hash::*;
use sha3::*; use sha3::*;
use num::pow;
/// Represents bloom index in cache /// Represents bloom index in cache
/// ///
@ -119,13 +118,21 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
let mut filter = ChainFilter { let mut filter = ChainFilter {
data_source: data_source, data_source: data_source,
index_size: index_size, 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 // cache level sizes, so we do not have to calculate them all the time
for i in 0..levels { // eg. if levels == 3, index_size = 16
filter.level_sizes.push(pow(index_size, i as usize)); // 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 filter
} }

View File

@ -9,6 +9,7 @@ use rand::Rng;
use rand::os::OsRng; use rand::os::OsRng;
use bytes::BytesConvertable; use bytes::BytesConvertable;
use math::log2; use math::log2;
use uint::U256;
/// types implementing FixedHash must be also BytesConvertable /// types implementing FixedHash must be also BytesConvertable
pub trait FixedHash: Sized + 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!(H32, 4);
impl_hash!(H64, 8); impl_hash!(H64, 8);
impl_hash!(H128, 16); impl_hash!(H128, 16);

View File

@ -1,13 +1,37 @@
//! Ethcore-util library //! Ethcore-util library
//! //!
//! TODO: check reexports //! ### Rust version:
//! - beta
//! - nightly
//!
//! ### 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 rustc_serialize;
extern crate mio; extern crate mio;
extern crate rand; extern crate rand;
extern crate rocksdb; extern crate rocksdb;
extern crate tiny_keccak; extern crate tiny_keccak;
extern crate num;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use] #[macro_use]
@ -39,12 +63,3 @@ pub mod trie;
pub mod nibbleslice; pub mod nibbleslice;
//pub mod network; //pub mod network;
// reexports
pub use std::str::FromStr;
pub use hash::*;
pub use sha3::*;
pub use bytes::*;
pub use hashdb::*;
pub use memorydb::*;

File diff suppressed because it is too large Load Diff