Merge pull request #60 from paritytech/update-fixed-hash-and-uint
Update fixed hash and uint
This commit is contained in:
commit
9a698b8272
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ethbloom"
|
name = "ethbloom"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
description = "Ethereum bloom filter"
|
description = "Ethereum bloom filter"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -10,8 +10,8 @@ repository = "https://github.com/paritytech/primitives"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tiny-keccak = "1.4"
|
tiny-keccak = "1.4"
|
||||||
crunchy = { version = "0.1.6", features = ["limit_256"] }
|
crunchy = { version = "0.2.1", default-features = false, features = ["limit_256"] }
|
||||||
fixed-hash = { version = "0.2", default_features = false }
|
fixed-hash = { version = "0.3", default_features = false }
|
||||||
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ rand = { version = "0.4" }
|
||||||
hex-literal = "0.1.1"
|
hex-literal = "0.1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"]
|
default = ["std", "heapsize", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"]
|
||||||
std = ["fixed-hash/std"]
|
std = ["fixed-hash/std", "crunchy/std"]
|
||||||
heapsizeof = ["fixed-hash/heapsizeof"]
|
heapsize = ["fixed-hash/heapsize"]
|
||||||
serialize = ["std", "ethereum-types-serialize", "serde"]
|
serialize = ["std", "ethereum-types-serialize", "serde"]
|
||||||
|
|
|
@ -11,7 +11,25 @@ use tiny_keccak::keccak256;
|
||||||
use ethbloom::{Bloom, Input};
|
use ethbloom::{Bloom, Input};
|
||||||
|
|
||||||
fn test_bloom() -> Bloom {
|
fn test_bloom() -> Bloom {
|
||||||
"00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into()
|
use std::str::FromStr;
|
||||||
|
Bloom::from_str(
|
||||||
|
"00000000000000000000000000000000\
|
||||||
|
00000000100000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000002020000000000000000000000\
|
||||||
|
00000000000000000000000800000000\
|
||||||
|
10000000000000000000000000000000\
|
||||||
|
00000000000000000000001000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000"
|
||||||
|
).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_topic() -> Vec<u8> {
|
fn test_topic() -> Vec<u8> {
|
||||||
|
|
|
@ -5,7 +5,25 @@
|
||||||
//! use ethbloom::{Bloom, Input};
|
//! use ethbloom::{Bloom, Input};
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
|
//! use std::str::FromStr;
|
||||||
|
//! let bloom = Bloom::from_str(
|
||||||
|
//! "00000000000000000000000000000000\
|
||||||
|
//! 00000000100000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000002020000000000000000000000\
|
||||||
|
//! 00000000000000000000000800000000\
|
||||||
|
//! 10000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000001000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000\
|
||||||
|
//! 00000000000000000000000000000000"
|
||||||
|
//! ).unwrap();
|
||||||
//! let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
//! let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
||||||
//! let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc");
|
//! let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc");
|
||||||
//!
|
//!
|
||||||
|
@ -60,7 +78,10 @@ use core::str;
|
||||||
const BLOOM_BITS: u32 = 3;
|
const BLOOM_BITS: u32 = 3;
|
||||||
const BLOOM_SIZE: usize = 256;
|
const BLOOM_SIZE: usize = 256;
|
||||||
|
|
||||||
construct_hash!(Bloom, BLOOM_SIZE);
|
construct_fixed_hash!{
|
||||||
|
/// Bloom hash type with 256 bytes (2048 bits) size.
|
||||||
|
pub struct Bloom(BLOOM_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns log2.
|
/// Returns log2.
|
||||||
fn log2(x: usize) -> u32 {
|
fn log2(x: usize) -> u32 {
|
||||||
|
@ -257,11 +278,29 @@ impl<'de> Deserialize<'de> for Bloom {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {Bloom, Input};
|
use super::{Bloom, Input};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
|
use std::str::FromStr;
|
||||||
|
let bloom = Bloom::from_str(
|
||||||
|
"00000000000000000000000000000000\
|
||||||
|
00000000100000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000002020000000000000000000000\
|
||||||
|
00000000000000000000000800000000\
|
||||||
|
10000000000000000000000000000000\
|
||||||
|
00000000000000000000001000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000\
|
||||||
|
00000000000000000000000000000000"
|
||||||
|
).unwrap();
|
||||||
let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
||||||
let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc");
|
let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc");
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ethereum-types"
|
name = "ethereum-types"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
homepage = "https://github.com/paritytech/primitives"
|
homepage = "https://github.com/paritytech/primitives"
|
||||||
description = "Ethereum types"
|
description = "Ethereum types"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crunchy = "0.1"
|
crunchy = { version = "0.2.1", default-features = false }
|
||||||
ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false }
|
ethbloom = { path = "../ethbloom", version = "0.6", default-features = false }
|
||||||
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
||||||
fixed-hash = { version = "0.2", default_features = false }
|
fixed-hash = { version = "0.3", default_features = false }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
uint = { version = "0.4", default_features = false }
|
uint = { version = "0.5", default_features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "heapsizeof", "serialize"]
|
default = ["std", "heapsize", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex"]
|
||||||
std = ["uint/std", "fixed-hash/std", "ethbloom/std"]
|
std = ["uint/std", "fixed-hash/std", "ethbloom/std", "crunchy/std"]
|
||||||
heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsizeof", "ethbloom/heapsizeof"]
|
heapsize = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsize"]
|
||||||
serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"]
|
serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use {U64, U128, U256, U512};
|
use crate::{U64, U128, U256, U512};
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||||
|
@ -31,16 +31,16 @@ macro_rules! impl_uint_conversions {
|
||||||
($hash: ident, $uint: ident) => {
|
($hash: ident, $uint: ident) => {
|
||||||
impl From<$uint> for $hash {
|
impl From<$uint> for $hash {
|
||||||
fn from(value: $uint) -> Self {
|
fn from(value: $uint) -> Self {
|
||||||
let mut ret = $hash::new();
|
let mut ret = $hash::zero();
|
||||||
value.to_big_endian(&mut ret);
|
value.to_big_endian(ret.as_bytes_mut());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a $uint> for $hash {
|
impl<'a> From<&'a $uint> for $hash {
|
||||||
fn from(value: &'a $uint) -> Self {
|
fn from(value: &'a $uint) -> Self {
|
||||||
let mut ret = $hash::new();
|
let mut ret = $hash::zero();
|
||||||
value.to_big_endian(&mut ret);
|
value.to_big_endian(ret.as_bytes_mut());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,54 +68,48 @@ impl_serde!(H264, 33);
|
||||||
impl_serde!(H512, 64);
|
impl_serde!(H512, 64);
|
||||||
impl_serde!(H520, 65);
|
impl_serde!(H520, 65);
|
||||||
|
|
||||||
construct_hash!(H32, 4);
|
construct_fixed_hash!{ pub struct H32(4); }
|
||||||
construct_hash!(H64, 8);
|
construct_fixed_hash!{ pub struct H64(8); }
|
||||||
construct_hash!(H128, 16);
|
construct_fixed_hash!{ pub struct H128(16); }
|
||||||
construct_hash!(H160, 20);
|
construct_fixed_hash!{ pub struct H160(20); }
|
||||||
construct_hash!(H256, 32);
|
construct_fixed_hash!{ pub struct H256(32); }
|
||||||
construct_hash!(H264, 33);
|
construct_fixed_hash!{ pub struct H264(33); }
|
||||||
construct_hash!(H512, 64);
|
construct_fixed_hash!{ pub struct H512(64); }
|
||||||
construct_hash!(H520, 65);
|
construct_fixed_hash!{ pub struct H520(65); }
|
||||||
|
|
||||||
impl_uint_conversions!(H64, U64);
|
impl_uint_conversions!(H64, U64);
|
||||||
impl_uint_conversions!(H128, U128);
|
impl_uint_conversions!(H128, U128);
|
||||||
impl_uint_conversions!(H256, U256);
|
impl_uint_conversions!(H256, U256);
|
||||||
impl_uint_conversions!(H512, U512);
|
impl_uint_conversions!(H512, U512);
|
||||||
|
|
||||||
#[deprecated]
|
|
||||||
impl From<H256> for H160 {
|
|
||||||
fn from(value: H256) -> H160 {
|
|
||||||
let mut ret = H160::new();
|
|
||||||
ret.0.copy_from_slice(&value[12..32]);
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated]
|
|
||||||
impl From<H256> for H64 {
|
|
||||||
fn from(value: H256) -> H64 {
|
|
||||||
let mut ret = H64::new();
|
|
||||||
ret.0.copy_from_slice(&value[20..28]);
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<H160> for H256 {
|
impl From<H160> for H256 {
|
||||||
fn from(value: H160) -> H256 {
|
fn from(value: H160) -> H256 {
|
||||||
let mut ret = H256::new();
|
let mut ret = H256::zero();
|
||||||
ret.0[12..32].copy_from_slice(&value);
|
ret.0[12..32].copy_from_slice(value.as_bytes());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a H160> for H256 {
|
impl<'a> From<&'a H160> for H256 {
|
||||||
fn from(value: &'a H160) -> H256 {
|
fn from(value: &'a H160) -> H256 {
|
||||||
let mut ret = H256::new();
|
let mut ret = H256::zero();
|
||||||
ret.0[12..32].copy_from_slice(value);
|
ret.0[12..32].copy_from_slice(value.as_bytes());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<u64> for H160 {
|
||||||
|
fn from(val: u64) -> Self {
|
||||||
|
H160::from_low_u64_be(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u64> for H256 {
|
||||||
|
fn from(val: u64) -> Self {
|
||||||
|
H256::from_low_u64_be(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{H160, H256};
|
use super::{H160, H256};
|
||||||
|
|
|
@ -24,7 +24,6 @@ mod uint;
|
||||||
pub use uint::{U64, U128, U256, U512};
|
pub use uint::{U64, U128, U256, U512};
|
||||||
pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520};
|
pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520};
|
||||||
pub use ethbloom::{Bloom, BloomRef, Input as BloomInput};
|
pub use ethbloom::{Bloom, BloomRef, Input as BloomInput};
|
||||||
pub use fixed_hash::clean_0x;
|
|
||||||
|
|
||||||
pub type Address = H160;
|
pub type Address = H160;
|
||||||
pub type Secret = H256;
|
pub type Secret = H256;
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl From<U512> for U256 {
|
||||||
fn from(value: U512) -> U256 {
|
fn from(value: U512) -> U256 {
|
||||||
let U512(ref arr) = value;
|
let U512(ref arr) = value;
|
||||||
if arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
if arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
||||||
panic!("Overflow");
|
panic!("From<U512> for U256: encountered overflow")
|
||||||
}
|
}
|
||||||
let mut ret = [0; 4];
|
let mut ret = [0; 4];
|
||||||
ret[0] = arr[0];
|
ret[0] = arr[0];
|
||||||
|
@ -89,7 +89,7 @@ impl<'a> From<&'a U512> for U256 {
|
||||||
fn from(value: &'a U512) -> U256 {
|
fn from(value: &'a U512) -> U256 {
|
||||||
let U512(ref arr) = *value;
|
let U512(ref arr) = *value;
|
||||||
if arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
if arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
||||||
panic!("Overflow");
|
panic!("From<&U512> for U256: encountered overflow")
|
||||||
}
|
}
|
||||||
let mut ret = [0; 4];
|
let mut ret = [0; 4];
|
||||||
ret[0] = arr[0];
|
ret[0] = arr[0];
|
||||||
|
@ -104,7 +104,7 @@ impl From<U256> for U128 {
|
||||||
fn from(value: U256) -> U128 {
|
fn from(value: U256) -> U128 {
|
||||||
let U256(ref arr) = value;
|
let U256(ref arr) = value;
|
||||||
if arr[2] | arr[3] != 0 {
|
if arr[2] | arr[3] != 0 {
|
||||||
panic!("Overflow");
|
panic!("From<U256> for U128: encountered overflow")
|
||||||
}
|
}
|
||||||
let mut ret = [0; 2];
|
let mut ret = [0; 2];
|
||||||
ret[0] = arr[0];
|
ret[0] = arr[0];
|
||||||
|
@ -117,7 +117,7 @@ impl From<U512> for U128 {
|
||||||
fn from(value: U512) -> U128 {
|
fn from(value: U512) -> U128 {
|
||||||
let U512(ref arr) = value;
|
let U512(ref arr) = value;
|
||||||
if arr[2] | arr[3] | arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
if arr[2] | arr[3] | arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
||||||
panic!("Overflow");
|
panic!("From<U512> for U128: encountered overflow")
|
||||||
}
|
}
|
||||||
let mut ret = [0; 2];
|
let mut ret = [0; 2];
|
||||||
ret[0] = arr[0];
|
ret[0] = arr[0];
|
||||||
|
|
|
@ -9,4 +9,7 @@ license = "MIT"
|
||||||
libc = { version = "0.2", default-features = false }
|
libc = { version = "0.2", default-features = false }
|
||||||
ethereum-types = { path = "../ethereum-types", default-features = false }
|
ethereum-types = { path = "../ethereum-types", default-features = false }
|
||||||
ethbloom = { path = "../ethbloom", default-features = false }
|
ethbloom = { path = "../ethbloom", default-features = false }
|
||||||
fixed-hash = { version = "0.2", default-features = false }
|
fixed-hash = { version = "0.3", default-features = false }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["fixed-hash/byteorder"]
|
||||||
|
|
|
@ -6,8 +6,6 @@ extern crate ethereum_types;
|
||||||
extern crate ethbloom;
|
extern crate ethbloom;
|
||||||
extern crate fixed_hash;
|
extern crate fixed_hash;
|
||||||
|
|
||||||
use ethereum_types::{Address, Public, Secret, Signature};
|
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
0
|
0
|
||||||
|
|
Loading…
Reference in New Issue