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:
committed by
GitHub
parent
efb80e1032
commit
0947261cf2
@@ -28,6 +28,7 @@ mod parity_set;
|
||||
#[cfg(any(test, feature = "accounts"))]
|
||||
mod personal;
|
||||
mod pubsub;
|
||||
mod rpc;
|
||||
#[cfg(any(test, feature = "accounts"))]
|
||||
mod secretstore;
|
||||
mod signer;
|
||||
@@ -53,6 +54,7 @@ pub use self::{
|
||||
parity::ParityClient,
|
||||
parity_set::ParitySetClient,
|
||||
pubsub::PubSubClient,
|
||||
rpc::RpcClient,
|
||||
signer::SignerClient,
|
||||
signing::SigningQueueClient,
|
||||
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,
|
||||
traits::{
|
||||
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,
|
||||
},
|
||||
types::Origin,
|
||||
|
||||
@@ -29,6 +29,7 @@ mod parity_set;
|
||||
#[cfg(any(test, feature = "accounts"))]
|
||||
mod personal;
|
||||
mod pubsub;
|
||||
mod rpc;
|
||||
#[cfg(any(test, feature = "accounts"))]
|
||||
mod secretstore;
|
||||
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 personal;
|
||||
pub mod pubsub;
|
||||
pub mod rpc;
|
||||
pub mod secretstore;
|
||||
pub mod signer;
|
||||
pub mod traces;
|
||||
@@ -44,6 +45,7 @@ pub use self::{
|
||||
parity_signing::ParitySigning,
|
||||
personal::Personal,
|
||||
pubsub::PubSub,
|
||||
rpc::Rpc,
|
||||
secretstore::SecretStore,
|
||||
signer::Signer,
|
||||
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>>;
|
||||
}
|
||||
Reference in New Issue
Block a user