From be435cde99e0f804ecbe16aad7ea7d762a1a5106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 7 Jun 2016 22:52:48 +0200 Subject: [PATCH] Splitting RPC Apis into more fine-grained sets (#1234) --- parity/cli.rs | 6 +-- parity/rpc_apis.rs | 25 +++++++--- rpc/src/v1/impls/ethcore.rs | 37 +------------- rpc/src/v1/impls/ethcore_set.rs | 78 ++++++++++++++++++++++++++++++ rpc/src/v1/impls/mod.rs | 2 + rpc/src/v1/mod.rs | 2 +- rpc/src/v1/tests/mocked/ethcore.rs | 71 ++++++++++++++------------- rpc/src/v1/traits/ethcore.rs | 20 -------- rpc/src/v1/traits/ethcore_set.rs | 51 +++++++++++++++++++ rpc/src/v1/traits/mod.rs | 2 + signer/src/ws_server/session.rs | 4 +- 11 files changed, 195 insertions(+), 103 deletions(-) create mode 100644 rpc/src/v1/impls/ethcore_set.rs create mode 100644 rpc/src/v1/traits/ethcore_set.rs diff --git a/parity/cli.rs b/parity/cli.rs index fbaa8bd89..0b3c96c55 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -76,14 +76,14 @@ API and Console Options: --jsonrpc-apis APIS Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API name. Possible name are web3, eth, net, personal, - ethcore, traces. - [default: web3,eth,net,personal,traces]. + ethcore, ethcore_set, traces. + [default: web3,eth,net,ethcore,personal,traces]. --ipc-off Disable JSON-RPC over IPC service. --ipc-path PATH Specify custom path for JSON-RPC over IPC service [default: $HOME/.parity/jsonrpc.ipc]. --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-port PORT Specify the port portion of the Dapps server diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 34dd3a387..a061b8e1b 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -40,7 +40,9 @@ pub enum Api { Net, Eth, Personal, + Signer, Ethcore, + EthcoreSet, Traces, Rpc, } @@ -66,7 +68,9 @@ impl FromStr for Api { "net" => Ok(Net), "eth" => Ok(Eth), "personal" => Ok(Personal), + "signer" => Ok(Signer), "ethcore" => Ok(Ethcore), + "ethcore_set" => Ok(EthcoreSet), "traces" => Ok(Traces), "rpc" => Ok(Rpc), e => Err(ApiError::UnknownApi(e.into())), @@ -94,7 +98,9 @@ fn to_modules(apis: &[Api]) -> BTreeMap { Api::Net => ("net", "1.0"), Api::Eth => ("eth", "1.0"), Api::Personal => ("personal", "1.0"), + Api::Signer => ("signer", "1.0"), Api::Ethcore => ("ethcore", "1.0"), + Api::EthcoreSet => ("ethcore_set", "1.0"), Api::Traces => ("traces", "1.0"), Api::Rpc => ("rpc", "1.0"), }; @@ -115,12 +121,12 @@ pub fn from_str(apis: Vec<&str>) -> Vec { fn list_apis(apis: ApiSet, signer_enabled: bool) -> Vec { match apis { ApiSet::List(apis) => apis, - ApiSet::UnsafeContext if signer_enabled => { - vec![Api::Web3, Api::Net, Api::Eth, Api::Ethcore, Api::Traces, Api::Rpc] - } + ApiSet::UnsafeContext => { + 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(server: T, deps: Arc, apis: ApiSet }, Api::Personal => { server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.signer_enabled).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 => { 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 => { server.add_delegate(TracesClient::new(&deps.client, &deps.miner).to_delegate()) }, diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index df88657d9..b3fe894c6 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . //! Ethcore-specific rpc implementation. -use util::{U256, Address, RotatingLogger}; +use util::RotatingLogger; use util::network_settings::NetworkSettings; use util::misc::version_data; use std::sync::{Arc, Weak}; @@ -48,41 +48,6 @@ impl EthcoreClient where M: MinerService { impl Ethcore for EthcoreClient where M: MinerService + 'static { - fn set_min_gas_price(&self, params: Params) -> Result { - 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 { - 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 { - 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 { - 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 { - from_params::<(usize,)>(params).and_then(|(limit,)| { - take_weak!(self.miner).set_transactions_limit(limit); - to_value(&true) - }) - } - fn transactions_limit(&self, _: Params) -> Result { to_value(&take_weak!(self.miner).transactions_limit()) } diff --git a/rpc/src/v1/impls/ethcore_set.rs b/rpc/src/v1/impls/ethcore_set.rs new file mode 100644 index 000000000..b07dcbf9e --- /dev/null +++ b/rpc/src/v1/impls/ethcore_set.rs @@ -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 . + +/// 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 where + M: MinerService { + + miner: Weak, +} + +impl EthcoreSetClient where M: MinerService { + /// Creates new `EthcoreSetClient`. + pub fn new(miner: &Arc) -> Self { + EthcoreSetClient { + miner: Arc::downgrade(miner), + } + } +} + +impl EthcoreSet for EthcoreSetClient where M: MinerService + 'static { + + fn set_min_gas_price(&self, params: Params) -> Result { + 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 { + 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 { + 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 { + 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 { + from_params::<(usize,)>(params).and_then(|(limit,)| { + take_weak!(self.miner).set_transactions_limit(limit); + to_value(&true) + }) + } + +} diff --git a/rpc/src/v1/impls/mod.rs b/rpc/src/v1/impls/mod.rs index 9e154a1c5..7fdf57249 100644 --- a/rpc/src/v1/impls/mod.rs +++ b/rpc/src/v1/impls/mod.rs @@ -37,6 +37,7 @@ mod net; mod personal; mod personal_signer; mod ethcore; +mod ethcore_set; mod traces; mod rpc; @@ -48,6 +49,7 @@ pub use self::net::NetClient; pub use self::personal::PersonalClient; pub use self::personal_signer::SignerClient; pub use self::ethcore::EthcoreClient; +pub use self::ethcore_set::EthcoreSetClient; pub use self::traces::TracesClient; pub use self::rpc::RpcClient; diff --git a/rpc/src/v1/mod.rs b/rpc/src/v1/mod.rs index 54628d892..b4d3693f3 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -25,6 +25,6 @@ pub mod traits; pub mod tests; 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::helpers::{SigningQueue, ConfirmationsQueue}; diff --git a/rpc/src/v1/tests/mocked/ethcore.rs b/rpc/src/v1/tests/mocked/ethcore.rs index 1685a598b..90103adef 100644 --- a/rpc/src/v1/tests/mocked/ethcore.rs +++ b/rpc/src/v1/tests/mocked/ethcore.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::str::FromStr; use jsonrpc_core::IoHandler; -use v1::{Ethcore, EthcoreClient}; +use v1::{Ethcore, EthcoreClient, EthcoreSet, EthcoreSetClient}; use ethcore::miner::MinerService; use v1::tests::helpers::TestMinerService; use util::numbers::*; @@ -49,12 +49,16 @@ fn ethcore_client(miner: &Arc) -> EthcoreClient) -> EthcoreSetClient { + EthcoreSetClient::new(&miner) +} + #[test] fn rpc_ethcore_extra_data() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#; @@ -68,9 +72,9 @@ fn rpc_ethcore_default_extra_data() { use util::ToPretty; let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 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] fn rpc_ethcore_gas_floor_target() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#; @@ -94,9 +98,9 @@ fn rpc_ethcore_gas_floor_target() { #[test] fn rpc_ethcore_min_gas_price() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#; @@ -107,9 +111,9 @@ fn rpc_ethcore_min_gas_price() { #[test] fn rpc_ethcore_set_min_gas_price() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; @@ -121,9 +125,9 @@ fn rpc_ethcore_set_min_gas_price() { #[test] fn rpc_ethcore_set_gas_floor_target() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; @@ -135,9 +139,9 @@ fn rpc_ethcore_set_gas_floor_target() { #[test] fn rpc_ethcore_set_extra_data() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; @@ -149,9 +153,9 @@ fn rpc_ethcore_set_extra_data() { #[test] fn rpc_ethcore_set_author() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 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 io = IoHandler::new(); 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 response = r#"{"jsonrpc":"2.0","result":["b","a"],"id":1}"#; @@ -179,9 +184,9 @@ fn rpc_ethcore_dev_logs() { #[test] fn rpc_ethcore_dev_logs_levels() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#; @@ -191,9 +196,9 @@ fn rpc_ethcore_dev_logs_levels() { #[test] fn rpc_ethcore_set_transactions_limit() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; @@ -205,9 +210,9 @@ fn rpc_ethcore_set_transactions_limit() { #[test] fn rpc_ethcore_transactions_limit() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#; @@ -218,9 +223,9 @@ fn rpc_ethcore_transactions_limit() { #[test] fn rpc_ethcore_net_chain() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#; @@ -231,9 +236,9 @@ fn rpc_ethcore_net_chain() { #[test] fn rpc_ethcore_net_max_peers() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":25,"id":1}"#; @@ -244,9 +249,9 @@ fn rpc_ethcore_net_max_peers() { #[test] fn rpc_ethcore_net_port() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#; @@ -257,9 +262,9 @@ fn rpc_ethcore_net_port() { #[test] fn rpc_ethcore_rpc_settings() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#; @@ -270,9 +275,9 @@ fn rpc_ethcore_rpc_settings() { #[test] fn rpc_ethcore_node_name() { let miner = miner_service(); - let ethcore = ethcore_client(&miner).to_delegate(); 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 response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#; diff --git a/rpc/src/v1/traits/ethcore.rs b/rpc/src/v1/traits/ethcore.rs index a0e12222a..4ce3eca59 100644 --- a/rpc/src/v1/traits/ethcore.rs +++ b/rpc/src/v1/traits/ethcore.rs @@ -21,21 +21,6 @@ use jsonrpc_core::*; /// Ethcore-specific rpc interface. pub trait Ethcore: Sized + Send + Sync + 'static { - /// Sets new minimal gas price for mined blocks. - fn set_min_gas_price(&self, _: Params) -> Result; - - /// Sets new gas floor target for mined blocks. - fn set_gas_floor_target(&self, _: Params) -> Result; - - /// Sets new extra data for mined blocks. - fn set_extra_data(&self, _: Params) -> Result; - - /// Sets new author for mined block. - fn set_author(&self, _: Params) -> Result; - - /// Sets the limits for transaction queue. - fn set_transactions_limit(&self, _: Params) -> Result; - /// Returns current transactions limit. fn transactions_limit(&self, _: Params) -> Result; @@ -75,11 +60,6 @@ pub trait Ethcore: Sized + Send + Sync + 'static { /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { 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_gasFloorTarget", Ethcore::gas_floor_target); diff --git a/rpc/src/v1/traits/ethcore_set.rs b/rpc/src/v1/traits/ethcore_set.rs new file mode 100644 index 000000000..332c505b6 --- /dev/null +++ b/rpc/src/v1/traits/ethcore_set.rs @@ -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 . + +//! 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; + + /// Sets new gas floor target for mined blocks. + fn set_gas_floor_target(&self, _: Params) -> Result; + + /// Sets new extra data for mined blocks. + fn set_extra_data(&self, _: Params) -> Result; + + /// Sets new author for mined block. + fn set_author(&self, _: Params) -> Result; + + /// Sets the limits for transaction queue. + fn set_transactions_limit(&self, _: Params) -> Result; + + /// Should be used to convert object to io delegate. + fn to_delegate(self) -> IoDelegate { + 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 + } +} diff --git a/rpc/src/v1/traits/mod.rs b/rpc/src/v1/traits/mod.rs index d994ffc24..3ca11b654 100644 --- a/rpc/src/v1/traits/mod.rs +++ b/rpc/src/v1/traits/mod.rs @@ -21,6 +21,7 @@ pub mod eth; pub mod net; pub mod personal; pub mod ethcore; +pub mod ethcore_set; pub mod traces; pub mod rpc; @@ -29,6 +30,7 @@ pub use self::eth::{Eth, EthFilter, EthSigning}; pub use self::net::Net; pub use self::personal::{Personal, PersonalSigner}; pub use self::ethcore::Ethcore; +pub use self::ethcore_set::EthcoreSet; pub use self::traces::Traces; pub use self::rpc::Rpc; diff --git a/signer/src/ws_server/session.rs b/signer/src/ws_server/session.rs index 153bf6622..8cc3f5d07 100644 --- a/signer/src/ws_server/session.rs +++ b/signer/src/ws_server/session.rs @@ -77,7 +77,7 @@ impl ws::Handler for Session { // Check request origin and host header. if !origin_is_allowed(&self.self_origin, origin) && !origin_is_allowed(&self.self_origin, host) { warn!(target: "signer", "Blocked connection to Signer API from untrusted origin."); - 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))); } // Detect if it's a websocket request. @@ -108,7 +108,7 @@ impl ws::Handler for Session { let mut res = ws::Response::ok(f.content.into()); { 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(("Content-Length".into(), content_len.as_bytes().to_vec())); headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec()));