From f78004a8cc807282bb97b1c53257b1c561d13a67 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 5 Nov 2018 17:03:12 +0100 Subject: [PATCH 01/29] Update ethbloom and ethereum-types to new `fixed-hash` version `0.3.0-beta` --- ethbloom/Cargo.toml | 7 ++-- ethbloom/benches/bloom.rs | 20 +++++++++++- ethbloom/src/lib.rs | 47 ++++++++++++++++++++++++--- ethereum-types/Cargo.toml | 6 ++-- ethereum-types/src/hash.rs | 66 ++++++++++++++++++++------------------ ethereum-types/src/lib.rs | 9 +++++- no-std-tests/Cargo.toml | 2 +- no-std-tests/src/main.rs | 2 -- 8 files changed, 112 insertions(+), 47 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index a3a421d..c3be170 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -11,7 +11,8 @@ repository = "https://github.com/paritytech/primitives" [dependencies] tiny-keccak = "1.4" crunchy = { version = "0.1.6", features = ["limit_256"] } -fixed-hash = { version = "0.2", default_features = false } +rustc-hex = { version = "2.0" } +fixed-hash = { version = "0.3.0-beta.2", default_features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } serde = { version = "1.0", optional = true } @@ -20,7 +21,7 @@ rand = { version = "0.4" } hex-literal = "0.1.1" [features] -default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"] +default = ["std", "heapsizeof", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"] std = ["fixed-hash/std"] -heapsizeof = ["fixed-hash/heapsizeof"] +heapsizeof = ["fixed-hash/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde"] diff --git a/ethbloom/benches/bloom.rs b/ethbloom/benches/bloom.rs index 674eeab..7c998e9 100644 --- a/ethbloom/benches/bloom.rs +++ b/ethbloom/benches/bloom.rs @@ -11,7 +11,25 @@ use tiny_keccak::keccak256; use ethbloom::{Bloom, Input}; 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 { diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 462551c..cfd5ab6 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -5,7 +5,25 @@ //! use ethbloom::{Bloom, Input}; //! //! 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 topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); //! @@ -60,7 +78,10 @@ use core::str; const BLOOM_BITS: u32 = 3; 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. fn log2(x: usize) -> u32 { @@ -257,11 +278,29 @@ impl<'de> Deserialize<'de> for Bloom { #[cfg(test)] mod tests { - use {Bloom, Input}; + use super::{Bloom, Input}; #[test] 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 topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index ccf2b7a..d713bd9 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -10,7 +10,7 @@ description = "Ethereum types" crunchy = "0.1" ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } -fixed-hash = { version = "0.2", default_features = false } +fixed-hash = { version = "0.3.0-beta.2", default_features = false } serde = { version = "1.0", optional = true } uint = { version = "0.4", default_features = false } @@ -18,7 +18,7 @@ uint = { version = "0.4", default_features = false } serde_json = "1.0" [features] -default = ["std", "heapsizeof", "serialize"] +default = ["std", "heapsizeof", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex"] std = ["uint/std", "fixed-hash/std", "ethbloom/std"] -heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsizeof", "ethbloom/heapsizeof"] +heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsize", "ethbloom/heapsizeof"] serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"] diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 64e436d..4e801eb 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -31,16 +31,16 @@ macro_rules! impl_uint_conversions { ($hash: ident, $uint: ident) => { impl From<$uint> for $hash { fn from(value: $uint) -> Self { - let mut ret = $hash::new(); - value.to_big_endian(&mut ret); + let mut ret = $hash::zero(); + value.to_big_endian(ret.as_bytes_mut()); ret } } impl<'a> From<&'a $uint> for $hash { fn from(value: &'a $uint) -> Self { - let mut ret = $hash::new(); - value.to_big_endian(&mut ret); + let mut ret = $hash::zero(); + value.to_big_endian(ret.as_bytes_mut()); ret } } @@ -68,14 +68,14 @@ impl_serde!(H264, 33); impl_serde!(H512, 64); impl_serde!(H520, 65); -construct_hash!(H32, 4); -construct_hash!(H64, 8); -construct_hash!(H128, 16); -construct_hash!(H160, 20); -construct_hash!(H256, 32); -construct_hash!(H264, 33); -construct_hash!(H512, 64); -construct_hash!(H520, 65); +construct_fixed_hash!{ pub struct H32(4); } +construct_fixed_hash!{ pub struct H64(8); } +construct_fixed_hash!{ pub struct H128(16); } +construct_fixed_hash!{ pub struct H160(20); } +construct_fixed_hash!{ pub struct H256(32); } +construct_fixed_hash!{ pub struct H264(33); } +construct_fixed_hash!{ pub struct H512(64); } +construct_fixed_hash!{ pub struct H520(65); } impl_uint_conversions!(H64, U64); impl_uint_conversions!(H128, U128); @@ -85,7 +85,7 @@ impl_uint_conversions!(H512, U512); #[deprecated] impl From for H160 { fn from(value: H256) -> H160 { - let mut ret = H160::new(); + let mut ret = H160::zero(); ret.0.copy_from_slice(&value[12..32]); ret } @@ -94,7 +94,7 @@ impl From for H160 { #[deprecated] impl From for H64 { fn from(value: H256) -> H64 { - let mut ret = H64::new(); + let mut ret = H64::zero(); ret.0.copy_from_slice(&value[20..28]); ret } @@ -102,16 +102,16 @@ impl From for H64 { impl From for H256 { fn from(value: H160) -> H256 { - let mut ret = H256::new(); - ret.0[12..32].copy_from_slice(&value); + let mut ret = H256::zero(); + ret.0[12..32].copy_from_slice(value.as_bytes()); ret } } impl<'a> From<&'a H160> for H256 { fn from(value: &'a H160) -> H256 { - let mut ret = H256::new(); - ret.0[12..32].copy_from_slice(value); + let mut ret = H256::zero(); + ret.0[12..32].copy_from_slice(value.as_bytes()); ret } } @@ -121,16 +121,17 @@ mod tests { use super::{H160, H256}; use serde_json as ser; + // #[cfg(feature = "fixed-hash/byteorder-support")] #[test] fn test_serialize_h160() { let tests = vec![ - (H160::from(0), "0x0000000000000000000000000000000000000000"), - (H160::from(2), "0x0000000000000000000000000000000000000002"), - (H160::from(15), "0x000000000000000000000000000000000000000f"), - (H160::from(16), "0x0000000000000000000000000000000000000010"), - (H160::from(1_000), "0x00000000000000000000000000000000000003e8"), - (H160::from(100_000), "0x00000000000000000000000000000000000186a0"), - (H160::from(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), + (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), + (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), + (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), + (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), + (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), + (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), + (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { @@ -139,16 +140,17 @@ mod tests { } } + #[cfg(feature = "byteorder-support")] #[test] fn test_serialize_h256() { let tests = vec![ - (H256::from(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), - (H256::from(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), - (H256::from(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), - (H256::from(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), - (H256::from(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), - (H256::from(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), - (H256::from(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), + (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), + (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), + (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), + (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), + (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), + (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), + (H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index 04be076..98552bb 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -24,7 +24,14 @@ mod uint; pub use uint::{U64, U128, U256, U512}; pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; -pub use fixed_hash::clean_0x; + +/// Cuts away `"0x"` prefix on the given `input` if existing and returns the result. +pub fn clean_0x(input: &str) -> &str { + if input.starts_with("0x") { + return &input[2..] + } + input +} pub type Address = H160; pub type Secret = H256; diff --git a/no-std-tests/Cargo.toml b/no-std-tests/Cargo.toml index 8cdd482..cbe6765 100644 --- a/no-std-tests/Cargo.toml +++ b/no-std-tests/Cargo.toml @@ -9,4 +9,4 @@ license = "MIT" libc = { version = "0.2", default-features = false } ethereum-types = { path = "../ethereum-types", default-features = false } ethbloom = { path = "../ethbloom", default-features = false } -fixed-hash = { version = "0.2", default-features = false } \ No newline at end of file +fixed-hash = { version = "0.3.0-beta.2", default-features = false } diff --git a/no-std-tests/src/main.rs b/no-std-tests/src/main.rs index 0fa4c3a..a5ec78d 100644 --- a/no-std-tests/src/main.rs +++ b/no-std-tests/src/main.rs @@ -6,8 +6,6 @@ extern crate ethereum_types; extern crate ethbloom; extern crate fixed_hash; -use ethereum_types::{Address, Public, Secret, Signature}; - #[start] fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 From 91c88f36890f4f07c6513c066a8d6cf1423e94aa Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 5 Nov 2018 17:06:40 +0100 Subject: [PATCH 02/29] Update `unit` to version `0.5.0-beta` --- ethereum-types/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index d713bd9..a2e2457 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -12,13 +12,13 @@ ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } fixed-hash = { version = "0.3.0-beta.2", default_features = false } serde = { version = "1.0", optional = true } -uint = { version = "0.4", default_features = false } +uint = { version = "0.5.0-beta", default_features = false } [dev-dependencies] serde_json = "1.0" [features] -default = ["std", "heapsizeof", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex"] +default = ["std", "heapsizeof", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex", "uint/common"] std = ["uint/std", "fixed-hash/std", "ethbloom/std"] -heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsize", "ethbloom/heapsizeof"] +heapsizeof = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsizeof"] serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"] From 5539e76da8b7f4009c46159ff2a325dc238266a9 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:20:08 +0100 Subject: [PATCH 03/29] [ethbloom]: Rename heapsizeof crate feature to heapsize --- ethbloom/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index c3be170..40c042b 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -23,5 +23,5 @@ hex-literal = "0.1.1" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"] std = ["fixed-hash/std"] -heapsizeof = ["fixed-hash/heapsize"] +heapsize = ["fixed-hash/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde"] From ab87602abf9ce6250ae6a0b7de3084a0d66c2331 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:20:38 +0100 Subject: [PATCH 04/29] [ethbloom] Update crunchy version 0.1.6 => 0.2.1 --- ethbloom/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 40c042b..8b847fb 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/primitives" [dependencies] tiny-keccak = "1.4" -crunchy = { version = "0.1.6", features = ["limit_256"] } +crunchy = { version = "0.2.1", default-features = false, features = ["limit_256"] } rustc-hex = { version = "2.0" } fixed-hash = { version = "0.3.0-beta.2", default_features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } @@ -22,6 +22,6 @@ hex-literal = "0.1.1" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"] -std = ["fixed-hash/std"] +std = ["fixed-hash/std", "crunchy/std"] heapsize = ["fixed-hash/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde"] From 9be7fc64974457294e12f0374e177f3032a25ea4 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:21:09 +0100 Subject: [PATCH 05/29] [ethbloom] Fix forgotten default feature "heapsizeof" => "heapsize" --- ethbloom/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 8b847fb..14d7934 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -21,7 +21,7 @@ rand = { version = "0.4" } hex-literal = "0.1.1" [features] -default = ["std", "heapsizeof", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"] +default = ["std", "heapsize", "serialize", "fixed-hash/libc", "fixed-hash/rustc-hex"] std = ["fixed-hash/std", "crunchy/std"] heapsize = ["fixed-hash/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde"] From ab3d73afdca6e9f263b70dc71de9f1376027153c Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:21:22 +0100 Subject: [PATCH 06/29] [ethbloom] Update fixed-hash 0.3.0-beta => 0.3.0 --- ethbloom/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 14d7934..6858a3d 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/paritytech/primitives" tiny-keccak = "1.4" crunchy = { version = "0.2.1", default-features = false, features = ["limit_256"] } rustc-hex = { version = "2.0" } -fixed-hash = { version = "0.3.0-beta.2", default_features = false } +fixed-hash = { version = "0.3.0", default_features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } serde = { version = "1.0", optional = true } From 491767d143cf847bdcd8b8505496e4a9f9da6f9a Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:21:38 +0100 Subject: [PATCH 07/29] [no-std-tests] Update fixed-hash 0.3.0-beta => 0.3.0 --- no-std-tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/no-std-tests/Cargo.toml b/no-std-tests/Cargo.toml index cbe6765..05d1ea1 100644 --- a/no-std-tests/Cargo.toml +++ b/no-std-tests/Cargo.toml @@ -9,4 +9,4 @@ license = "MIT" libc = { version = "0.2", default-features = false } ethereum-types = { path = "../ethereum-types", default-features = false } ethbloom = { path = "../ethbloom", default-features = false } -fixed-hash = { version = "0.3.0-beta.2", default-features = false } +fixed-hash = { version = "0.3.0", default-features = false } From 2c124b9e0778f1671c6b84d28c9337370b248da0 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:22:37 +0100 Subject: [PATCH 08/29] Rename heapsizeof crate feature to heapsize --- ethereum-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index a2e2457..bab50d4 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -20,5 +20,5 @@ serde_json = "1.0" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex", "uint/common"] std = ["uint/std", "fixed-hash/std", "ethbloom/std"] -heapsizeof = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsizeof"] +heapsize = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"] From c2e5edbec6c6c8bbf1e3f7e5580f66a8634531cf Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:23:07 +0100 Subject: [PATCH 09/29] [ethereum-types] Update uint 0.5.0-beta => 0.5.0 --- ethereum-types/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index bab50d4..b026e1d 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -12,13 +12,13 @@ ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } fixed-hash = { version = "0.3.0-beta.2", default_features = false } serde = { version = "1.0", optional = true } -uint = { version = "0.5.0-beta", default_features = false } +uint = { version = "0.5.0", default_features = false } [dev-dependencies] serde_json = "1.0" [features] -default = ["std", "heapsizeof", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex", "uint/common"] +default = ["std", "heapsize", "serialize", "fixed-hash/byteorder", "fixed-hash/rustc-hex"] std = ["uint/std", "fixed-hash/std", "ethbloom/std"] heapsize = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"] From 1cdfea3dd822d94f527e41a515c8d5d03e3678d4 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:23:44 +0100 Subject: [PATCH 10/29] [ethereum-types] Update crunchy 0.1 => 0.2.1 --- ethereum-types/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index b026e1d..9069dab 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://github.com/paritytech/primitives" description = "Ethereum types" [dependencies] -crunchy = "0.1" +crunchy = { version = "0.2.1", default-features = false } ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } fixed-hash = { version = "0.3.0-beta.2", default_features = false } @@ -19,6 +19,6 @@ serde_json = "1.0" [features] 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"] heapsize = ["uint/heapsize", "fixed-hash/heapsize", "ethbloom/heapsize"] serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"] From eca7e3b8b066e62b478e9e0df8f031ab0ee41127 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:23:59 +0100 Subject: [PATCH 11/29] [ethereum-types] Update fixed-hash 0.3.0-beta => 0.3.0 --- ethereum-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 9069dab..db0ed04 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -10,7 +10,7 @@ description = "Ethereum types" crunchy = { version = "0.2.1", default-features = false } ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } -fixed-hash = { version = "0.3.0-beta.2", default_features = false } +fixed-hash = { version = "0.3.0", default_features = false } serde = { version = "1.0", optional = true } uint = { version = "0.5.0", default_features = false } From de0a759f4a904ce1a044435a0c2807c9c52ec43a Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:24:28 +0100 Subject: [PATCH 12/29] [ethereum-types] Remove clean_0x function --- ethereum-types/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index 98552bb..e53964d 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -25,14 +25,6 @@ pub use uint::{U64, U128, U256, U512}; pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; -/// Cuts away `"0x"` prefix on the given `input` if existing and returns the result. -pub fn clean_0x(input: &str) -> &str { - if input.starts_with("0x") { - return &input[2..] - } - input -} - pub type Address = H160; pub type Secret = H256; pub type Public = H512; From 071b5362735891efa5c87dba1c7827ae5672311d Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:25:01 +0100 Subject: [PATCH 13/29] [ethereum-types] Remove U64 definition --- ethereum-types/src/lib.rs | 2 +- ethereum-types/src/uint.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index e53964d..e8b7b81 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -21,7 +21,7 @@ extern crate serde_json; mod hash; mod uint; -pub use uint::{U64, U128, U256, U512}; +pub use uint::{U128, U256, U512}; pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index a2de9ff..2cc8ee1 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -27,12 +27,10 @@ macro_rules! impl_serde { } } -construct_uint!(U64, 1); construct_uint!(U128, 2); construct_uint!(U256, 4); construct_uint!(U512, 8); -impl_serde!(U64, 1); impl_serde!(U128, 2); impl_serde!(U256, 4); impl_serde!(U512, 8); From 6b57ca0c534a9da74f6e413cc5765183e060020d Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:25:48 +0100 Subject: [PATCH 14/29] [ethereum-types] Add From impls for H160 and H256 --- ethereum-types/src/hash.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 4e801eb..f4ae7d0 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -116,6 +116,18 @@ impl<'a> From<&'a H160> for H256 { } } +impl From for H160 { + fn from(val: u64) -> Self { + H160::from_low_u64_be(val) + } +} + +impl From for H256 { + fn from(val: u64) -> Self { + H256::from_low_u64_be(val) + } +} + #[cfg(test)] mod tests { use super::{H160, H256}; From f7895618a9f3cbccf41913abc3a090d395d6ce98 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:26:19 +0100 Subject: [PATCH 15/29] [ethereum-types] Use new From impls in tests --- ethereum-types/src/hash.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index f4ae7d0..c5980ff 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -137,13 +137,13 @@ mod tests { #[test] fn test_serialize_h160() { let tests = vec![ - (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), - (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), - (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), - (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), - (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), - (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), - (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), + (H160::from(0), "0x0000000000000000000000000000000000000000"), + (H160::from(2), "0x0000000000000000000000000000000000000002"), + (H160::from(15), "0x000000000000000000000000000000000000000f"), + (H160::from(16), "0x0000000000000000000000000000000000000010"), + (H160::from(1_000), "0x00000000000000000000000000000000000003e8"), + (H160::from(100_000), "0x00000000000000000000000000000000000186a0"), + (H160::from(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { @@ -156,13 +156,13 @@ mod tests { #[test] fn test_serialize_h256() { let tests = vec![ - (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), - (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), - (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), - (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), - (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), - (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), - (H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), + (H256::from(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), + (H256::from(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), + (H256::from(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), + (H256::from(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), + (H256::from(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), + (H256::from(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), + (H256::from(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { From d59defc7e1728ad62aa3ffaaf6ab420ed44e9ef2 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:26:32 +0100 Subject: [PATCH 16/29] [ethereum-types] Remove bad feature gate usages --- ethereum-types/src/hash.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index c5980ff..13afdec 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -133,7 +133,6 @@ mod tests { use super::{H160, H256}; use serde_json as ser; - // #[cfg(feature = "fixed-hash/byteorder-support")] #[test] fn test_serialize_h160() { let tests = vec![ @@ -152,7 +151,6 @@ mod tests { } } - #[cfg(feature = "byteorder-support")] #[test] fn test_serialize_h256() { let tests = vec![ From 4476efe5356ea5b8a1e81013aaf31f6b10c43da5 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:26:51 +0100 Subject: [PATCH 17/29] [ethereum-types] Remove deprecated From impls for H64 and H160 --- ethereum-types/src/hash.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 13afdec..76a464e 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -82,24 +82,6 @@ impl_uint_conversions!(H128, U128); impl_uint_conversions!(H256, U256); impl_uint_conversions!(H512, U512); -#[deprecated] -impl From for H160 { - fn from(value: H256) -> H160 { - let mut ret = H160::zero(); - ret.0.copy_from_slice(&value[12..32]); - ret - } -} - -#[deprecated] -impl From for H64 { - fn from(value: H256) -> H64 { - let mut ret = H64::zero(); - ret.0.copy_from_slice(&value[20..28]); - ret - } -} - impl From for H256 { fn from(value: H160) -> H256 { let mut ret = H256::zero(); From 146263d83745f6dc003bed274b417a792e5e45c8 Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:27:16 +0100 Subject: [PATCH 18/29] [ethereum-types] Improve formatting a bit --- ethereum-types/src/hash.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 76a464e..ae6aab2 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -1,14 +1,14 @@ use {U64, U128, U256, U512}; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use serde::{Serialize, Serializer, Deserialize, Deserializer}; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use ethereum_types_serialize; macro_rules! impl_serde { ($name: ident, $len: expr) => { - #[cfg(feature="serialize")] + #[cfg(feature = "serialize")] impl Serialize for $name { fn serialize(&self, serializer: S) -> Result where S: Serializer { let mut slice = [0u8; 2 + 2 * $len]; @@ -16,7 +16,7 @@ macro_rules! impl_serde { } } - #[cfg(feature="serialize")] + #[cfg(feature = "serialize")] impl<'de> Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de> { let mut bytes = [0u8; $len]; @@ -160,4 +160,4 @@ mod tests { assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); } -} \ No newline at end of file +} From 5308d515dbd9d47695371f2b9872def529f9bf5e Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:28:16 +0100 Subject: [PATCH 19/29] [ethereum-types] Remove H32, H64, H128 and H264 hash types The only remaining hash types are now: H160, H256, H512 and H520 --- ethereum-types/src/hash.rs | 12 +----------- ethereum-types/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index ae6aab2..c57b4e4 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -1,4 +1,4 @@ -use {U64, U128, U256, U512}; +use crate::{U256, U512}; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer, Deserialize, Deserializer}; @@ -59,26 +59,16 @@ macro_rules! impl_uint_conversions { } } -impl_serde!(H32, 4); -impl_serde!(H64, 8); -impl_serde!(H128, 16); impl_serde!(H160, 20); impl_serde!(H256, 32); -impl_serde!(H264, 33); impl_serde!(H512, 64); impl_serde!(H520, 65); -construct_fixed_hash!{ pub struct H32(4); } -construct_fixed_hash!{ pub struct H64(8); } -construct_fixed_hash!{ pub struct H128(16); } construct_fixed_hash!{ pub struct H160(20); } construct_fixed_hash!{ pub struct H256(32); } -construct_fixed_hash!{ pub struct H264(33); } construct_fixed_hash!{ pub struct H512(64); } construct_fixed_hash!{ pub struct H520(65); } -impl_uint_conversions!(H64, U64); -impl_uint_conversions!(H128, U128); impl_uint_conversions!(H256, U256); impl_uint_conversions!(H512, U512); diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index e8b7b81..178435d 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -22,7 +22,7 @@ mod hash; mod uint; pub use uint::{U128, U256, U512}; -pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520}; +pub use hash::{H160, H256, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; pub type Address = H160; From 0b53e91ef161915d3c37568c04f42bb519664e0c Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:28:54 +0100 Subject: [PATCH 20/29] [ethereum-types] Bump version 0.4.0 => 0.5.0 --- ethereum-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index db0ed04..5770838 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethereum-types" -version = "0.4.0" +version = "0.5.0" authors = ["Parity Technologies "] license = "MIT" homepage = "https://github.com/paritytech/primitives" From 304cc6f2310285acdaa76d4a6f09c7ebda19984d Mon Sep 17 00:00:00 2001 From: Herobird Date: Mon, 12 Nov 2018 20:29:26 +0100 Subject: [PATCH 21/29] [ethbloom] Bump version 0.5.1 => 0.6.0 --- ethbloom/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 6858a3d..e60b09c 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethbloom" -version = "0.5.1" +version = "0.6.0" authors = ["Parity Technologies "] description = "Ethereum bloom filter" license = "MIT" From 0a007d5adafda2b0713f74394bfe191927b8e036 Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:12:22 +0100 Subject: [PATCH 22/29] Update dependency versions in Cargo.toml --- ethbloom/Cargo.toml | 2 +- ethereum-types/Cargo.toml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index e60b09c..1a6d6af 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/paritytech/primitives" tiny-keccak = "1.4" crunchy = { version = "0.2.1", default-features = false, features = ["limit_256"] } rustc-hex = { version = "2.0" } -fixed-hash = { version = "0.3.0", default_features = false } +fixed-hash = { version = "0.3", default_features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } serde = { version = "1.0", optional = true } diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 5770838..8f53d7b 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -8,11 +8,11 @@ description = "Ethereum types" [dependencies] 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 } -fixed-hash = { version = "0.3.0", default_features = false } +fixed-hash = { version = "0.3", default_features = false } serde = { version = "1.0", optional = true } -uint = { version = "0.5.0", default_features = false } +uint = { version = "0.5", default_features = false } [dev-dependencies] serde_json = "1.0" From 50af083e1482b4f0e66ceb10542c54f582c5bf80 Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:15:40 +0100 Subject: [PATCH 23/29] [no-std-tests] Update dependency version of fixed-hahs --- no-std-tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/no-std-tests/Cargo.toml b/no-std-tests/Cargo.toml index 05d1ea1..dc40221 100644 --- a/no-std-tests/Cargo.toml +++ b/no-std-tests/Cargo.toml @@ -9,4 +9,4 @@ license = "MIT" libc = { version = "0.2", default-features = false } ethereum-types = { path = "../ethereum-types", default-features = false } ethbloom = { path = "../ethbloom", default-features = false } -fixed-hash = { version = "0.3.0", default-features = false } +fixed-hash = { version = "0.3", default-features = false } From eb3ba0b8f0068b424ed450e9d906ecaac9a9a259 Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:22:00 +0100 Subject: [PATCH 24/29] Revert removals of some uint and hash types --- ethereum-types/src/hash.rs | 12 +++++++++++- ethereum-types/src/lib.rs | 4 ++-- ethereum-types/src/uint.rs | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index c57b4e4..26410ae 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -1,4 +1,4 @@ -use crate::{U256, U512}; +use crate::{U64, U128, U256, U512}; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer, Deserialize, Deserializer}; @@ -59,16 +59,26 @@ macro_rules! impl_uint_conversions { } } +impl_serde!(H32, 4); +impl_serde!(H64, 8); +impl_serde!(H128, 16); impl_serde!(H160, 20); impl_serde!(H256, 32); +impl_serde!(H264, 33); impl_serde!(H512, 64); impl_serde!(H520, 65); +construct_fixed_hash!{ pub struct H32(4); } +construct_fixed_hash!{ pub struct H64(8); } +construct_fixed_hash!{ pub struct H128(16); } construct_fixed_hash!{ pub struct H160(20); } construct_fixed_hash!{ pub struct H256(32); } +construct_fixed_hash!{ pub struct H264(33); } construct_fixed_hash!{ pub struct H512(64); } construct_fixed_hash!{ pub struct H520(65); } +impl_uint_conversions!(H64, U64); +impl_uint_conversions!(H128, U128); impl_uint_conversions!(H256, U256); impl_uint_conversions!(H512, U512); diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index 178435d..e53964d 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -21,8 +21,8 @@ extern crate serde_json; mod hash; mod uint; -pub use uint::{U128, U256, U512}; -pub use hash::{H160, H256, H512, H520}; +pub use uint::{U64, U128, U256, U512}; +pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; pub type Address = H160; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 2cc8ee1..a2de9ff 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -27,10 +27,12 @@ macro_rules! impl_serde { } } +construct_uint!(U64, 1); construct_uint!(U128, 2); construct_uint!(U256, 4); construct_uint!(U512, 8); +impl_serde!(U64, 1); impl_serde!(U128, 2); impl_serde!(U256, 4); impl_serde!(U512, 8); From 972b84ca0475c852ceba2be5c8d51156126f94f6 Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:22:19 +0100 Subject: [PATCH 25/29] Improve some #[cfg(..)] formattings --- ethereum-types/src/uint.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index a2de9ff..32a862f 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -1,12 +1,12 @@ -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use serde::{Serialize, Serializer, Deserialize, Deserializer}; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use ethereum_types_serialize; macro_rules! impl_serde { ($name: ident, $len: expr) => { - #[cfg(feature="serialize")] + #[cfg(feature = "serialize")] impl Serialize for $name { fn serialize(&self, serializer: S) -> Result where S: Serializer { let mut slice = [0u8; 2 + 2 * $len * 8]; @@ -16,7 +16,7 @@ macro_rules! impl_serde { } } - #[cfg(feature="serialize")] + #[cfg(feature = "serialize")] impl<'de> Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de> { let mut bytes = [0u8; $len * 8]; From 2da14eca58c920d9f955fc081484bed278fb7c6b Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:22:36 +0100 Subject: [PATCH 26/29] Improve panic messages by overflow for some uint From impls --- ethereum-types/src/uint.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 32a862f..88aeb29 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -62,7 +62,7 @@ impl From for U256 { fn from(value: U512) -> U256 { let U512(ref arr) = value; if arr[4] | arr[5] | arr[6] | arr[7] != 0 { - panic!("Overflow"); + panic!("From for U256: encountered overflow") } let mut ret = [0; 4]; ret[0] = arr[0]; @@ -89,7 +89,7 @@ impl<'a> From<&'a U512> for U256 { fn from(value: &'a U512) -> U256 { let U512(ref arr) = *value; if arr[4] | arr[5] | arr[6] | arr[7] != 0 { - panic!("Overflow"); + panic!("From<&U512> for U256: encountered overflow") } let mut ret = [0; 4]; ret[0] = arr[0]; @@ -104,7 +104,7 @@ impl From for U128 { fn from(value: U256) -> U128 { let U256(ref arr) = value; if arr[2] | arr[3] != 0 { - panic!("Overflow"); + panic!("From for U128: encountered overflow") } let mut ret = [0; 2]; ret[0] = arr[0]; @@ -117,7 +117,7 @@ impl From for U128 { fn from(value: U512) -> U128 { let U512(ref arr) = value; if arr[2] | arr[3] | arr[4] | arr[5] | arr[6] | arr[7] != 0 { - panic!("Overflow"); + panic!("From for U128: encountered overflow") } let mut ret = [0; 2]; ret[0] = arr[0]; From f76b9a44590ff3ed3b494df2c90ac43305accf65 Mon Sep 17 00:00:00 2001 From: Herobird Date: Tue, 13 Nov 2018 11:27:50 +0100 Subject: [PATCH 27/29] Improve some formatting of #[cfg(..)] --- ethereum-types/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index e53964d..bcda15b 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -1,6 +1,6 @@ -#![cfg_attr(not(feature="std"), no_std)] +#![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature="std")] +#[cfg(feature = "std")] extern crate core; #[macro_use] extern crate crunchy; @@ -10,9 +10,9 @@ extern crate uint as uint_crate; extern crate fixed_hash; extern crate ethbloom; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] extern crate ethereum_types_serialize; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] extern crate serde; #[cfg(test)] From ff7b5c815897ba9df1f5c9b38bf8fd55fd7f7525 Mon Sep 17 00:00:00 2001 From: Herobird Date: Fri, 30 Nov 2018 17:58:36 +0100 Subject: [PATCH 28/29] [no-std-tests] Add `fixed-hash/byteorder` used feature Makes it compile again --- no-std-tests/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/no-std-tests/Cargo.toml b/no-std-tests/Cargo.toml index dc40221..2994083 100644 --- a/no-std-tests/Cargo.toml +++ b/no-std-tests/Cargo.toml @@ -10,3 +10,6 @@ libc = { version = "0.2", default-features = false } ethereum-types = { path = "../ethereum-types", default-features = false } ethbloom = { path = "../ethbloom", default-features = false } fixed-hash = { version = "0.3", default-features = false } + +[features] +default = ["fixed-hash/byteorder"] From 6db964fd5328ace9d1343bf15a8b15273ef1d068 Mon Sep 17 00:00:00 2001 From: Herobird Date: Fri, 30 Nov 2018 17:58:48 +0100 Subject: [PATCH 29/29] [ethbloom] Remove rustc-hex dependency --- ethbloom/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 1a6d6af..16de3c0 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -11,7 +11,6 @@ repository = "https://github.com/paritytech/primitives" [dependencies] tiny-keccak = "1.4" crunchy = { version = "0.2.1", default-features = false, features = ["limit_256"] } -rustc-hex = { version = "2.0" } fixed-hash = { version = "0.3", default_features = false } ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true } serde = { version = "1.0", optional = true }