From 225a5ee825bff64e9151ad0ca35ef979ffbf98fa Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 19 Apr 2016 19:35:32 +0200 Subject: [PATCH] removed redundant unwraps (#935) * removed redundant unwraps * fixed compilation error, removed warnings * fixed transaction queue merge conflict * fixed failing ethminer doc test --- ethcore/src/client/client.rs | 8 ++++---- ethcore/src/json_tests/chain.rs | 2 +- ethcore/src/json_tests/executive.rs | 2 -- ethcore/src/service.rs | 2 +- ethcore/src/tests/client.rs | 13 +++---------- ethcore/src/tests/helpers.rs | 4 ++-- miner/src/lib.rs | 2 +- sync/src/lib.rs | 2 +- 8 files changed, 13 insertions(+), 22 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 90ec8693f..c3e8d942e 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -122,7 +122,7 @@ const CLIENT_DB_VER_STR: &'static str = "5.3"; impl Client { /// Create a new client with given spec and DB path. - pub fn new(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel ) -> Result, Error> { + pub fn new(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel ) -> Arc { Client::::new_with_verifier(config, spec, path, message_channel) } } @@ -146,7 +146,7 @@ pub fn append_path(path: &Path, item: &str) -> String { impl Client where V: Verifier { /// Create a new client with given spec and DB path and custom verifier. - pub fn new_with_verifier(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel ) -> Result>, Error> { + pub fn new_with_verifier(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel ) -> Arc> { let path = get_db_path(path, config.pruning, spec.genesis_header().hash()); let gb = spec.genesis_block(); let chain = Arc::new(BlockChain::new(config.blockchain, &gb, &path)); @@ -163,7 +163,7 @@ impl Client where V: Verifier { let panic_handler = PanicHandler::new_in_arc(); panic_handler.forward_from(&block_queue); - Ok(Arc::new(Client { + Arc::new(Client { chain: chain, engine: engine, state_db: Mutex::new(state_db), @@ -172,7 +172,7 @@ impl Client where V: Verifier { import_lock: Mutex::new(()), panic_handler: panic_handler, verifier: PhantomData, - })) + }) } /// Flush the block import queue. diff --git a/ethcore/src/json_tests/chain.rs b/ethcore/src/json_tests/chain.rs index a1154f6a9..9413d025a 100644 --- a/ethcore/src/json_tests/chain.rs +++ b/ethcore/src/json_tests/chain.rs @@ -53,7 +53,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec { let temp = RandomTempPath::new(); { - let client = Client::new(ClientConfig::default(), spec, temp.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), spec, temp.as_path(), IoChannel::disconnected()); for b in &blockchain.blocks_rlp() { if Block::is_good(&b) { let _ = client.import_block(b.clone()); diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index 0825f3c27..427868807 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -17,11 +17,9 @@ use super::test_common::*; use state::*; use executive::*; -use spec::*; use engine::*; use evm; use evm::{Schedule, Ext, Factory, VMType, ContractCreateResult, MessageCallResult}; -use ethereum; use externalities::*; use substate::*; use tests::helpers::*; diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index 38bd873b8..2464b7cc6 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -61,7 +61,7 @@ impl ClientService { info!("Starting {}", net_service.host_info()); info!("Configured for {} using {:?} engine", spec.name, spec.engine.name()); - let client = try!(Client::new(config, spec, db_path, net_service.io().channel())); + let client = Client::new(config, spec, db_path, net_service.io().channel()); panic_handler.forward_from(client.deref()); let client_io = Arc::new(ClientIoHandler { client: client.clone() diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 539a33d10..926009ac4 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -20,17 +20,10 @@ use tests::helpers::*; use common::*; use devtools::*; -#[test] -fn created() { - let dir = RandomTempPath::new(); - let client_result = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); - assert!(client_result.is_ok()); -} - #[test] fn imports_from_empty() { let dir = RandomTempPath::new(); - let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); client.import_verified_blocks(&IoChannel::disconnected()); client.flush_queue(); } @@ -48,7 +41,7 @@ fn returns_state_root_basic() { #[test] fn imports_good_block() { let dir = RandomTempPath::new(); - let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); let good_block = get_good_dummy_block(); if let Err(_) = client.import_block(good_block) { panic!("error importing block being good by definition"); @@ -63,7 +56,7 @@ fn imports_good_block() { #[test] fn query_none_block() { let dir = RandomTempPath::new(); - let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); let non_existant = client.block_header(BlockId::Number(188)); assert!(non_existant.is_none()); diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 152ac0ef6..56e33d76b 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -145,7 +145,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[&SignedTrans pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult> { let dir = RandomTempPath::new(); - let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); let test_spec = get_test_spec(); let test_engine = &test_spec.engine; let state_root = test_spec.genesis_header().state_root; @@ -211,7 +211,7 @@ pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting pub fn get_test_client_with_blocks(blocks: Vec) -> GuardedTempResult> { let dir = RandomTempPath::new(); - let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); + let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()); for block in &blocks { if let Err(_) = client.import_block(block.clone()) { panic!("panic importing block which is well-formed"); diff --git a/miner/src/lib.rs b/miner/src/lib.rs index bdffa1073..bcfad253e 100644 --- a/miner/src/lib.rs +++ b/miner/src/lib.rs @@ -38,7 +38,7 @@ //! fn main() { //! let mut service = NetworkService::start(NetworkConfiguration::new()).unwrap(); //! let dir = env::temp_dir(); -//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()).unwrap(); +//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()); //! //! let miner: Miner = Miner::default(); //! // get status diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 6e900e97e..0b95f0b92 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -44,7 +44,7 @@ //! fn main() { //! let mut service = NetworkService::start(NetworkConfiguration::new()).unwrap(); //! let dir = env::temp_dir(); -//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()).unwrap(); +//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()); //! let miner = Miner::new(false); //! EthSync::register(&mut service, SyncConfig::default(), client, miner); //! }