diff --git a/Cargo.lock b/Cargo.lock index 86db0c97a..e9d7a757a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,6 +416,7 @@ dependencies = [ "mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)", "parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.1.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -442,6 +443,7 @@ dependencies = [ "jsonrpc-core 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 6.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.1.0", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -588,6 +590,7 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.1.0", "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index ac1fd96c5..0d5bfc62c 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -23,6 +23,7 @@ ethash = { path = "../ethash" } ethsync = { path = "../sync" } ethjson = { path = "../json" } ethcore-devtools = { path = "../devtools" } +rlp = { path = "../util/rlp" } rustc-serialize = "0.3" transient-hashmap = "0.1" serde_macros = { version = "0.7.0", optional = true } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 6edc72d41..17d1837ae 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -19,15 +19,12 @@ #![cfg_attr(feature="nightly", feature(custom_derive, custom_attribute, plugin))] #![cfg_attr(feature="nightly", plugin(serde_macros, clippy))] -#[macro_use] -extern crate log; extern crate rustc_serialize; extern crate serde; extern crate serde_json; extern crate jsonrpc_core; extern crate jsonrpc_http_server; -#[macro_use] -extern crate ethcore_util as util; + extern crate ethcore_io as io; extern crate ethcore; extern crate ethkey; @@ -37,6 +34,12 @@ extern crate transient_hashmap; extern crate json_ipc_server as ipc; extern crate ethcore_ipc; extern crate time; +extern crate rlp; + +#[macro_use] +extern crate log; +#[macro_use] +extern crate ethcore_util as util; #[cfg(test)] extern crate ethjson; diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index b26dca8dc..bf8442a85 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -15,7 +15,6 @@ // along with Parity. If not, see . use util::{Address, H256, U256, Uint}; -use util::rlp::encode; use util::bytes::ToPretty; use ethcore::miner::MinerService; use ethcore::client::MiningBlockChainClient; @@ -70,7 +69,7 @@ pub fn unlock_sign_and_dispatch(client: &C, miner: &M, request: Transactio t.with_signature(signature) }; - trace!(target: "miner", "send_transaction: dispatching tx: {}", encode(&signed_transaction).to_vec().pretty()); + trace!(target: "miner", "send_transaction: dispatching tx: {}", ::rlp::encode(&signed_transaction).to_vec().pretty()); dispatch_transaction(&*client, &*miner, signed_transaction) } @@ -84,7 +83,7 @@ pub fn sign_and_dispatch(client: &C, miner: &M, request: TransactionReques t.with_signature(signature) }; - trace!(target: "miner", "send_transaction: dispatching tx: {}", encode(&signed_transaction).to_vec().pretty()); + trace!(target: "miner", "send_transaction: dispatching tx: {}", ::rlp::encode(&signed_transaction).to_vec().pretty()); dispatch_transaction(&*client, &*miner, signed_transaction) } diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index d805d57ee..8ec1904ea 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -29,8 +29,8 @@ use ethcore::miner::{MinerService, ExternalMinerService}; use jsonrpc_core::*; use util::{H256, Address, FixedHash, U256, H64, Uint}; use util::sha3::*; -use util::rlp::{encode, decode, UntrustedRlp, View}; use util::{FromHex, Mutex}; +use rlp::{self, UntrustedRlp, View}; use ethcore::account_provider::AccountProvider; use ethcore::client::{MiningBlockChainClient, BlockID, TransactionID, UncleID}; use ethcore::header::Header as BlockHeader; @@ -123,7 +123,7 @@ impl EthClient where timestamp: view.timestamp().into(), difficulty: view.difficulty().into(), total_difficulty: total_difficulty.into(), - seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), + seal_fields: view.seal().into_iter().map(|f| rlp::decode(&f)).map(Bytes::new).collect(), uncles: block_view.uncle_hashes().into_iter().map(Into::into).collect(), transactions: match include_txs { true => BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect()), @@ -147,7 +147,7 @@ impl EthClient where fn uncle(&self, id: UncleID) -> Result { let client = take_weak!(self.client); let uncle: BlockHeader = match client.uncle(id) { - Some(rlp) => decode(&rlp), + Some(rlp) => rlp::decode(&rlp), None => { return Ok(Value::Null); } }; let parent_difficulty = match client.block_total_difficulty(BlockID::Hash(uncle.parent_hash().clone())) { @@ -173,7 +173,7 @@ impl EthClient where total_difficulty: (uncle.difficulty().clone() + parent_difficulty).into(), receipts_root: uncle.receipts_root().clone().into(), extra_data: uncle.extra_data().clone().into(), - seal_fields: uncle.seal().clone().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), + seal_fields: uncle.seal().clone().into_iter().map(|f| rlp::decode(&f)).map(Bytes::new).collect(), uncles: vec![], transactions: BlockTransactions::Hashes(vec![]), }; @@ -566,7 +566,7 @@ impl Eth for EthClient where trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); let miner = take_weak!(self.miner); let client = take_weak!(self.client); - let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()]; + let seal = vec![rlp::encode(&mix_hash).to_vec(), rlp::encode(&nonce).to_vec()]; let r = miner.submit_seal(&*client, pow_hash, seal); to_value(&r.is_ok()) }) diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index e5f84d9ef..0189fbaee 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -18,7 +18,7 @@ use std::sync::{Weak, Arc}; use jsonrpc_core::*; -use util::rlp::{UntrustedRlp, View}; +use rlp::{UntrustedRlp, View}; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId}; use ethcore::miner::MinerService; use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action}; diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index d7d93137f..1ff15dd0d 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -364,7 +364,7 @@ fn rpc_eth_pending_transaction_by_hash() { let tester = EthTester::default(); { - let tx: SignedTransaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap()); + let tx: SignedTransaction = ::rlp::decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap()); tester.miner.pending_transactions.lock().insert(H256::zero(), tx); } @@ -705,7 +705,7 @@ fn rpc_eth_send_raw_transaction() { let signature = tester.accounts_provider.sign(address, t.hash()).unwrap(); let t = t.with_signature(signature); - let rlp = ::util::rlp::encode(&t).to_vec().to_hex(); + let rlp = ::rlp::encode(&t).to_vec().to_hex(); let req = r#"{ "jsonrpc": "2.0", diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 812c006e4..6ce9eafc3 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::rlp::encode; use ethcore::contract_address; use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction}; use v1::types::{Bytes, H160, H256, U256}; @@ -75,7 +74,7 @@ impl From for Transaction { Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()), Action::Call(_) => None, }, - raw: encode(&t.signed).to_vec().into(), + raw: ::rlp::encode(&t.signed).to_vec().into(), } } } @@ -101,7 +100,7 @@ impl From for Transaction { Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()), Action::Call(_) => None, }, - raw: encode(&t).to_vec().into(), + raw: ::rlp::encode(&t).to_vec().into(), } } } diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 3a2e8aec2..a73077c9c 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -16,6 +16,7 @@ ethcore-util = { path = "../util" } ethcore-network = { path = "../util/network" } ethcore-io = { path = "../util/io" } ethcore = { path = "../ethcore" } +rlp = { path = "../util/rlp" } clippy = { version = "0.0.85", optional = true} log = "0.3" env_logger = "0.3" diff --git a/sync/src/blocks.rs b/sync/src/blocks.rs index 498b35f43..753ba7111 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use util::*; +use rlp::*; use network::NetworkError; use ethcore::header::{ Header as BlockHeader}; @@ -283,11 +284,11 @@ impl BlockCollection { transactions_root: info.transactions_root().clone(), uncles: info.uncles_hash().clone(), }; - if header_id.transactions_root == rlp::SHA3_NULL_RLP && header_id.uncles == rlp::SHA3_EMPTY_LIST_RLP { + if header_id.transactions_root == sha3::SHA3_NULL_RLP && header_id.uncles == sha3::SHA3_EMPTY_LIST_RLP { // empty body, just mark as downloaded let mut body_stream = RlpStream::new_list(2); - body_stream.append_raw(&rlp::EMPTY_LIST_RLP, 1); - body_stream.append_raw(&rlp::EMPTY_LIST_RLP, 1); + body_stream.append_raw(&::rlp::EMPTY_LIST_RLP, 1); + body_stream.append_raw(&::rlp::EMPTY_LIST_RLP, 1); block.body = Some(body_stream.out()); } else { @@ -337,6 +338,7 @@ mod test { use ethcore::views::HeaderView; use ethcore::header::BlockNumber; use util::*; + use rlp::*; fn is_empty(bc: &BlockCollection) -> bool { bc.heads.is_empty() && diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 9abd05398..feac90741 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -88,6 +88,7 @@ /// use util::*; +use rlp::*; use network::*; use std::mem::{replace}; use ethcore::views::{HeaderView, BlockView}; @@ -1531,6 +1532,7 @@ mod tests { use super::*; use ::SyncConfig; use util::*; + use rlp::*; use super::{PeerInfo, PeerAsking}; use ethcore::views::BlockView; use ethcore::header::*; @@ -1548,8 +1550,8 @@ mod tests { let mut rlp = RlpStream::new_list(3); rlp.append(&header); - rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1); - rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1); + rlp.append_raw(&::rlp::EMPTY_LIST_RLP, 1); + rlp.append_raw(&::rlp::EMPTY_LIST_RLP, 1); rlp.out() } diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 69dd03a2a..c0c240f9d 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -34,7 +34,6 @@ //! extern crate ethcore; //! extern crate ethsync; //! use std::env; -//! use std::sync::Arc; //! use io::IoChannel; //! use ethcore::client::{Client, ClientConfig}; //! use ethsync::{EthSync, SyncConfig, ManageNetwork, NetworkConfiguration}; @@ -62,22 +61,24 @@ //! } //! ``` -#[macro_use] -extern crate log; -#[macro_use] -extern crate ethcore_util as util; extern crate ethcore_network as network; extern crate ethcore_io as io; extern crate ethcore; extern crate env_logger; extern crate time; extern crate rand; +extern crate semver; +extern crate parking_lot; +extern crate rlp; + +#[macro_use] +extern crate log; +#[macro_use] +extern crate ethcore_util as util; #[macro_use] extern crate heapsize; #[macro_use] extern crate ethcore_ipc as ipc; -extern crate semver; -extern crate parking_lot; mod chain; mod blocks; diff --git a/util/network/Cargo.toml b/util/network/Cargo.toml index caad5c0d5..50ef6a5e4 100644 --- a/util/network/Cargo.toml +++ b/util/network/Cargo.toml @@ -25,6 +25,7 @@ ethcore-util = { path = ".." } ethcore-devtools = { path = "../../devtools" } ethkey = { path = "../../ethkey" } ethcrypto = { path = "../../ethcrypto" } +rlp = { path = "../rlp" } [features] default = [] diff --git a/util/network/src/connection.rs b/util/network/src/connection.rs index d3e54393b..4a7b5a3c7 100644 --- a/util/network/src/connection.rs +++ b/util/network/src/connection.rs @@ -23,7 +23,7 @@ use mio::tcp::*; use util::hash::*; use util::sha3::*; use util::bytes::*; -use util::rlp::*; +use rlp::*; use std::io::{self, Cursor, Read, Write}; use error::*; use io::{IoContext, StreamToken}; diff --git a/util/network/src/discovery.rs b/util/network/src/discovery.rs index 48d16be48..61eaf4094 100644 --- a/util/network/src/discovery.rs +++ b/util/network/src/discovery.rs @@ -24,7 +24,7 @@ use mio::udp::*; use util::sha3::*; use time; use util::hash::*; -use util::rlp::*; +use rlp::*; use node_table::*; use error::NetworkError; use io::{StreamToken, IoContext}; diff --git a/util/network/src/error.rs b/util/network/src/error.rs index 99bfb4500..a1c4d70a1 100644 --- a/util/network/src/error.rs +++ b/util/network/src/error.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use io::IoError; -use util::rlp::*; +use rlp::*; use util::UtilError; use std::fmt; use ethkey::Error as KeyError; diff --git a/util/network/src/handshake.rs b/util/network/src/handshake.rs index 403079de4..1456cf801 100644 --- a/util/network/src/handshake.rs +++ b/util/network/src/handshake.rs @@ -18,9 +18,9 @@ use std::sync::Arc; use rand::random; use mio::tcp::*; use util::hash::*; -use util::rlp::*; use util::sha3::Hashable; use util::bytes::Bytes; +use rlp::*; use connection::{Connection}; use host::{HostInfo}; use node_table::NodeId; diff --git a/util/network/src/host.rs b/util/network/src/host.rs index a1d320c58..359f54f1a 100644 --- a/util/network/src/host.rs +++ b/util/network/src/host.rs @@ -29,8 +29,8 @@ use mio::*; use mio::tcp::*; use util::hash::*; use util::Hashable; -use util::rlp::*; use util::version; +use rlp::*; use session::{Session, SessionData}; use error::*; use io::*; diff --git a/util/network/src/lib.rs b/util/network/src/lib.rs index e36861f37..bfcd49cea 100644 --- a/util/network/src/lib.rs +++ b/util/network/src/lib.rs @@ -54,9 +54,6 @@ //! } //! ``` - -#[macro_use] -extern crate log; extern crate ethcore_io as io; extern crate ethcore_util as util; extern crate parking_lot; @@ -72,6 +69,11 @@ extern crate libc; extern crate slab; extern crate ethkey; extern crate ethcrypto as crypto; +extern crate rlp; + +#[macro_use] +extern crate log; + #[cfg(test)] extern crate ethcore_devtools as devtools; diff --git a/util/network/src/node_table.rs b/util/network/src/node_table.rs index 26f6d9f8c..073e9ab76 100644 --- a/util/network/src/node_table.rs +++ b/util/network/src/node_table.rs @@ -26,8 +26,8 @@ use std::fmt; use std::fs; use std::io::{Read, Write}; use util::hash::*; -use util::rlp::*; use util::UtilError; +use rlp::*; use time::Tm; use error::NetworkError; use discovery::{TableUpdates, NodeEntry}; diff --git a/util/network/src/session.rs b/util/network/src/session.rs index 4e6dd1c8a..8ebd37090 100644 --- a/util/network/src/session.rs +++ b/util/network/src/session.rs @@ -19,8 +19,8 @@ use std::io; use std::sync::*; use mio::*; use mio::tcp::*; -use util::rlp::*; use util::hash::*; +use rlp::*; use connection::{EncryptedConnection, Packet, Connection}; use handshake::Handshake; use io::{IoContext, StreamToken};