Sunce86/rpc module reverted for RPC JSON api (#284)
* rpc module reverted for RPC JSON api Co-authored-by: Dusan Stanivukovic <dusan.stanivukovic@gnosis.pm>
This commit is contained in:
parent
efb80e1032
commit
0947261cf2
@ -409,9 +409,9 @@ usage! {
|
|||||||
"--jsonrpc-interface=[IP]",
|
"--jsonrpc-interface=[IP]",
|
||||||
"Specify the hostname portion of the HTTP JSON-RPC API server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
"Specify the hostname portion of the HTTP JSON-RPC API server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
||||||
|
|
||||||
ARG arg_jsonrpc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces", or |c: &Config| c.rpc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
ARG arg_jsonrpc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc", or |c: &Config| c.rpc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||||
"--jsonrpc-apis=[APIS]",
|
"--jsonrpc-apis=[APIS]",
|
||||||
"Specify the APIs available through the HTTP JSON-RPC interface using a comma-delimited list of API names. Possible names are: all, safe, debug, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
"Specify the APIs available through the HTTP JSON-RPC interface using a comma-delimited list of API names. Possible names are: all, safe, debug, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||||
|
|
||||||
ARG arg_jsonrpc_hosts: (String) = "none", or |c: &Config| c.rpc.as_ref()?.hosts.as_ref().map(|vec| vec.join(",")),
|
ARG arg_jsonrpc_hosts: (String) = "none", or |c: &Config| c.rpc.as_ref()?.hosts.as_ref().map(|vec| vec.join(",")),
|
||||||
"--jsonrpc-hosts=[HOSTS]",
|
"--jsonrpc-hosts=[HOSTS]",
|
||||||
@ -450,9 +450,9 @@ usage! {
|
|||||||
"--ws-interface=[IP]",
|
"--ws-interface=[IP]",
|
||||||
"Specify the hostname portion of the WebSockets JSON-RPC server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
"Specify the hostname portion of the WebSockets JSON-RPC server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
||||||
|
|
||||||
ARG arg_ws_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces", or |c: &Config| c.websockets.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
ARG arg_ws_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc", or |c: &Config| c.websockets.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||||
"--ws-apis=[APIS]",
|
"--ws-apis=[APIS]",
|
||||||
"Specify the JSON-RPC APIs available through the WebSockets interface using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
"Specify the JSON-RPC APIs available through the WebSockets interface using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||||
|
|
||||||
ARG arg_ws_origins: (String) = "parity://*,chrome-extension://*,moz-extension://*", or |c: &Config| c.websockets.as_ref()?.origins.as_ref().map(|vec| vec.join(",")),
|
ARG arg_ws_origins: (String) = "parity://*,chrome-extension://*,moz-extension://*", or |c: &Config| c.websockets.as_ref()?.origins.as_ref().map(|vec| vec.join(",")),
|
||||||
"--ws-origins=[URL]",
|
"--ws-origins=[URL]",
|
||||||
@ -492,9 +492,9 @@ usage! {
|
|||||||
"--ipc-path=[PATH]",
|
"--ipc-path=[PATH]",
|
||||||
"Specify custom path for JSON-RPC over IPC service.",
|
"Specify custom path for JSON-RPC over IPC service.",
|
||||||
|
|
||||||
ARG arg_ipc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces", or |c: &Config| c.ipc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
ARG arg_ipc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces,rpc", or |c: &Config| c.ipc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||||
"--ipc-apis=[APIS]",
|
"--ipc-apis=[APIS]",
|
||||||
"Specify custom API set available via JSON-RPC over IPC using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
"Specify custom API set available via JSON-RPC over IPC using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||||
|
|
||||||
["Secret Store Options"]
|
["Secret Store Options"]
|
||||||
FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable.clone(),
|
FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable.clone(),
|
||||||
@ -1312,7 +1312,7 @@ mod tests {
|
|||||||
arg_jsonrpc_port: 8545u16,
|
arg_jsonrpc_port: 8545u16,
|
||||||
arg_jsonrpc_interface: "local".into(),
|
arg_jsonrpc_interface: "local".into(),
|
||||||
arg_jsonrpc_cors: "null".into(),
|
arg_jsonrpc_cors: "null".into(),
|
||||||
arg_jsonrpc_apis: "web3,eth,net,parity,traces,secretstore".into(),
|
arg_jsonrpc_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(),
|
||||||
arg_jsonrpc_hosts: "none".into(),
|
arg_jsonrpc_hosts: "none".into(),
|
||||||
arg_jsonrpc_server_threads: None,
|
arg_jsonrpc_server_threads: None,
|
||||||
arg_jsonrpc_threads: 4,
|
arg_jsonrpc_threads: 4,
|
||||||
@ -1324,7 +1324,7 @@ mod tests {
|
|||||||
flag_no_ws: false,
|
flag_no_ws: false,
|
||||||
arg_ws_port: 8546u16,
|
arg_ws_port: 8546u16,
|
||||||
arg_ws_interface: "local".into(),
|
arg_ws_interface: "local".into(),
|
||||||
arg_ws_apis: "web3,eth,net,parity,traces,secretstore".into(),
|
arg_ws_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(),
|
||||||
arg_ws_origins: "none".into(),
|
arg_ws_origins: "none".into(),
|
||||||
arg_ws_hosts: "none".into(),
|
arg_ws_hosts: "none".into(),
|
||||||
arg_ws_max_connections: 100,
|
arg_ws_max_connections: 100,
|
||||||
@ -1333,7 +1333,7 @@ mod tests {
|
|||||||
// IPC
|
// IPC
|
||||||
flag_no_ipc: false,
|
flag_no_ipc: false,
|
||||||
arg_ipc_path: "$HOME/.parity/jsonrpc.ipc".into(),
|
arg_ipc_path: "$HOME/.parity/jsonrpc.ipc".into(),
|
||||||
arg_ipc_apis: "web3,eth,net,parity,parity_accounts,personal,traces,secretstore"
|
arg_ipc_apis: "web3,eth,net,parity,parity_accounts,personal,traces,rpc,secretstore"
|
||||||
.into(),
|
.into(),
|
||||||
|
|
||||||
// METRICS
|
// METRICS
|
||||||
|
@ -39,7 +39,7 @@ disable = false
|
|||||||
port = 8545
|
port = 8545
|
||||||
interface = "local"
|
interface = "local"
|
||||||
cors = ["null"]
|
cors = ["null"]
|
||||||
apis = ["web3", "eth", "net", "parity", "traces", "secretstore"]
|
apis = ["web3", "eth", "net", "parity", "traces", "rpc", "secretstore"]
|
||||||
hosts = ["none"]
|
hosts = ["none"]
|
||||||
allow_missing_blocks = false
|
allow_missing_blocks = false
|
||||||
|
|
||||||
@ -48,13 +48,13 @@ disable = false
|
|||||||
port = 8546
|
port = 8546
|
||||||
interface = "local"
|
interface = "local"
|
||||||
origins = ["none"]
|
origins = ["none"]
|
||||||
apis = ["web3", "eth", "net", "parity", "traces", "secretstore"]
|
apis = ["web3", "eth", "net", "parity", "traces", "rpc", "secretstore"]
|
||||||
hosts = ["none"]
|
hosts = ["none"]
|
||||||
|
|
||||||
[ipc]
|
[ipc]
|
||||||
disable = false
|
disable = false
|
||||||
path = "$HOME/.parity/jsonrpc.ipc"
|
path = "$HOME/.parity/jsonrpc.ipc"
|
||||||
apis = ["web3", "eth", "net", "parity", "parity_accounts", "personal", "traces", "secretstore"]
|
apis = ["web3", "eth", "net", "parity", "parity_accounts", "personal", "traces", "rpc", "secretstore"]
|
||||||
|
|
||||||
[secretstore]
|
[secretstore]
|
||||||
disable = false
|
disable = false
|
||||||
|
@ -1741,7 +1741,7 @@ mod tests {
|
|||||||
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
||||||
_ => panic!("Incorrect rpc apis"),
|
_ => panic!("Incorrect rpc apis"),
|
||||||
}
|
}
|
||||||
// "web3,eth,net,personal,parity,parity_set,traces,parity_accounts");
|
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
||||||
assert_eq!(c.http_conf.hosts, None);
|
assert_eq!(c.http_conf.hosts, None);
|
||||||
}
|
}
|
||||||
_ => panic!("Should be Cmd::Run"),
|
_ => panic!("Should be Cmd::Run"),
|
||||||
@ -1762,7 +1762,7 @@ mod tests {
|
|||||||
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
||||||
_ => panic!("Incorrect rpc apis"),
|
_ => panic!("Incorrect rpc apis"),
|
||||||
}
|
}
|
||||||
// "web3,eth,net,personal,parity,parity_set,traces,parity_accounts");
|
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
||||||
assert_eq!(c.http_conf.hosts, None);
|
assert_eq!(c.http_conf.hosts, None);
|
||||||
}
|
}
|
||||||
_ => panic!("Should be Cmd::Run"),
|
_ => panic!("Should be Cmd::Run"),
|
||||||
|
@ -14,7 +14,12 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::{cmp::PartialEq, collections::HashSet, str::FromStr, sync::Arc};
|
use std::{
|
||||||
|
cmp::PartialEq,
|
||||||
|
collections::{BTreeMap, HashSet},
|
||||||
|
str::FromStr,
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
pub use parity_rpc::signer::SignerService;
|
pub use parity_rpc::signer::SignerService;
|
||||||
|
|
||||||
@ -51,6 +56,8 @@ pub enum Api {
|
|||||||
Parity,
|
Parity,
|
||||||
/// Traces (Safe)
|
/// Traces (Safe)
|
||||||
Traces,
|
Traces,
|
||||||
|
/// Rpc (Safe)
|
||||||
|
Rpc,
|
||||||
/// Parity PubSub - Generic Publish-Subscriber (Safety depends on other APIs exposed).
|
/// Parity PubSub - Generic Publish-Subscriber (Safety depends on other APIs exposed).
|
||||||
ParityPubSub,
|
ParityPubSub,
|
||||||
/// Parity Accounts extensions (UNSAFE: Passwords, Side Effects (new account))
|
/// Parity Accounts extensions (UNSAFE: Passwords, Side Effects (new account))
|
||||||
@ -80,6 +87,7 @@ impl FromStr for Api {
|
|||||||
"parity_set" => Ok(ParitySet),
|
"parity_set" => Ok(ParitySet),
|
||||||
"personal" => Ok(Personal),
|
"personal" => Ok(Personal),
|
||||||
"pubsub" => Ok(EthPubSub),
|
"pubsub" => Ok(EthPubSub),
|
||||||
|
"rpc" => Ok(Rpc),
|
||||||
"secretstore" => Ok(SecretStore),
|
"secretstore" => Ok(SecretStore),
|
||||||
"signer" => Ok(Signer),
|
"signer" => Ok(Signer),
|
||||||
"traces" => Ok(Traces),
|
"traces" => Ok(Traces),
|
||||||
@ -146,6 +154,30 @@ impl FromStr for ApiSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_modules(apis: &HashSet<Api>) -> BTreeMap<String, String> {
|
||||||
|
let mut modules = BTreeMap::new();
|
||||||
|
for api in apis {
|
||||||
|
let (name, version) = match *api {
|
||||||
|
Api::Debug => ("debug", "1.0"),
|
||||||
|
Api::Eth => ("eth", "1.0"),
|
||||||
|
Api::EthPubSub => ("pubsub", "1.0"),
|
||||||
|
Api::Net => ("net", "1.0"),
|
||||||
|
Api::Parity => ("parity", "1.0"),
|
||||||
|
Api::ParityAccounts => ("parity_accounts", "1.0"),
|
||||||
|
Api::ParityPubSub => ("parity_pubsub", "1.0"),
|
||||||
|
Api::ParitySet => ("parity_set", "1.0"),
|
||||||
|
Api::Personal => ("personal", "1.0"),
|
||||||
|
Api::Rpc => ("rpc", "1.0"),
|
||||||
|
Api::SecretStore => ("secretstore", "1.0"),
|
||||||
|
Api::Signer => ("signer", "1.0"),
|
||||||
|
Api::Traces => ("traces", "1.0"),
|
||||||
|
Api::Web3 => ("web3", "1.0"),
|
||||||
|
};
|
||||||
|
modules.insert(name.into(), version.into());
|
||||||
|
}
|
||||||
|
modules
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! add_signing_methods {
|
macro_rules! add_signing_methods {
|
||||||
($namespace:ident, $handler:expr, $deps:expr, $dispatch:expr) => {{
|
($namespace:ident, $handler:expr, $deps:expr, $dispatch:expr) => {{
|
||||||
let deps = &$deps;
|
let deps = &$deps;
|
||||||
@ -376,6 +408,10 @@ impl FullDependencies {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Api::Traces => handler.extend_with(TracesClient::new(&self.client).to_delegate()),
|
Api::Traces => handler.extend_with(TracesClient::new(&self.client).to_delegate()),
|
||||||
|
Api::Rpc => {
|
||||||
|
let modules = to_modules(&apis);
|
||||||
|
handler.extend_with(RpcClient::new(modules).to_delegate());
|
||||||
|
}
|
||||||
Api::SecretStore => {
|
Api::SecretStore => {
|
||||||
#[cfg(feature = "accounts")]
|
#[cfg(feature = "accounts")]
|
||||||
handler.extend_with(SecretStoreClient::new(&self.accounts).to_delegate());
|
handler.extend_with(SecretStoreClient::new(&self.accounts).to_delegate());
|
||||||
@ -409,8 +445,14 @@ impl ApiSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_apis(&self) -> HashSet<Api> {
|
pub fn list_apis(&self) -> HashSet<Api> {
|
||||||
let mut public_list: HashSet<Api> =
|
let mut public_list: HashSet<Api> = [
|
||||||
[Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity]
|
Api::Web3,
|
||||||
|
Api::Net,
|
||||||
|
Api::Eth,
|
||||||
|
Api::EthPubSub,
|
||||||
|
Api::Parity,
|
||||||
|
Api::Rpc,
|
||||||
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
@ -470,6 +512,7 @@ mod test {
|
|||||||
assert_eq!(Api::ParityAccounts, "parity_accounts".parse().unwrap());
|
assert_eq!(Api::ParityAccounts, "parity_accounts".parse().unwrap());
|
||||||
assert_eq!(Api::ParitySet, "parity_set".parse().unwrap());
|
assert_eq!(Api::ParitySet, "parity_set".parse().unwrap());
|
||||||
assert_eq!(Api::Traces, "traces".parse().unwrap());
|
assert_eq!(Api::Traces, "traces".parse().unwrap());
|
||||||
|
assert_eq!(Api::Rpc, "rpc".parse().unwrap());
|
||||||
assert_eq!(Api::SecretStore, "secretstore".parse().unwrap());
|
assert_eq!(Api::SecretStore, "secretstore".parse().unwrap());
|
||||||
assert!("rp".parse::<Api>().is_err());
|
assert!("rp".parse::<Api>().is_err());
|
||||||
}
|
}
|
||||||
@ -498,6 +541,7 @@ mod test {
|
|||||||
Api::Parity,
|
Api::Parity,
|
||||||
Api::ParityPubSub,
|
Api::ParityPubSub,
|
||||||
Api::Traces,
|
Api::Traces,
|
||||||
|
Api::Rpc,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
@ -515,6 +559,7 @@ mod test {
|
|||||||
Api::Parity,
|
Api::Parity,
|
||||||
Api::ParityPubSub,
|
Api::ParityPubSub,
|
||||||
Api::Traces,
|
Api::Traces,
|
||||||
|
Api::Rpc,
|
||||||
// semi-safe
|
// semi-safe
|
||||||
Api::ParityAccounts,
|
Api::ParityAccounts,
|
||||||
]
|
]
|
||||||
@ -536,6 +581,7 @@ mod test {
|
|||||||
Api::Parity,
|
Api::Parity,
|
||||||
Api::ParityPubSub,
|
Api::ParityPubSub,
|
||||||
Api::Traces,
|
Api::Traces,
|
||||||
|
Api::Rpc,
|
||||||
Api::SecretStore,
|
Api::SecretStore,
|
||||||
Api::ParityAccounts,
|
Api::ParityAccounts,
|
||||||
Api::ParitySet,
|
Api::ParitySet,
|
||||||
@ -562,6 +608,7 @@ mod test {
|
|||||||
Api::Parity,
|
Api::Parity,
|
||||||
Api::ParityPubSub,
|
Api::ParityPubSub,
|
||||||
Api::Traces,
|
Api::Traces,
|
||||||
|
Api::Rpc,
|
||||||
Api::SecretStore,
|
Api::SecretStore,
|
||||||
Api::ParityAccounts,
|
Api::ParityAccounts,
|
||||||
Api::ParitySet,
|
Api::ParitySet,
|
||||||
@ -587,6 +634,7 @@ mod test {
|
|||||||
Api::Parity,
|
Api::Parity,
|
||||||
Api::ParityPubSub,
|
Api::ParityPubSub,
|
||||||
Api::Traces,
|
Api::Traces,
|
||||||
|
Api::Rpc,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -28,6 +28,7 @@ mod parity_set;
|
|||||||
#[cfg(any(test, feature = "accounts"))]
|
#[cfg(any(test, feature = "accounts"))]
|
||||||
mod personal;
|
mod personal;
|
||||||
mod pubsub;
|
mod pubsub;
|
||||||
|
mod rpc;
|
||||||
#[cfg(any(test, feature = "accounts"))]
|
#[cfg(any(test, feature = "accounts"))]
|
||||||
mod secretstore;
|
mod secretstore;
|
||||||
mod signer;
|
mod signer;
|
||||||
@ -53,6 +54,7 @@ pub use self::{
|
|||||||
parity::ParityClient,
|
parity::ParityClient,
|
||||||
parity_set::ParitySetClient,
|
parity_set::ParitySetClient,
|
||||||
pubsub::PubSubClient,
|
pubsub::PubSubClient,
|
||||||
|
rpc::RpcClient,
|
||||||
signer::SignerClient,
|
signer::SignerClient,
|
||||||
signing::SigningQueueClient,
|
signing::SigningQueueClient,
|
||||||
signing_unsafe::SigningUnsafeClient,
|
signing_unsafe::SigningUnsafeClient,
|
||||||
|
66
crates/rpc/src/v1/impls/rpc.rs
Normal file
66
crates/rpc/src/v1/impls/rpc.rs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of OpenEthereum.
|
||||||
|
|
||||||
|
// OpenEthereum 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.
|
||||||
|
|
||||||
|
// OpenEthereum 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 OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! RPC generic methods implementation.
|
||||||
|
use jsonrpc_core::Result;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use v1::traits::Rpc;
|
||||||
|
|
||||||
|
/// RPC generic methods implementation.
|
||||||
|
pub struct RpcClient {
|
||||||
|
modules: BTreeMap<String, String>,
|
||||||
|
valid_apis: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcClient {
|
||||||
|
/// Creates new `RpcClient`.
|
||||||
|
pub fn new(modules: BTreeMap<String, String>) -> Self {
|
||||||
|
// geth 1.3.6 fails upon receiving unknown api
|
||||||
|
let valid_apis = vec!["web3", "eth", "net", "personal", "rpc"];
|
||||||
|
|
||||||
|
RpcClient {
|
||||||
|
modules,
|
||||||
|
valid_apis: valid_apis.into_iter().map(ToOwned::to_owned).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rpc for RpcClient {
|
||||||
|
fn rpc_modules(&self) -> Result<BTreeMap<String, String>> {
|
||||||
|
let modules = self
|
||||||
|
.modules
|
||||||
|
.iter()
|
||||||
|
.fold(BTreeMap::new(), |mut map, (k, v)| {
|
||||||
|
map.insert(k.to_owned(), v.to_owned());
|
||||||
|
map
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(modules)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modules(&self) -> Result<BTreeMap<String, String>> {
|
||||||
|
let modules = self
|
||||||
|
.modules
|
||||||
|
.iter()
|
||||||
|
.filter(|&(k, _v)| self.valid_apis.contains(k))
|
||||||
|
.fold(BTreeMap::new(), |mut map, (k, v)| {
|
||||||
|
map.insert(k.to_owned(), v.to_owned());
|
||||||
|
map
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(modules)
|
||||||
|
}
|
||||||
|
}
|
@ -48,7 +48,7 @@ pub use self::{
|
|||||||
metadata::Metadata,
|
metadata::Metadata,
|
||||||
traits::{
|
traits::{
|
||||||
Debug, Eth, EthFilter, EthPubSub, EthSigning, Net, Parity, ParityAccounts,
|
Debug, Eth, EthFilter, EthPubSub, EthSigning, Net, Parity, ParityAccounts,
|
||||||
ParityAccountsInfo, ParitySet, ParitySetAccounts, ParitySigning, Personal, PubSub,
|
ParityAccountsInfo, ParitySet, ParitySetAccounts, ParitySigning, Personal, PubSub, Rpc,
|
||||||
SecretStore, Signer, Traces, Web3,
|
SecretStore, Signer, Traces, Web3,
|
||||||
},
|
},
|
||||||
types::Origin,
|
types::Origin,
|
||||||
|
@ -29,6 +29,7 @@ mod parity_set;
|
|||||||
#[cfg(any(test, feature = "accounts"))]
|
#[cfg(any(test, feature = "accounts"))]
|
||||||
mod personal;
|
mod personal;
|
||||||
mod pubsub;
|
mod pubsub;
|
||||||
|
mod rpc;
|
||||||
#[cfg(any(test, feature = "accounts"))]
|
#[cfg(any(test, feature = "accounts"))]
|
||||||
mod secretstore;
|
mod secretstore;
|
||||||
mod signer;
|
mod signer;
|
||||||
|
52
crates/rpc/src/v1/tests/mocked/rpc.rs
Normal file
52
crates/rpc/src/v1/tests/mocked/rpc.rs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of OpenEthereum.
|
||||||
|
|
||||||
|
// OpenEthereum 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.
|
||||||
|
|
||||||
|
// OpenEthereum 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 OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use jsonrpc_core::IoHandler;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use v1::{Rpc, RpcClient};
|
||||||
|
|
||||||
|
fn rpc_client() -> RpcClient {
|
||||||
|
let mut modules = BTreeMap::new();
|
||||||
|
modules.insert("rpc".to_owned(), "1.0".to_owned());
|
||||||
|
modules.insert("web3".to_owned(), "1.0".to_owned());
|
||||||
|
modules.insert("ethcore".to_owned(), "1.0".to_owned());
|
||||||
|
RpcClient::new(modules)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn modules() {
|
||||||
|
let rpc = rpc_client().to_delegate();
|
||||||
|
let mut io = IoHandler::new();
|
||||||
|
io.extend_with(rpc);
|
||||||
|
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "modules", "params": [], "id": 1}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":{"rpc":"1.0","web3":"1.0"},"id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rpc_modules() {
|
||||||
|
let rpc = rpc_client().to_delegate();
|
||||||
|
let mut io = IoHandler::new();
|
||||||
|
io.extend_with(rpc);
|
||||||
|
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "rpc_modules", "params": [], "id": 1}"#;
|
||||||
|
let response =
|
||||||
|
r#"{"jsonrpc":"2.0","result":{"ethcore":"1.0","rpc":"1.0","web3":"1.0"},"id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||||
|
}
|
@ -27,6 +27,7 @@ pub mod parity_set;
|
|||||||
pub mod parity_signing;
|
pub mod parity_signing;
|
||||||
pub mod personal;
|
pub mod personal;
|
||||||
pub mod pubsub;
|
pub mod pubsub;
|
||||||
|
pub mod rpc;
|
||||||
pub mod secretstore;
|
pub mod secretstore;
|
||||||
pub mod signer;
|
pub mod signer;
|
||||||
pub mod traces;
|
pub mod traces;
|
||||||
@ -44,6 +45,7 @@ pub use self::{
|
|||||||
parity_signing::ParitySigning,
|
parity_signing::ParitySigning,
|
||||||
personal::Personal,
|
personal::Personal,
|
||||||
pubsub::PubSub,
|
pubsub::PubSub,
|
||||||
|
rpc::Rpc,
|
||||||
secretstore::SecretStore,
|
secretstore::SecretStore,
|
||||||
signer::Signer,
|
signer::Signer,
|
||||||
traces::Traces,
|
traces::Traces,
|
||||||
|
36
crates/rpc/src/v1/traits/rpc.rs
Normal file
36
crates/rpc/src/v1/traits/rpc.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of OpenEthereum.
|
||||||
|
|
||||||
|
// OpenEthereum 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.
|
||||||
|
|
||||||
|
// OpenEthereum 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 OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! RPC interface.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use jsonrpc_core::Result;
|
||||||
|
use jsonrpc_derive::rpc;
|
||||||
|
|
||||||
|
/// RPC Interface.
|
||||||
|
#[rpc(server)]
|
||||||
|
pub trait Rpc {
|
||||||
|
/// Returns supported modules for Geth 1.3.6
|
||||||
|
/// @ignore
|
||||||
|
#[rpc(name = "modules")]
|
||||||
|
fn modules(&self) -> Result<BTreeMap<String, String>>;
|
||||||
|
|
||||||
|
/// Returns supported modules for Geth 1.4.0
|
||||||
|
/// @ignore
|
||||||
|
#[rpc(name = "rpc_modules")]
|
||||||
|
fn rpc_modules(&self) -> Result<BTreeMap<String, String>>;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user