Single place where RPC apis are created.
This commit is contained in:
parent
129ad0bbcb
commit
07399d377f
@ -52,6 +52,7 @@ extern crate serde_json;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate jsonrpc_http_server;
|
||||
extern crate parity_dapps;
|
||||
extern crate ethcore_rpc;
|
||||
|
||||
mod endpoint;
|
||||
mod apps;
|
||||
@ -66,6 +67,7 @@ use std::net::SocketAddr;
|
||||
use std::collections::HashMap;
|
||||
use jsonrpc_core::{IoHandler, IoDelegate};
|
||||
use router::auth::{Authorization, NoAuth, HttpBasicAuth};
|
||||
use ethcore_rpc::Extendable;
|
||||
|
||||
static DAPPS_DOMAIN : &'static str = ".parity";
|
||||
|
||||
@ -74,6 +76,12 @@ pub struct ServerBuilder {
|
||||
handler: Arc<IoHandler>,
|
||||
}
|
||||
|
||||
impl Extendable for ServerBuilder {
|
||||
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerBuilder {
|
||||
/// Construct new dapps server
|
||||
pub fn new() -> Self {
|
||||
@ -82,11 +90,6 @@ impl ServerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add io delegate.
|
||||
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
|
||||
/// Asynchronously start server with no authentication,
|
||||
/// returns result with `Server` handle on success or an error.
|
||||
pub fn start_unsecure_http(&self, addr: &SocketAddr) -> Result<Server, ServerError> {
|
||||
|
@ -17,14 +17,9 @@
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use std::net::SocketAddr;
|
||||
use ethcore::client::Client;
|
||||
use ethsync::EthSync;
|
||||
use ethminer::{Miner, ExternalMiner};
|
||||
use util::RotatingLogger;
|
||||
use util::panics::PanicHandler;
|
||||
use util::keys::store::AccountService;
|
||||
use util::network_settings::NetworkSettings;
|
||||
use die::*;
|
||||
use rpc_apis;
|
||||
|
||||
#[cfg(feature = "dapps")]
|
||||
pub use ethcore_dapps::Server as WebappServer;
|
||||
@ -41,13 +36,7 @@ pub struct Configuration {
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
pub miner: Arc<Miner>,
|
||||
pub external_miner: Arc<ExternalMiner>,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
}
|
||||
|
||||
pub fn new(configuration: Configuration, deps: Dependencies) -> Option<WebappServer> {
|
||||
@ -92,18 +81,11 @@ pub fn setup_dapps_server(
|
||||
url: &SocketAddr,
|
||||
auth: Option<(String, String)>
|
||||
) -> WebappServer {
|
||||
use ethcore_rpc::v1::*;
|
||||
use ethcore_dapps as dapps;
|
||||
|
||||
let server = dapps::ServerBuilder::new();
|
||||
server.add_delegate(Web3Client::new().to_delegate());
|
||||
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
|
||||
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
|
||||
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
|
||||
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate());
|
||||
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate());
|
||||
|
||||
// TODO [ToDr] Specify apis
|
||||
let server = rpc_apis::setup_rpc(server, deps.apis.clone(), None);
|
||||
let start_result = match auth {
|
||||
None => {
|
||||
server.start_unsecure_http(url)
|
||||
|
@ -69,6 +69,7 @@ mod cli;
|
||||
mod configuration;
|
||||
mod migration;
|
||||
mod signer;
|
||||
mod rpc_apis;
|
||||
|
||||
use std::io::{Write, Read, BufReader, BufRead};
|
||||
use std::ops::Deref;
|
||||
@ -197,8 +198,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
// Sync
|
||||
let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone());
|
||||
|
||||
let dependencies = Arc::new(rpc::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
|
||||
client: client.clone(),
|
||||
sync: sync.clone(),
|
||||
secret_store: account_service.clone(),
|
||||
@ -208,6 +208,11 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
settings: network_settings.clone(),
|
||||
});
|
||||
|
||||
let dependencies = rpc::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
};
|
||||
|
||||
// Setup http rpc
|
||||
let rpc_server = rpc::new_http(rpc::HttpConfiguration {
|
||||
enabled: network_settings.rpc_enabled,
|
||||
@ -229,13 +234,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
pass: conf.args.flag_dapps_pass.clone(),
|
||||
}, dapps::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
client: client.clone(),
|
||||
sync: sync.clone(),
|
||||
secret_store: account_service.clone(),
|
||||
miner: miner.clone(),
|
||||
external_miner: external_miner.clone(),
|
||||
logger: logger.clone(),
|
||||
settings: network_settings.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
});
|
||||
|
||||
// Set up a signer
|
||||
@ -244,11 +243,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
port: conf.args.flag_signer_port,
|
||||
}, signer::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
client: client.clone(),
|
||||
sync: sync.clone(),
|
||||
secret_store: account_service.clone(),
|
||||
miner: miner.clone(),
|
||||
external_miner: external_miner.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
});
|
||||
|
||||
// Register IO handler
|
||||
|
@ -15,19 +15,13 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use ethcore::client::Client;
|
||||
use ethsync::EthSync;
|
||||
use ethminer::{Miner, ExternalMiner};
|
||||
use util::RotatingLogger;
|
||||
use util::panics::PanicHandler;
|
||||
use util::keys::store::AccountService;
|
||||
use util::network_settings::NetworkSettings;
|
||||
use die::*;
|
||||
use jsonipc;
|
||||
use rpc_apis;
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
pub use ethcore_rpc::Server as RpcServer;
|
||||
@ -52,16 +46,10 @@ pub struct IpcConfiguration {
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
pub miner: Arc<Miner>,
|
||||
pub external_miner: Arc<ExternalMiner>,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
}
|
||||
|
||||
pub fn new_http(conf: HttpConfiguration, deps: &Arc<Dependencies>) -> Option<RpcServer> {
|
||||
pub fn new_http(conf: HttpConfiguration, deps: &Dependencies) -> Option<RpcServer> {
|
||||
if !conf.enabled {
|
||||
return None;
|
||||
}
|
||||
@ -78,59 +66,23 @@ pub fn new_http(conf: HttpConfiguration, deps: &Arc<Dependencies>) -> Option<Rpc
|
||||
Some(setup_http_rpc_server(deps, &addr, conf.cors, apis))
|
||||
}
|
||||
|
||||
pub fn new_ipc(conf: IpcConfiguration, deps: &Arc<Dependencies>) -> Option<jsonipc::Server> {
|
||||
pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option<jsonipc::Server> {
|
||||
if !conf.enabled { return None; }
|
||||
let apis = conf.apis.split(',').collect();
|
||||
Some(setup_ipc_rpc_server(deps, &conf.socket_addr, apis))
|
||||
}
|
||||
|
||||
fn setup_rpc_server(apis: Vec<&str>, deps: &Arc<Dependencies>) -> Server {
|
||||
use ethcore_rpc::v1::*;
|
||||
|
||||
fn setup_rpc_server(apis: Vec<&str>, deps: &Dependencies) -> Server {
|
||||
let apis = rpc_apis::from_str(apis);
|
||||
let server = Server::new();
|
||||
let mut modules = BTreeMap::new();
|
||||
for api in apis.into_iter() {
|
||||
match api {
|
||||
"web3" => {
|
||||
modules.insert("web3".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(Web3Client::new().to_delegate());
|
||||
},
|
||||
"net" => {
|
||||
modules.insert("net".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
|
||||
},
|
||||
"eth" => {
|
||||
modules.insert("eth".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
|
||||
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
|
||||
},
|
||||
"personal" => {
|
||||
modules.insert("personal".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate())
|
||||
},
|
||||
"ethcore" => {
|
||||
modules.insert("ethcore".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate())
|
||||
},
|
||||
"traces" => {
|
||||
modules.insert("traces".to_owned(), "1.0".to_owned());
|
||||
server.add_delegate(TracesClient::new(&deps.client).to_delegate())
|
||||
},
|
||||
_ => {
|
||||
die!("{}: Invalid API name to be enabled.", api);
|
||||
},
|
||||
}
|
||||
}
|
||||
server.add_delegate(RpcClient::new(modules).to_delegate());
|
||||
server
|
||||
rpc_apis::setup_rpc(server, deps.apis.clone(), Some(apis))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "rpc"))]
|
||||
pub fn setup_http_rpc_server(
|
||||
_deps: Dependencies,
|
||||
_deps: &Dependencies,
|
||||
_url: &SocketAddr,
|
||||
_cors_domain: Option<String>,
|
||||
_cors_domain: Vec<String>,
|
||||
_apis: Vec<&str>,
|
||||
) -> ! {
|
||||
die!("Your Parity version has been compiled without JSON-RPC support.")
|
||||
@ -138,27 +90,31 @@ pub fn setup_http_rpc_server(
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
pub fn setup_http_rpc_server(
|
||||
dependencies: &Arc<Dependencies>,
|
||||
dependencies: &Dependencies,
|
||||
url: &SocketAddr,
|
||||
cors_domains: Vec<String>,
|
||||
apis: Vec<&str>,
|
||||
) -> RpcServer {
|
||||
let server = setup_rpc_server(apis, dependencies);
|
||||
let start_result = server.start_http(url, cors_domains);
|
||||
let deps = dependencies.clone();
|
||||
let ph = dependencies.panic_handler.clone();
|
||||
match start_result {
|
||||
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),
|
||||
Err(e) => die!("RPC: {:?}", e),
|
||||
Ok(server) => {
|
||||
server.set_panic_handler(move || {
|
||||
deps.panic_handler.notify_all("Panic in RPC thread.".to_owned());
|
||||
ph.notify_all("Panic in RPC thread.".to_owned());
|
||||
});
|
||||
server
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup_ipc_rpc_server(dependencies: &Arc<Dependencies>, addr: &str, apis: Vec<&str>) -> jsonipc::Server {
|
||||
#[cfg(not(feature = "rpc"))]
|
||||
pub fn setup_ipc_rpc_server(_dependencies: &Dependencies, _addr: &str, _apis: Vec<&str>) -> ! {
|
||||
die!("Your Parity version has been compiled without JSON-RPC support.")
|
||||
}
|
||||
#[cfg(feature = "rpc")]
|
||||
pub fn setup_ipc_rpc_server(dependencies: &Dependencies, addr: &str, apis: Vec<&str>) -> jsonipc::Server {
|
||||
let server = setup_rpc_server(apis, dependencies);
|
||||
match server.start_ipc(addr) {
|
||||
Err(jsonipc::Error::Io(io_error)) => die_with_io_error("RPC", io_error),
|
||||
|
136
parity/rpc_apis.rs
Normal file
136
parity/rpc_apis.rs
Normal file
@ -0,0 +1,136 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use die::*;
|
||||
use ethsync::EthSync;
|
||||
use ethminer::{Miner, ExternalMiner};
|
||||
use ethcore::client::Client;
|
||||
use util::RotatingLogger;
|
||||
use util::keys::store::AccountService;
|
||||
use util::network_settings::NetworkSettings;
|
||||
|
||||
use ethcore_rpc::Extendable;
|
||||
|
||||
pub enum Api {
|
||||
Web3,
|
||||
Net,
|
||||
Eth,
|
||||
Personal,
|
||||
Ethcore,
|
||||
Traces,
|
||||
Rpc,
|
||||
}
|
||||
pub enum ApiError {
|
||||
UnknownApi(String)
|
||||
}
|
||||
|
||||
impl FromStr for Api {
|
||||
type Err = ApiError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
use self::Api::*;
|
||||
|
||||
match s {
|
||||
"web3" => Ok(Web3),
|
||||
"net" => Ok(Net),
|
||||
"eth" => Ok(Eth),
|
||||
"personal" => Ok(Personal),
|
||||
"ethcore" => Ok(Ethcore),
|
||||
"traces" => Ok(Traces),
|
||||
"rpc" => Ok(Rpc),
|
||||
e => Err(ApiError::UnknownApi(e.into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
pub miner: Arc<Miner>,
|
||||
pub external_miner: Arc<ExternalMiner>,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
}
|
||||
|
||||
fn to_modules(apis: &[Api]) -> BTreeMap<String, String> {
|
||||
let mut modules = BTreeMap::new();
|
||||
for api in apis {
|
||||
let (name, version) = match *api {
|
||||
Api::Web3 => ("web3", "1.0"),
|
||||
Api::Net => ("net", "1.0"),
|
||||
Api::Eth => ("eth", "1.0"),
|
||||
Api::Personal => ("personal", "1.0"),
|
||||
Api::Ethcore => ("ethcore", "1.0"),
|
||||
Api::Traces => ("traces", "1.0"),
|
||||
Api::Rpc => ("rpc", "1.0"),
|
||||
};
|
||||
modules.insert(name.into(), version.into());
|
||||
}
|
||||
modules
|
||||
}
|
||||
|
||||
pub fn from_str(apis: Vec<&str>) -> Vec<Api> {
|
||||
apis.into_iter()
|
||||
.map(Api::from_str)
|
||||
.collect::<Result<Vec<Api>, ApiError>>()
|
||||
.unwrap_or_else(|e| match e {
|
||||
ApiError::UnknownApi(s) => die!("Unknown RPC API specified: {}", s),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: Option<Vec<Api>>) -> 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],
|
||||
};
|
||||
|
||||
for api in &apis {
|
||||
match *api {
|
||||
Api::Web3 => {
|
||||
server.add_delegate(Web3Client::new().to_delegate());
|
||||
},
|
||||
Api::Net => {
|
||||
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
|
||||
},
|
||||
Api::Eth => {
|
||||
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
|
||||
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
|
||||
},
|
||||
Api::Personal => {
|
||||
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate())
|
||||
},
|
||||
Api::Ethcore => {
|
||||
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate())
|
||||
},
|
||||
Api::Traces => {
|
||||
server.add_delegate(TracesClient::new(&deps.client).to_delegate())
|
||||
},
|
||||
Api::Rpc => {
|
||||
let modules = to_modules(&apis);
|
||||
server.add_delegate(RpcClient::new(modules).to_delegate());
|
||||
}
|
||||
}
|
||||
}
|
||||
server
|
||||
}
|
@ -15,12 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use ethcore::client::Client;
|
||||
use ethsync::EthSync;
|
||||
use ethminer::{Miner, ExternalMiner};
|
||||
use util::keys::store::AccountService;
|
||||
use util::panics::{PanicHandler, ForwardPanic};
|
||||
use die::*;
|
||||
use rpc_apis;
|
||||
|
||||
#[cfg(feature = "ethcore-signer")]
|
||||
use ethcore_signer as signer;
|
||||
@ -36,11 +33,7 @@ pub struct Configuration {
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
pub miner: Arc<Miner>,
|
||||
pub external_miner: Arc<ExternalMiner>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
}
|
||||
|
||||
pub fn start(conf: Configuration, deps: Dependencies) -> Option<SignerServer> {
|
||||
@ -58,14 +51,9 @@ fn do_start(conf: Configuration, deps: Dependencies) -> SignerServer {
|
||||
});
|
||||
|
||||
let start_result = {
|
||||
use ethcore_rpc::v1::*;
|
||||
let server = signer::ServerBuilder::new();
|
||||
server.add_delegate(Web3Client::new().to_delegate());
|
||||
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
|
||||
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
|
||||
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
|
||||
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate());
|
||||
// TODO [ToDr] Setup APIS
|
||||
let server = rpc_apis::setup_rpc(server, deps.apis, None);
|
||||
server.start(addr)
|
||||
};
|
||||
|
||||
|
@ -40,11 +40,24 @@ use self::jsonrpc_core::{IoHandler, IoDelegate};
|
||||
pub use jsonrpc_http_server::{Server, RpcServerError};
|
||||
pub mod v1;
|
||||
|
||||
/// An object that can be extended with `IoDelegates`
|
||||
pub trait Extendable {
|
||||
/// Add `Delegate` to this object.
|
||||
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>);
|
||||
}
|
||||
|
||||
/// Http server.
|
||||
pub struct RpcServer {
|
||||
handler: Arc<jsonrpc_core::io::IoHandler>,
|
||||
}
|
||||
|
||||
impl Extendable for RpcServer {
|
||||
/// Add io delegate.
|
||||
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
impl RpcServer {
|
||||
/// Construct new http server object.
|
||||
pub fn new() -> RpcServer {
|
||||
@ -53,11 +66,6 @@ impl RpcServer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add io delegate.
|
||||
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
|
||||
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
|
||||
let cors_domains = cors_domains.into_iter()
|
||||
|
@ -35,3 +35,5 @@ pub use self::personal::Personal;
|
||||
pub use self::ethcore::Ethcore;
|
||||
pub use self::traces::Traces;
|
||||
pub use self::rpc::Rpc;
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use util::panics::{PanicHandler, OnPanicListener, MayPanic};
|
||||
use jsonrpc_core::{IoHandler, IoDelegate};
|
||||
use rpc::Extendable;
|
||||
|
||||
mod session;
|
||||
|
||||
@ -57,6 +58,12 @@ impl Default for ServerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Extendable for ServerBuilder {
|
||||
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerBuilder {
|
||||
/// Creates new `ServerBuilder`
|
||||
pub fn new() -> Self {
|
||||
@ -65,11 +72,6 @@ impl ServerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds rpc delegate
|
||||
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
|
||||
/// Starts a new `WebSocket` server in separate thread.
|
||||
/// Returns a `Server` handle which closes the server when droped.
|
||||
pub fn start(self, addr: SocketAddr) -> Result<Server, ServerError> {
|
||||
|
Loading…
Reference in New Issue
Block a user