Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ethereum-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>"]
license = "MIT"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions keccak-hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>"]
repository = "https://github.com/paritytech/parity-common"
Expand All @@ -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" }
Comment thread
ordian marked this conversation as resolved.

[dev-dependencies]
tempdir = "0.3"
4 changes: 2 additions & 2 deletions primitive-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "primitive-types"
version = "0.2.4"
version = "0.3.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0/MIT"
homepage = "https://github.com/paritytech/parity-common"
Expand All @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions primitive-types/impls/rlp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "impl-rlp"
version = "0.1.1"
version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"]
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" }
7 changes: 2 additions & 5 deletions rlp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
[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"
authors = ["Parity Technologies <admin@parity.io>"]

[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"]
88 changes: 0 additions & 88 deletions rlp/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, DecoderError> {
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<Self, DecoderError> {
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());
Expand Down
2 changes: 0 additions & 2 deletions rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 4 additions & 10 deletions rlp/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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])
Expand Down
10 changes: 4 additions & 6 deletions triehash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
[package]
name = "triehash"
version = "0.4.0"
version = "0.5.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "In-memory patricia trie operations"
repository = "https://github.com/paritytech/parity-common"
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"
17 changes: 12 additions & 5 deletions triehash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,13 +45,14 @@ fn shared_prefix_len<T: Eq>(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::<KeccakHasher, _>(v), root.as_ref());
/// }
/// ```
Expand All @@ -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;
Expand All @@ -78,7 +84,7 @@ where
/// ("dogglesworth", "cat"),
/// ];
///
/// let root = H256::from("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
/// let root = H256::from(hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"));
/// assert_eq!(trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// }
/// ```
Expand Down Expand Up @@ -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;
Expand All @@ -134,7 +141,7 @@ where
/// ("dogglesworth", "cat"),
/// ];
///
/// let root = H256::from("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585");
/// let root = H256::from(hex!("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585"));
/// assert_eq!(sec_trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// }
/// ```
Expand Down Expand Up @@ -323,7 +330,7 @@ mod tests {
fn simple_test() {
assert_eq!(trie_root::<KeccakHasher, _, _, _>(vec![
(b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8])
]), H256::from("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").as_ref());
]), H256::from(hex!("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")).as_ref());
}

#[test]
Expand Down