diff --git a/ethcore/src/views/block.rs b/ethcore/src/views/block.rs index abc1f5031..c60cc07c5 100644 --- a/ethcore/src/views/block.rs +++ b/ethcore/src/views/block.rs @@ -16,13 +16,13 @@ //! View onto block rlp. -use hash::keccak; -use ethereum_types::H256; use bytes::Bytes; -use header::*; -use transaction::*; -use super::{TransactionView, HeaderView}; +use ethereum_types::H256; +use hash::keccak; +use header::Header; use rlp::Rlp; +use transaction::{UnverifiedTransaction, LocalizedTransaction}; +use views::{TransactionView, HeaderView}; /// View onto block rlp. pub struct BlockView<'a> { @@ -158,9 +158,7 @@ impl<'a> BlockView<'a> { #[cfg(test)] mod tests { - use std::str::FromStr; use rustc_hex::FromHex; - use ethereum_types::H256; use super::BlockView; #[test] @@ -169,7 +167,7 @@ mod tests { let rlp = "f90261f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23f862f86002018304cb2f94ec0e71ad0a90ffe1909d27dac207f7680abba42d01801ba03a347e72953c860f32b1eb2c78a680d8734b2ea08085d949d729479796f218d5a047ea6239d9e31ccac8af3366f5ca37184d26e7646e3191a3aeb81c4cf74de500c0".from_hex().unwrap(); let view = BlockView::new(&rlp); - assert_eq!(view.hash(), H256::from_str("2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259").unwrap()); + assert_eq!(view.hash(), "2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259".into()); assert_eq!(view.transactions_count(), 1); assert_eq!(view.uncles_count(), 0); } diff --git a/ethcore/src/views/body.rs b/ethcore/src/views/body.rs index 519b9944f..433f7c2b6 100644 --- a/ethcore/src/views/body.rs +++ b/ethcore/src/views/body.rs @@ -16,13 +16,13 @@ //! View onto block body rlp. -use hash::keccak; -use ethereum_types::H256; use bytes::Bytes; -use header::*; -use transaction::*; -use super::{TransactionView, HeaderView}; +use ethereum_types::H256; +use hash::keccak; +use header::{Header, BlockNumber}; use rlp::Rlp; +use transaction::{LocalizedTransaction, UnverifiedTransaction}; +use views::{TransactionView, HeaderView}; /// View onto block rlp. pub struct BodyView<'a> { @@ -146,4 +146,3 @@ mod tests { assert_eq!(view.uncles_count(), 0); } } - diff --git a/ethcore/src/views/header.rs b/ethcore/src/views/header.rs index e19ccfe2d..cce4eee82 100644 --- a/ethcore/src/views/header.rs +++ b/ethcore/src/views/header.rs @@ -16,11 +16,11 @@ //! View onto block header rlp -use hash::keccak; -use ethereum_types::{H256, Bloom, U256, Address}; use bytes::Bytes; -use rlp::{self, Rlp}; +use ethereum_types::{H256, Bloom, U256, Address}; +use hash::keccak; use header::BlockNumber; +use rlp::{self, Rlp}; /// View onto block header rlp. pub struct HeaderView<'a> { @@ -109,9 +109,8 @@ impl<'a> HeaderView<'a> { #[cfg(test)] mod tests { - use std::str::FromStr; use rustc_hex::FromHex; - use ethereum_types::{H256, Bloom, U256, Address}; + use ethereum_types::Bloom; use super::HeaderView; #[test] @@ -122,18 +121,18 @@ mod tests { let nonce = "88ab4e252a7e8c2a23".from_hex().unwrap(); let view = HeaderView::new(&rlp); - assert_eq!(view.hash(), H256::from_str("2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259").unwrap()); - assert_eq!(view.parent_hash(), H256::from_str("d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7").unwrap()); - assert_eq!(view.uncles_hash(), H256::from_str("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap()); - assert_eq!(view.author(), Address::from_str("8888f1f195afa192cfee860698584c030f4c9db1").unwrap()); - assert_eq!(view.state_root(), H256::from_str("5fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25").unwrap()); - assert_eq!(view.transactions_root(), H256::from_str("88d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158").unwrap()); - assert_eq!(view.receipts_root(), H256::from_str("07c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1").unwrap()); + assert_eq!(view.hash(), "2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259".into()); + assert_eq!(view.parent_hash(), "d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7".into()); + assert_eq!(view.uncles_hash(), "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".into()); + assert_eq!(view.author(), "8888f1f195afa192cfee860698584c030f4c9db1".into()); + assert_eq!(view.state_root(), "5fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25".into()); + assert_eq!(view.transactions_root(), "88d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158".into()); + assert_eq!(view.receipts_root(), "07c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1".into()); assert_eq!(view.log_bloom(), Bloom::default()); - assert_eq!(view.difficulty(), U256::from(0x02_00_80)); + assert_eq!(view.difficulty(), 0x020080.into()); assert_eq!(view.number(), 3); - assert_eq!(view.gas_limit(), U256::from(0x2f_ef_ba)); - assert_eq!(view.gas_used(), U256::from(0x52_4d)); + assert_eq!(view.gas_limit(), 0x2fefba.into()); + assert_eq!(view.gas_used(), 0x524d.into()); assert_eq!(view.timestamp(), 0x56_8e_93_2a); assert_eq!(view.extra_data(), vec![] as Vec); assert_eq!(view.seal(), vec![mix_hash, nonce]); diff --git a/ethcore/src/views/mod.rs b/ethcore/src/views/mod.rs index 4e6ae34d2..5d3cc8cdc 100644 --- a/ethcore/src/views/mod.rs +++ b/ethcore/src/views/mod.rs @@ -17,11 +17,11 @@ //! Block oriented views onto rlp. mod block; +mod body; mod header; mod transaction; -mod body; pub use self::block::BlockView; -pub use self::header::HeaderView; pub use self::body::BodyView; +pub use self::header::HeaderView; pub use self::transaction::TransactionView; diff --git a/ethcore/src/views/transaction.rs b/ethcore/src/views/transaction.rs index 52049c1fa..92bd49c27 100644 --- a/ethcore/src/views/transaction.rs +++ b/ethcore/src/views/transaction.rs @@ -15,8 +15,8 @@ // along with Parity. If not, see . //! View onto transaction rlp -use ethereum_types::{H256, U256}; use bytes::Bytes; +use ethereum_types::{H256, U256}; use hash::keccak; use rlp::Rlp; @@ -77,9 +77,7 @@ impl<'a> TransactionView<'a> { #[cfg(test)] mod tests { - use std::str::FromStr; use rustc_hex::FromHex; - use ethereum_types::U256; use super::TransactionView; #[test] @@ -87,13 +85,13 @@ mod tests { let rlp = "f87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d00000000000000000000000000000000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804".from_hex().unwrap(); let view = TransactionView::new(&rlp); - assert_eq!(view.nonce(), U256::from(0)); - assert_eq!(view.gas_price(), U256::from(1)); - assert_eq!(view.gas(), U256::from(0x61a8)); - assert_eq!(view.value(), U256::from(0xa)); + assert_eq!(view.nonce(), 0.into()); + assert_eq!(view.gas_price(), 1.into()); + assert_eq!(view.gas(), 0x61a8.into()); + assert_eq!(view.value(), 0xa.into()); assert_eq!(view.data(), "0000000000000000000000000000000000000000000000000000000000".from_hex().unwrap()); - assert_eq!(view.r(), U256::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353").unwrap()); - assert_eq!(view.s(), U256::from_str("efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap()); + assert_eq!(view.r(), "48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353".into()); + assert_eq!(view.s(), "efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804".into()); assert_eq!(view.v(), 0x1b); } }