From d1e3c633e5de6e88b9596415361d2dc8f2b5e310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 7 Apr 2016 12:49:20 +0200 Subject: [PATCH 1/2] Fixing compilation with rpc feature disabled --- parity/main.rs | 55 ++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index 06710a3a4..11f9dd91d 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -43,6 +43,7 @@ extern crate rpassword; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; +use std::any::Any; use std::io::{BufRead, BufReader}; use std::fs::File; use std::net::{SocketAddr, IpAddr}; @@ -270,8 +271,10 @@ fn setup_rpc_server( sync: Arc, secret_store: Arc, miner: Arc, + url: &str, + cors_domain: &str, apis: Vec<&str> -) -> Option { +) -> Option> { use rpc::v1::*; let server = rpc::RpcServer::new(); @@ -289,7 +292,12 @@ fn setup_rpc_server( } } } - Some(server) + let start_result = server.start_http(url, cors_domain, ::num_cpus::get()); + match start_result { + Err(rpc::RpcServerError::IoError(err)) => die_with_io_error(err), + Err(e) => die!("{:?}", e), + Ok(handle) => Some(Box::new(handle)), + } } #[cfg(not(feature = "rpc"))] @@ -298,9 +306,11 @@ fn setup_rpc_server( _sync: Arc, _secret_store: Arc, _miner: Arc, + _url: &str, + _cors_domain: &str, _apis: Vec<&str> -) -> Option> { - None +) -> ! { + die!("Your Parity version has been compiled without JSON-RPC support.") } fn print_version() { @@ -582,20 +592,7 @@ impl Configuration { // Setup rpc let rpc_server = if self.args.flag_jsonrpc || self.args.flag_rpc { - // TODO: use this as the API list. let apis = self.args.flag_rpcapi.as_ref().unwrap_or(&self.args.flag_jsonrpc_apis); - setup_rpc_server( - service.client(), - sync.clone(), - account_service.clone(), - miner.clone(), - apis.split(',').collect() - ) - } else { - None - }; - - let rpc_handle = rpc_server.map(|server| { let url = format!("{}:{}", match self.args.flag_rpcaddr.as_ref().unwrap_or(&self.args.flag_jsonrpc_interface).as_str() { "all" => "0.0.0.0", @@ -606,13 +603,19 @@ impl Configuration { ); SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid JSONRPC listen host/port given.", url)); let cors_domain = self.args.flag_rpccorsdomain.as_ref().unwrap_or(&self.args.flag_jsonrpc_cors); - let start_result = server.start_http(&url, cors_domain, ::num_cpus::get()); - match start_result { - Ok(handle) => handle, - Err(rpc::RpcServerError::IoError(err)) => die_with_io_error(err), - Err(e) => die!("{:?}", e), - } - }); + + setup_rpc_server( + service.client(), + sync.clone(), + account_service.clone(), + miner.clone(), + &url, + &cors_domain, + apis.split(',').collect() + ) + } else { + None + }; // Register IO handler let io_handler = Arc::new(ClientIoHandler { @@ -624,11 +627,11 @@ impl Configuration { service.io().register_handler(io_handler).expect("Error registering IO handler"); // Handle exit - wait_for_exit(panic_handler, rpc_handle); + wait_for_exit(panic_handler, rpc_server); } } -fn wait_for_exit(panic_handler: Arc, _rpc_handle: Option) { +fn wait_for_exit(panic_handler: Arc, _rpc_server: Option>) { let exit = Arc::new(Condvar::new()); // Handle possible exits From 2adeb9fe8800f8edb6f54bff03658f1cb9d9cbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 7 Apr 2016 12:55:06 +0200 Subject: [PATCH 2/2] Removing Option from setup_rpc_server method return type --- parity/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index 11f9dd91d..011d761ef 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -274,7 +274,7 @@ fn setup_rpc_server( url: &str, cors_domain: &str, apis: Vec<&str> -) -> Option> { +) -> Box { use rpc::v1::*; let server = rpc::RpcServer::new(); @@ -296,7 +296,7 @@ fn setup_rpc_server( match start_result { Err(rpc::RpcServerError::IoError(err)) => die_with_io_error(err), Err(e) => die!("{:?}", e), - Ok(handle) => Some(Box::new(handle)), + Ok(handle) => Box::new(handle), } } @@ -604,7 +604,7 @@ impl Configuration { SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid JSONRPC listen host/port given.", url)); let cors_domain = self.args.flag_rpccorsdomain.as_ref().unwrap_or(&self.args.flag_jsonrpc_cors); - setup_rpc_server( + Some(setup_rpc_server( service.client(), sync.clone(), account_service.clone(), @@ -612,7 +612,7 @@ impl Configuration { &url, &cors_domain, apis.split(',').collect() - ) + )) } else { None };