From d4e66ba52f2f5d7cdbd98731cb8644afda708023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sat, 28 May 2016 19:26:01 +0200 Subject: [PATCH] Defining ApiSets dependent on context --- parity/dapps.rs | 3 +-- parity/rpc.rs | 2 +- parity/rpc_apis.rs | 30 +++++++++++++++++++++--------- parity/signer.rs | 3 +-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/parity/dapps.rs b/parity/dapps.rs index 4ea74d7f2..91742d9e3 100644 --- a/parity/dapps.rs +++ b/parity/dapps.rs @@ -84,8 +84,7 @@ pub fn setup_dapps_server( use ethcore_dapps as dapps; let server = dapps::ServerBuilder::new(); - // TODO [ToDr] Specify apis - let server = rpc_apis::setup_rpc(server, deps.apis.clone(), None); + let server = rpc_apis::setup_rpc(server, deps.apis.clone(), rpc_apis::ApiSet::UnsafeContext); let start_result = match auth { None => { server.start_unsecure_http(url) diff --git a/parity/rpc.rs b/parity/rpc.rs index af998ff97..66f504408 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -75,7 +75,7 @@ pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option, deps: &Dependencies) -> Server { let apis = rpc_apis::from_str(apis); let server = Server::new(); - rpc_apis::setup_rpc(server, deps.apis.clone(), Some(apis)) + rpc_apis::setup_rpc(server, deps.apis.clone(), rpc_apis::ApiSet::List(apis)) } #[cfg(not(feature = "rpc"))] diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 4278fb060..c73a70fee 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -35,9 +35,6 @@ pub struct ConfirmationsQueue; #[cfg(feature="rpc")] use ethcore_rpc::Extendable; - - - pub enum Api { Web3, Net, @@ -47,10 +44,17 @@ pub enum Api { Traces, Rpc, } + pub enum ApiError { UnknownApi(String) } +pub enum ApiSet { + SafeContext, + UnsafeContext, + List(Vec), +} + impl FromStr for Api { type Err = ApiError; @@ -108,14 +112,22 @@ pub fn from_str(apis: Vec<&str>) -> Vec { }) } -pub fn setup_rpc(server: T, deps: Arc, apis: Option>) -> T { +fn list_apis(apis: ApiSet, signer_enabled: bool) -> Vec { + match apis { + ApiSet::List(apis) => apis, + ApiSet::UnsafeContext if signer_enabled => { + vec![Api::Web3, Api::Net, Api::Eth, Api::Ethcore, Api::Traces, Api::Rpc] + } + _ => { + vec![Api::Web3, Api::Net, Api::Eth, Api::Personal, Api::Ethcore, Api::Traces, Api::Rpc] + } + } +} + +pub fn setup_rpc(server: T, deps: Arc, apis: ApiSet) -> T { use ethcore_rpc::v1::*; - let apis = match apis { - Some(api) => api, - None => vec![Api::Web3, Api::Net, Api::Eth, Api::Personal, Api::Ethcore, Api::Traces, Api::Rpc], - }; - + let apis = list_apis(apis, deps.signer_enabled); for api in &apis { match *api { Api::Web3 => { diff --git a/parity/signer.rs b/parity/signer.rs index b2224b106..d549b89cb 100644 --- a/parity/signer.rs +++ b/parity/signer.rs @@ -52,8 +52,7 @@ fn do_start(conf: Configuration, deps: Dependencies) -> SignerServer { let start_result = { let server = signer::ServerBuilder::new(); - // TODO [ToDr] Setup APIS - let server = rpc_apis::setup_rpc(server, deps.apis, None); + let server = rpc_apis::setup_rpc(server, deps.apis, rpc_apis::ApiSet::SafeContext); server.start(addr) };