diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index a8cf6262a..8b0f3f867 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "ethereum-types" +# TODO: needs to be `0.6` but diff PR version = "0.5.3-beta.2" authors = ["Parity Technologies "] license = "MIT" @@ -10,9 +11,9 @@ description = "Ethereum types" ethbloom = { path = "../ethbloom", version = "0.6", default-features = false } fixed-hash = { path = "../fixed-hash", version = "0.3", default-features = false, features = ["byteorder", "rustc-hex"] } uint = { path = "../uint", version = "0.7", default-features = false } -primitive-types = { path = "../primitive-types", version = "0.2", features = ["rlp", "byteorder", "rustc-hex"], default-features = false } +primitive-types = { path = "../primitive-types", version = "0.3", features = ["rlp", "byteorder", "rustc-hex"], default-features = false } impl-serde = { path = "../primitive-types/impls/serde", version = "0.2", default-features = false, optional = true } -impl-rlp = { path = "../primitive-types/impls/rlp", version = "0.1", default-features = false } +impl-rlp = { path = "../primitive-types/impls/rlp", version = "0.2", default-features = false } [dev-dependencies] serde_json = "1.0" diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 37ea6ee28..c1178a96b 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keccak-hash" -version = "0.1.3" +version = "0.2.0" description = "`keccak-hash` is a set of utility functions to facilitate working with Keccak hashes (256/512 bits long)." authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" @@ -9,7 +9,7 @@ license = "GPL-3.0" [dependencies] tiny-keccak = "1.4" -primitive-types = { path = "../primitive-types", version = "0.2" } +primitive-types = { path = "../primitive-types", version = "0.3" } [dev-dependencies] tempdir = "0.3" diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 6bd9541c9..bfbb04618 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primitive-types" -version = "0.2.4" +version = "0.3.0" authors = ["Parity Technologies "] license = "Apache-2.0/MIT" homepage = "https://github.com/paritytech/parity-common" @@ -11,7 +11,7 @@ fixed-hash = { version = "0.3", path = "../fixed-hash", default-features = false uint = { version = "0.7", path = "../uint", default-features = false } impl-serde = { version = "0.2", path = "impls/serde", default-features = false, optional = true } impl-codec = { version = "0.2", path = "impls/codec", default-features = false, optional = true } -impl-rlp = { version = "0.1", path = "impls/rlp", default-features = false, optional = true } +impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, optional = true } [features] default = ["std"] diff --git a/primitive-types/impls/rlp/Cargo.toml b/primitive-types/impls/rlp/Cargo.toml index cc84f2b9b..7f0ee2696 100644 --- a/primitive-types/impls/rlp/Cargo.toml +++ b/primitive-types/impls/rlp/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "impl-rlp" -version = "0.1.1" +version = "0.2.0" authors = ["Parity Technologies "] license = "Apache-2.0/MIT" homepage = "https://github.com/paritytech/parity-common" description = "RLP serialization support for uint and fixed hash." [dependencies] -rlp = { version = "0.3", path = "../../../rlp", default-features = false } +rlp = { version = "0.4", path = "../../../rlp" } diff --git a/rlp/Cargo.toml b/rlp/Cargo.toml index d486847fd..f7bb9e56c 100644 --- a/rlp/Cargo.toml +++ b/rlp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rlp" -version = "0.3.0" +version = "0.4.0" description = "Recursive-length prefix encoding, decoding, and compression" repository = "https://github.com/paritytech/parity-common" license = "MIT/Apache-2.0" @@ -8,12 +8,9 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" -ethereum-types = { version = "0.4", optional = true } rustc-hex = {version = "2.0", default-features = false } [dev-dependencies] hex-literal = "0.1" +primitive-types = { path = "../primitive-types", version = "0.3", features = ["impl-rlp"] } -[features] -default = ["ethereum"] -ethereum = ["ethereum-types"] diff --git a/rlp/src/impls.rs b/rlp/src/impls.rs index 4abc6d4e0..6d385b3c2 100644 --- a/rlp/src/impls.rs +++ b/rlp/src/impls.rs @@ -175,94 +175,6 @@ impl Decodable for usize { } } -#[cfg(feature = "ethereum")] -mod ethereum_traits { - use super::*; - use std::cmp; - use ethereum_types::{U128, U256, H64, H128, H160, H256, H512, H520, Bloom}; - - macro_rules! impl_encodable_for_hash { - ($name: ident) => { - impl Encodable for $name { - fn rlp_append(&self, s: &mut RlpStream) { - s.encoder().encode_value(self); - } - } - } - } - - macro_rules! impl_decodable_for_hash { - ($name: ident, $size: expr) => { - impl Decodable for $name { - fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| match bytes.len().cmp(&$size) { - cmp::Ordering::Less => Err(DecoderError::RlpIsTooShort), - cmp::Ordering::Greater => Err(DecoderError::RlpIsTooBig), - cmp::Ordering::Equal => { - let mut t = [0u8; $size]; - t.copy_from_slice(bytes); - Ok($name(t)) - } - }) - } - } - } - } - - macro_rules! impl_encodable_for_uint { - ($name: ident, $size: expr) => { - impl Encodable for $name { - fn rlp_append(&self, s: &mut RlpStream) { - let leading_empty_bytes = $size - (self.bits() + 7) / 8; - let mut buffer = [0u8; $size]; - self.to_big_endian(&mut buffer); - s.encoder().encode_value(&buffer[leading_empty_bytes..]); - } - } - } - } - - macro_rules! impl_decodable_for_uint { - ($name: ident, $size: expr) => { - impl Decodable for $name { - fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| { - if !bytes.is_empty() && bytes[0] == 0 { - Err(DecoderError::RlpInvalidIndirection) - } else if bytes.len() <= $size { - Ok($name::from(bytes)) - } else { - Err(DecoderError::RlpIsTooBig) - } - }) - } - } - } - } - - impl_encodable_for_hash!(H64); - impl_encodable_for_hash!(H128); - impl_encodable_for_hash!(H160); - impl_encodable_for_hash!(H256); - impl_encodable_for_hash!(H512); - impl_encodable_for_hash!(H520); - impl_encodable_for_hash!(Bloom); - - impl_decodable_for_hash!(H64, 8); - impl_decodable_for_hash!(H128, 16); - impl_decodable_for_hash!(H160, 20); - impl_decodable_for_hash!(H256, 32); - impl_decodable_for_hash!(H512, 64); - impl_decodable_for_hash!(H520, 65); - impl_decodable_for_hash!(Bloom, 256); - - impl_encodable_for_uint!(U256, 32); - impl_encodable_for_uint!(U128, 16); - - impl_decodable_for_uint!(U256, 32); - impl_decodable_for_uint!(U128, 16); -} - impl<'a> Encodable for &'a str { fn rlp_append(&self, s: &mut RlpStream) { s.encoder().encode_value(self.as_bytes()); diff --git a/rlp/src/lib.rs b/rlp/src/lib.rs index 01dafc812..235a546b0 100644 --- a/rlp/src/lib.rs +++ b/rlp/src/lib.rs @@ -33,8 +33,6 @@ //! * You don't want to decode whole rlp at once. extern crate byteorder; -#[cfg(feature = "ethereum")] -extern crate ethereum_types; extern crate rustc_hex; #[cfg(test)] #[macro_use] diff --git a/rlp/tests/tests.rs b/rlp/tests/tests.rs index 1c4e2027a..6f534a325 100644 --- a/rlp/tests/tests.rs +++ b/rlp/tests/tests.rs @@ -6,15 +6,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(feature = "ethereum")] -extern crate ethereum_types; extern crate rlp; #[macro_use] extern crate hex_literal; +extern crate primitive_types; +use primitive_types::{H160, U256}; use std::{fmt, cmp}; -#[cfg(feature = "ethereum")] -use ethereum_types::{U256, H160}; use rlp::{Encodable, Decodable, Rlp, RlpStream, DecoderError}; #[test] @@ -134,7 +132,6 @@ fn encode_u64() { run_encode_tests(tests); } -#[cfg(feature = "ethereum")] #[test] fn encode_u256() { let tests = vec![ETestPair(U256::from(0u64), vec![0x80u8]), @@ -167,11 +164,10 @@ fn encode_str() { run_encode_tests(tests); } -#[cfg(feature = "ethereum")] #[test] fn encode_address() { let tests = vec![ - ETestPair(H160::from("ef2d6d194084c2de36e0dabfce45d046b37d1106"), + ETestPair(H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), vec![0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06]) @@ -278,7 +274,6 @@ fn decode_untrusted_u64() { run_decode_tests(tests); } -#[cfg(feature = "ethereum")] #[test] fn decode_untrusted_u256() { let tests = vec![DTestPair(U256::from(0u64), vec![0x80u8]), @@ -313,11 +308,10 @@ fn decode_untrusted_str() { run_decode_tests(tests); } -#[cfg(feature = "ethereum")] #[test] fn decode_untrusted_address() { let tests = vec![ - DTestPair(H160::from("ef2d6d194084c2de36e0dabfce45d046b37d1106"), + DTestPair(H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), vec![0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06]) diff --git a/triehash/Cargo.toml b/triehash/Cargo.toml index 5493078e6..c0dab4dce 100644 --- a/triehash/Cargo.toml +++ b/triehash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "triehash" -version = "0.4.0" +version = "0.5.0" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/parity-common" @@ -8,12 +8,10 @@ license = "GPL-3.0" [dependencies] hash-db = { version = "0.11.0", default-features = false } -rlp = { version = "0.3.0", path = "../rlp", default-features = false } +rlp = { version = "0.4", path = "../rlp" } [dev-dependencies] keccak-hasher = { version = "0.11.0" } tiny-keccak = "1.4.2" -ethereum-types = "0.4" - -[features] -ethereum = ["rlp/ethereum"] +ethereum-types = "0.5" +hex-literal = "0.2" diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 995fb027a..343564e04 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -20,7 +20,11 @@ extern crate hash_db; extern crate rlp; -#[cfg(test)] extern crate keccak_hasher; +#[cfg(test)] +extern crate keccak_hasher; +#[cfg(test)] +#[macro_use] +extern crate hex_literal; use std::collections::BTreeMap; use std::cmp; @@ -41,13 +45,14 @@ fn shared_prefix_len(first: &[T], second: &[T]) -> usize { /// extern crate triehash; /// extern crate keccak_hasher; /// extern crate ethereum_types; +/// #[macro_use] extern crate hex_literal; /// use ethereum_types::H256; /// use triehash::ordered_trie_root; /// use keccak_hasher::KeccakHasher; /// /// fn main() { /// let v = &["doe", "reindeer"]; -/// let root = H256::from("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3"); +/// let root = H256::from(hex!("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3")); /// assert_eq!(ordered_trie_root::(v), root.as_ref()); /// } /// ``` @@ -67,6 +72,7 @@ where /// extern crate triehash; /// extern crate ethereum_types; /// extern crate keccak_hasher; +/// #[macro_use] extern crate hex_literal; /// use triehash::trie_root; /// use ethereum_types::H256; /// use keccak_hasher::KeccakHasher; @@ -78,7 +84,7 @@ where /// ("dogglesworth", "cat"), /// ]; /// -/// let root = H256::from("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"); +/// let root = H256::from(hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")); /// assert_eq!(trie_root::(v), root.as_ref()); /// } /// ``` @@ -123,6 +129,7 @@ where /// extern crate triehash; /// extern crate keccak_hasher; /// extern crate ethereum_types; +/// #[macro_use] extern crate hex_literal; /// use ethereum_types::H256; /// use triehash::sec_trie_root; /// use keccak_hasher::KeccakHasher; @@ -134,7 +141,7 @@ where /// ("dogglesworth", "cat"), /// ]; /// -/// let root = H256::from("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585"); +/// let root = H256::from(hex!("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585")); /// assert_eq!(sec_trie_root::(v), root.as_ref()); /// } /// ``` @@ -323,7 +330,7 @@ mod tests { fn simple_test() { assert_eq!(trie_root::(vec![ (b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8]) - ]), H256::from("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").as_ref()); + ]), H256::from(hex!("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")).as_ref()); } #[test]