Splitting RPC Apis into more fine-grained sets

This commit is contained in:
Tomasz Drwięga 2016-06-07 13:01:37 +02:00
parent e408b7ac99
commit 62e37aef8f
11 changed files with 195 additions and 103 deletions

View File

@ -75,14 +75,14 @@ API and Console Options:
--jsonrpc-apis APIS Specify the APIs available through the JSONRPC --jsonrpc-apis APIS Specify the APIs available through the JSONRPC
interface. APIS is a comma-delimited list of API interface. APIS is a comma-delimited list of API
name. Possible name are web3, eth, net, personal, name. Possible name are web3, eth, net, personal,
ethcore, traces. ethcore, ethcore_set, traces.
[default: web3,eth,net,personal,traces]. [default: web3,eth,net,ethcore,personal,traces].
--ipc-off Disable JSON-RPC over IPC service. --ipc-off Disable JSON-RPC over IPC service.
--ipc-path PATH Specify custom path for JSON-RPC over IPC service --ipc-path PATH Specify custom path for JSON-RPC over IPC service
[default: $HOME/.parity/jsonrpc.ipc]. [default: $HOME/.parity/jsonrpc.ipc].
--ipc-apis APIS Specify custom API set available via JSON-RPC over --ipc-apis APIS Specify custom API set available via JSON-RPC over
IPC [default: web3,eth,net,personal,traces]. IPC [default: web3,eth,net,ethcore,personal,traces].
--dapps-off Disable the Dapps server (e.g. status page). --dapps-off Disable the Dapps server (e.g. status page).
--dapps-port PORT Specify the port portion of the Dapps server --dapps-port PORT Specify the port portion of the Dapps server

View File

@ -40,7 +40,9 @@ pub enum Api {
Net, Net,
Eth, Eth,
Personal, Personal,
Signer,
Ethcore, Ethcore,
EthcoreSet,
Traces, Traces,
Rpc, Rpc,
} }
@ -66,7 +68,9 @@ impl FromStr for Api {
"net" => Ok(Net), "net" => Ok(Net),
"eth" => Ok(Eth), "eth" => Ok(Eth),
"personal" => Ok(Personal), "personal" => Ok(Personal),
"signer" => Ok(Signer),
"ethcore" => Ok(Ethcore), "ethcore" => Ok(Ethcore),
"ethcore_set" => Ok(EthcoreSet),
"traces" => Ok(Traces), "traces" => Ok(Traces),
"rpc" => Ok(Rpc), "rpc" => Ok(Rpc),
e => Err(ApiError::UnknownApi(e.into())), e => Err(ApiError::UnknownApi(e.into())),
@ -94,7 +98,9 @@ fn to_modules(apis: &[Api]) -> BTreeMap<String, String> {
Api::Net => ("net", "1.0"), Api::Net => ("net", "1.0"),
Api::Eth => ("eth", "1.0"), Api::Eth => ("eth", "1.0"),
Api::Personal => ("personal", "1.0"), Api::Personal => ("personal", "1.0"),
Api::Signer => ("signer", "1.0"),
Api::Ethcore => ("ethcore", "1.0"), Api::Ethcore => ("ethcore", "1.0"),
Api::EthcoreSet => ("ethcore_set", "1.0"),
Api::Traces => ("traces", "1.0"), Api::Traces => ("traces", "1.0"),
Api::Rpc => ("rpc", "1.0"), Api::Rpc => ("rpc", "1.0"),
}; };
@ -115,12 +121,12 @@ pub fn from_str(apis: Vec<&str>) -> Vec<Api> {
fn list_apis(apis: ApiSet, signer_enabled: bool) -> Vec<Api> { fn list_apis(apis: ApiSet, signer_enabled: bool) -> Vec<Api> {
match apis { match apis {
ApiSet::List(apis) => apis, ApiSet::List(apis) => apis,
ApiSet::UnsafeContext if signer_enabled => { ApiSet::UnsafeContext => {
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::EthcoreSet, Api::Traces, Api::Rpc]
} },
_ => { _ => {
vec![Api::Web3, Api::Net, Api::Eth, Api::Personal, Api::Ethcore, Api::Traces, Api::Rpc] vec![Api::Web3, Api::Net, Api::Eth, Api::Personal, Api::Signer, Api::Ethcore, Api::EthcoreSet, Api::Traces, Api::Rpc]
} },
} }
} }
@ -148,13 +154,16 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
}, },
Api::Personal => { Api::Personal => {
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate()); server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate());
if deps.signer_enabled { },
server.add_delegate(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_queue).to_delegate()); Api::Signer => {
} server.add_delegate(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_queue).to_delegate());
}, },
Api::Ethcore => { Api::Ethcore => {
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate()) server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate())
}, },
Api::EthcoreSet => {
server.add_delegate(EthcoreSetClient::new(&deps.miner).to_delegate())
},
Api::Traces => { Api::Traces => {
server.add_delegate(TracesClient::new(&deps.client, &deps.miner).to_delegate()) server.add_delegate(TracesClient::new(&deps.client, &deps.miner).to_delegate())
}, },

View File

@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Ethcore-specific rpc implementation. //! Ethcore-specific rpc implementation.
use util::{U256, Address, RotatingLogger}; use util::RotatingLogger;
use util::network_settings::NetworkSettings; use util::network_settings::NetworkSettings;
use util::misc::version_data; use util::misc::version_data;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
@ -48,41 +48,6 @@ impl<M> EthcoreClient<M> where M: MinerService {
impl<M> Ethcore for EthcoreClient<M> where M: MinerService + 'static { impl<M> Ethcore for EthcoreClient<M> where M: MinerService + 'static {
fn set_min_gas_price(&self, params: Params) -> Result<Value, Error> {
from_params::<(U256,)>(params).and_then(|(gas_price,)| {
take_weak!(self.miner).set_minimal_gas_price(gas_price);
to_value(&true)
})
}
fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> {
from_params::<(U256,)>(params).and_then(|(gas_floor_target,)| {
take_weak!(self.miner).set_gas_floor_target(gas_floor_target);
to_value(&true)
})
}
fn set_extra_data(&self, params: Params) -> Result<Value, Error> {
from_params::<(Bytes,)>(params).and_then(|(extra_data,)| {
take_weak!(self.miner).set_extra_data(extra_data.to_vec());
to_value(&true)
})
}
fn set_author(&self, params: Params) -> Result<Value, Error> {
from_params::<(Address,)>(params).and_then(|(author,)| {
take_weak!(self.miner).set_author(author);
to_value(&true)
})
}
fn set_transactions_limit(&self, params: Params) -> Result<Value, Error> {
from_params::<(usize,)>(params).and_then(|(limit,)| {
take_weak!(self.miner).set_transactions_limit(limit);
to_value(&true)
})
}
fn transactions_limit(&self, _: Params) -> Result<Value, Error> { fn transactions_limit(&self, _: Params) -> Result<Value, Error> {
to_value(&take_weak!(self.miner).transactions_limit()) to_value(&take_weak!(self.miner).transactions_limit())
} }

View File

@ -0,0 +1,78 @@
// 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/>.
/// Ethcore-specific rpc interface for operations altering the settings.
use util::{U256, Address};
use std::sync::{Arc, Weak};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use v1::traits::EthcoreSet;
use v1::types::{Bytes};
/// Ethcore-specific rpc interface for operations altering the settings.
pub struct EthcoreSetClient<M> where
M: MinerService {
miner: Weak<M>,
}
impl<M> EthcoreSetClient<M> where M: MinerService {
/// Creates new `EthcoreSetClient`.
pub fn new(miner: &Arc<M>) -> Self {
EthcoreSetClient {
miner: Arc::downgrade(miner),
}
}
}
impl<M> EthcoreSet for EthcoreSetClient<M> where M: MinerService + 'static {
fn set_min_gas_price(&self, params: Params) -> Result<Value, Error> {
from_params::<(U256,)>(params).and_then(|(gas_price,)| {
take_weak!(self.miner).set_minimal_gas_price(gas_price);
to_value(&true)
})
}
fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> {
from_params::<(U256,)>(params).and_then(|(gas_floor_target,)| {
take_weak!(self.miner).set_gas_floor_target(gas_floor_target);
to_value(&true)
})
}
fn set_extra_data(&self, params: Params) -> Result<Value, Error> {
from_params::<(Bytes,)>(params).and_then(|(extra_data,)| {
take_weak!(self.miner).set_extra_data(extra_data.to_vec());
to_value(&true)
})
}
fn set_author(&self, params: Params) -> Result<Value, Error> {
from_params::<(Address,)>(params).and_then(|(author,)| {
take_weak!(self.miner).set_author(author);
to_value(&true)
})
}
fn set_transactions_limit(&self, params: Params) -> Result<Value, Error> {
from_params::<(usize,)>(params).and_then(|(limit,)| {
take_weak!(self.miner).set_transactions_limit(limit);
to_value(&true)
})
}
}

View File

@ -37,6 +37,7 @@ mod net;
mod personal; mod personal;
mod personal_signer; mod personal_signer;
mod ethcore; mod ethcore;
mod ethcore_set;
mod traces; mod traces;
mod rpc; mod rpc;
@ -48,6 +49,7 @@ pub use self::net::NetClient;
pub use self::personal::PersonalClient; pub use self::personal::PersonalClient;
pub use self::personal_signer::SignerClient; pub use self::personal_signer::SignerClient;
pub use self::ethcore::EthcoreClient; pub use self::ethcore::EthcoreClient;
pub use self::ethcore_set::EthcoreSetClient;
pub use self::traces::TracesClient; pub use self::traces::TracesClient;
pub use self::rpc::RpcClient; pub use self::rpc::RpcClient;

View File

@ -25,6 +25,6 @@ pub mod traits;
pub mod tests; pub mod tests;
pub mod types; pub mod types;
pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Personal, PersonalSigner, Net, Ethcore, Traces, Rpc}; pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Personal, PersonalSigner, Net, Ethcore, EthcoreSet, Traces, Rpc};
pub use self::impls::*; pub use self::impls::*;
pub use self::helpers::{SigningQueue, ConfirmationsQueue}; pub use self::helpers::{SigningQueue, ConfirmationsQueue};

View File

@ -17,7 +17,7 @@
use std::sync::Arc; use std::sync::Arc;
use std::str::FromStr; use std::str::FromStr;
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
use v1::{Ethcore, EthcoreClient}; use v1::{Ethcore, EthcoreClient, EthcoreSet, EthcoreSetClient};
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use util::numbers::*; use util::numbers::*;
@ -49,12 +49,16 @@ fn ethcore_client(miner: &Arc<TestMinerService>) -> EthcoreClient<TestMinerServi
EthcoreClient::new(&miner, logger(), settings()) EthcoreClient::new(&miner, logger(), settings())
} }
fn ethcore_set_client(miner: &Arc<TestMinerService>) -> EthcoreSetClient<TestMinerService> {
EthcoreSetClient::new(&miner)
}
#[test] #[test]
fn rpc_ethcore_extra_data() { fn rpc_ethcore_extra_data() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#;
@ -68,9 +72,9 @@ fn rpc_ethcore_default_extra_data() {
use util::ToPretty; use util::ToPretty;
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#;
let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex()); let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex());
@ -81,9 +85,9 @@ fn rpc_ethcore_default_extra_data() {
#[test] #[test]
fn rpc_ethcore_gas_floor_target() { fn rpc_ethcore_gas_floor_target() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#;
@ -94,9 +98,9 @@ fn rpc_ethcore_gas_floor_target() {
#[test] #[test]
fn rpc_ethcore_min_gas_price() { fn rpc_ethcore_min_gas_price() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#;
@ -107,9 +111,9 @@ fn rpc_ethcore_min_gas_price() {
#[test] #[test]
fn rpc_ethcore_set_min_gas_price() { fn rpc_ethcore_set_min_gas_price() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setMinGasPrice", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setMinGasPrice", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@ -121,9 +125,9 @@ fn rpc_ethcore_set_min_gas_price() {
#[test] #[test]
fn rpc_ethcore_set_gas_floor_target() { fn rpc_ethcore_set_gas_floor_target() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setGasFloorTarget", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setGasFloorTarget", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@ -135,9 +139,9 @@ fn rpc_ethcore_set_gas_floor_target() {
#[test] #[test]
fn rpc_ethcore_set_extra_data() { fn rpc_ethcore_set_extra_data() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setExtraData", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setExtraData", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@ -149,9 +153,9 @@ fn rpc_ethcore_set_extra_data() {
#[test] #[test]
fn rpc_ethcore_set_author() { fn rpc_ethcore_set_author() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setAuthor", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setAuthor", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@ -169,6 +173,7 @@ fn rpc_ethcore_dev_logs() {
let ethcore = EthcoreClient::new(&miner, logger.clone(), settings()).to_delegate(); let ethcore = EthcoreClient::new(&miner, logger.clone(), settings()).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogs", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogs", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":["b","a"],"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":["b","a"],"id":1}"#;
@ -179,9 +184,9 @@ fn rpc_ethcore_dev_logs() {
#[test] #[test]
fn rpc_ethcore_dev_logs_levels() { fn rpc_ethcore_dev_logs_levels() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#;
@ -191,9 +196,9 @@ fn rpc_ethcore_dev_logs_levels() {
#[test] #[test]
fn rpc_ethcore_set_transactions_limit() { fn rpc_ethcore_set_transactions_limit() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setTransactionsLimit", "params":[10240240], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setTransactionsLimit", "params":[10240240], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@ -205,9 +210,9 @@ fn rpc_ethcore_set_transactions_limit() {
#[test] #[test]
fn rpc_ethcore_transactions_limit() { fn rpc_ethcore_transactions_limit() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
@ -218,9 +223,9 @@ fn rpc_ethcore_transactions_limit() {
#[test] #[test]
fn rpc_ethcore_net_chain() { fn rpc_ethcore_net_chain() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#;
@ -231,9 +236,9 @@ fn rpc_ethcore_net_chain() {
#[test] #[test]
fn rpc_ethcore_net_max_peers() { fn rpc_ethcore_net_max_peers() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netMaxPeers", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netMaxPeers", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":25,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":25,"id":1}"#;
@ -244,9 +249,9 @@ fn rpc_ethcore_net_max_peers() {
#[test] #[test]
fn rpc_ethcore_net_port() { fn rpc_ethcore_net_port() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#;
@ -257,9 +262,9 @@ fn rpc_ethcore_net_port() {
#[test] #[test]
fn rpc_ethcore_rpc_settings() { fn rpc_ethcore_rpc_settings() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#;
@ -270,9 +275,9 @@ fn rpc_ethcore_rpc_settings() {
#[test] #[test]
fn rpc_ethcore_node_name() { fn rpc_ethcore_node_name() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#; let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#;

View File

@ -21,21 +21,6 @@ use jsonrpc_core::*;
/// Ethcore-specific rpc interface. /// Ethcore-specific rpc interface.
pub trait Ethcore: Sized + Send + Sync + 'static { pub trait Ethcore: Sized + Send + Sync + 'static {
/// Sets new minimal gas price for mined blocks.
fn set_min_gas_price(&self, _: Params) -> Result<Value, Error>;
/// Sets new gas floor target for mined blocks.
fn set_gas_floor_target(&self, _: Params) -> Result<Value, Error>;
/// Sets new extra data for mined blocks.
fn set_extra_data(&self, _: Params) -> Result<Value, Error>;
/// Sets new author for mined block.
fn set_author(&self, _: Params) -> Result<Value, Error>;
/// Sets the limits for transaction queue.
fn set_transactions_limit(&self, _: Params) -> Result<Value, Error>;
/// Returns current transactions limit. /// Returns current transactions limit.
fn transactions_limit(&self, _: Params) -> Result<Value, Error>; fn transactions_limit(&self, _: Params) -> Result<Value, Error>;
@ -75,11 +60,6 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
/// Should be used to convert object to io delegate. /// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> { fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self)); let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("ethcore_setMinGasPrice", Ethcore::set_min_gas_price);
delegate.add_method("ethcore_setGasFloorTarget", Ethcore::set_gas_floor_target);
delegate.add_method("ethcore_setExtraData", Ethcore::set_extra_data);
delegate.add_method("ethcore_setAuthor", Ethcore::set_author);
delegate.add_method("ethcore_setTransactionsLimit", Ethcore::set_transactions_limit);
delegate.add_method("ethcore_extraData", Ethcore::extra_data); delegate.add_method("ethcore_extraData", Ethcore::extra_data);
delegate.add_method("ethcore_gasFloorTarget", Ethcore::gas_floor_target); delegate.add_method("ethcore_gasFloorTarget", Ethcore::gas_floor_target);

View File

@ -0,0 +1,51 @@
// 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/>.
//! Ethcore-specific rpc interface for operations altering the settings.
use std::sync::Arc;
use jsonrpc_core::*;
/// Ethcore-specific rpc interface for operations altering the settings.
pub trait EthcoreSet: Sized + Send + Sync + 'static {
/// Sets new minimal gas price for mined blocks.
fn set_min_gas_price(&self, _: Params) -> Result<Value, Error>;
/// Sets new gas floor target for mined blocks.
fn set_gas_floor_target(&self, _: Params) -> Result<Value, Error>;
/// Sets new extra data for mined blocks.
fn set_extra_data(&self, _: Params) -> Result<Value, Error>;
/// Sets new author for mined block.
fn set_author(&self, _: Params) -> Result<Value, Error>;
/// Sets the limits for transaction queue.
fn set_transactions_limit(&self, _: Params) -> Result<Value, Error>;
/// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("ethcore_setMinGasPrice", EthcoreSet::set_min_gas_price);
delegate.add_method("ethcore_setGasFloorTarget", EthcoreSet::set_gas_floor_target);
delegate.add_method("ethcore_setExtraData", EthcoreSet::set_extra_data);
delegate.add_method("ethcore_setAuthor", EthcoreSet::set_author);
delegate.add_method("ethcore_setTransactionsLimit", EthcoreSet::set_transactions_limit);
delegate
}
}

View File

@ -21,6 +21,7 @@ pub mod eth;
pub mod net; pub mod net;
pub mod personal; pub mod personal;
pub mod ethcore; pub mod ethcore;
pub mod ethcore_set;
pub mod traces; pub mod traces;
pub mod rpc; pub mod rpc;
@ -29,6 +30,7 @@ pub use self::eth::{Eth, EthFilter, EthSigning};
pub use self::net::Net; pub use self::net::Net;
pub use self::personal::{Personal, PersonalSigner}; pub use self::personal::{Personal, PersonalSigner};
pub use self::ethcore::Ethcore; pub use self::ethcore::Ethcore;
pub use self::ethcore_set::EthcoreSet;
pub use self::traces::Traces; pub use self::traces::Traces;
pub use self::rpc::Rpc; pub use self::rpc::Rpc;

View File

@ -53,7 +53,7 @@ impl ws::Handler for Session {
// Check request origin and host header. // Check request origin and host header.
if !origin_is_allowed(&self.self_origin, origin) && !origin_is_allowed(&self.self_origin, host) { if !origin_is_allowed(&self.self_origin, origin) && !origin_is_allowed(&self.self_origin, host) {
return Ok(ws::Response::forbidden("You are not allowed to access system ui.".into())); return Ok(ws::Response::forbidden(format!("You are not allowed to access system ui. Use: http://{}", self.self_origin)));
} }
// Check authorization // Check authorization
@ -77,7 +77,7 @@ impl ws::Handler for Session {
let mut res = ws::Response::ok(f.content.into()); let mut res = ws::Response::ok(f.content.into());
{ {
let mut headers = res.headers_mut(); let mut headers = res.headers_mut();
headers.push(("Server".into(), b"Parity/SystemUI".to_vec())); headers.push(("Server".into(), b"Parity/SignerUI".to_vec()));
headers.push(("Connection".into(), b"Closed".to_vec())); headers.push(("Connection".into(), b"Closed".to_vec()));
headers.push(("Content-Length".into(), content_len.as_bytes().to_vec())); headers.push(("Content-Length".into(), content_len.as_bytes().to_vec()));
headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec())); headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec()));