Defining ApiSets dependent on context
This commit is contained in:
parent
1607478405
commit
d4e66ba52f
@ -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)
|
||||
|
@ -75,7 +75,7 @@ pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option<jsonipc::S
|
||||
fn setup_rpc_server(apis: Vec<&str>, 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"))]
|
||||
|
@ -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<Api>),
|
||||
}
|
||||
|
||||
impl FromStr for Api {
|
||||
type Err = ApiError;
|
||||
|
||||
@ -108,14 +112,22 @@ pub fn from_str(apis: Vec<&str>) -> Vec<Api> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: Option<Vec<Api>>) -> T {
|
||||
fn list_apis(apis: ApiSet, signer_enabled: bool) -> Vec<Api> {
|
||||
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<T: Extendable>(server: T, deps: Arc<Dependencies>, 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 => {
|
||||
|
@ -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)
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user