From 62e37aef8faa2182a58bcf55e9596d738b9d7e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 7 Jun 2016 13:01:37 +0200 Subject: [PATCH 1/5] Splitting RPC Apis into more fine-grained sets --- 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 bb67ee5c6..750deab8f 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -75,14 +75,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 b54693582..eaa2da7d9 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).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 54be63eaf..c640d113d 100644 --- a/signer/src/ws_server/session.rs +++ b/signer/src/ws_server/session.rs @@ -53,7 +53,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) { - 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 @@ -77,7 +77,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())); From 5397da0c93a4d42900f1feb578b79cb1fc78ecec Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jun 2016 12:30:35 -0700 Subject: [PATCH 2/5] Remove old code/comment. --- ethcore/src/block.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 0b75f5a7e..c10542866 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -38,23 +38,7 @@ pub struct Block { impl Block { /// Returns true if the given bytes form a valid encoding of a block in RLP. - // TODO: implement Decoder for this and have this use that. pub fn is_good(b: &[u8]) -> bool { - /* - let urlp = UntrustedRlp::new(&b); - if !urlp.is_list() || urlp.item_count() != 3 || urlp.size() != b.len() { return false; } - if urlp.val_at::
(0).is_err() { return false; } - - if !urlp.at(1).unwrap().is_list() { return false; } - if urlp.at(1).unwrap().iter().find(|i| i.as_val::().is_err()).is_some() { - return false; - } - - if !urlp.at(2).unwrap().is_list() { return false; } - if urlp.at(2).unwrap().iter().find(|i| i.as_val::
().is_err()).is_some() { - return false; - } - true*/ UntrustedRlp::new(b).as_val::().is_ok() } } From 446c9096f4025c92084bf3ce475603e81bc4567a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jun 2016 12:30:44 -0700 Subject: [PATCH 3/5] Add test for VMTrace ser. --- rpc/src/v1/types/trace.rs | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 5b4192886..60d1e5d74 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -446,6 +446,49 @@ mod tests { assert_eq!(serialized, r#"{"action":{"call":{"from":"0x0000000000000000000000000000000000000004","to":"0x0000000000000000000000000000000000000005","value":"0x06","gas":"0x07","input":"0x1234"}},"result":{"call":{"gasUsed":"0x08","output":"0x5678"}},"traceAddress":["0x0a"],"subtraces":"0x01","transactionPosition":"0x0b","transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":"0x0d","blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); } + #[test] + fn test_vmtrace_serialize() { + let t = VMTrace { + code: vec![0, 1, 2, 3], + ops: vec![ + VMOperation { + pc: 0, + cost: 10, + ex: None, + sub: None, + }, + VMOperation { + pc: 1, + cost: 11, + ex: Some(VMExecutedOperation { + used: 10, + push: vec![69.into()], + mem: None, + store: None, + }), + sub: Some(VMTrace { + code: vec![0], + ops: vec![ + VMOperation { + pc: 0, + cost: 0, + ex: Some(VMExecutedOperation { + used: 10, + push: vec![42.into()], + mem: Some(MemoryDiff {off: 42, data: vec![1, 2, 3]}), + store: Some(StorageDiff {key: 69.into(), val: 42.into()}), + }), + sub: None, + } + ] + }), + } + ] + }; + let serialized = serde_json::to_string(&t).unwrap(); + assert_eq!(serialized, "{\"code\":[0,1,2,3],\"ops\":[{\"pc\":0,\"cost\":10,\"ex\":null,\"sub\":null},{\"pc\":1,\"cost\":11,\"ex\":{\"used\":10,\"push\":[\"0x45\"],\"mem\":null,\"store\":null},\"sub\":{\"code\":[0],\"ops\":[{\"pc\":0,\"cost\":0,\"ex\":{\"used\":10,\"push\":[\"0x2a\"],\"mem\":{\"off\":42,\"data\":[1,2,3]},\"store\":{\"key\":\"0x45\",\"val\":\"0x2a\"}},\"sub\":null}]}}]}"); + } + #[test] fn test_action_serialize() { let actions = vec![Action::Call(Call { From c5d8f5e1361193e311c2e81d7e47953b91b17445 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jun 2016 12:44:57 -0700 Subject: [PATCH 4/5] Add StateDiff ser test. --- rpc/src/v1/types/trace.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 60d1e5d74..12bcfa1cc 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -417,6 +417,7 @@ impl From for Trace { #[cfg(test)] mod tests { use serde_json; + use std::collections::BTreeMap; use util::{U256, H256, Address}; use v1::types::Bytes; use super::*; @@ -489,6 +490,28 @@ mod tests { assert_eq!(serialized, "{\"code\":[0,1,2,3],\"ops\":[{\"pc\":0,\"cost\":10,\"ex\":null,\"sub\":null},{\"pc\":1,\"cost\":11,\"ex\":{\"used\":10,\"push\":[\"0x45\"],\"mem\":null,\"store\":null},\"sub\":{\"code\":[0],\"ops\":[{\"pc\":0,\"cost\":0,\"ex\":{\"used\":10,\"push\":[\"0x2a\"],\"mem\":{\"off\":42,\"data\":[1,2,3]},\"store\":{\"key\":\"0x45\",\"val\":\"0x2a\"}},\"sub\":null}]}}]}"); } + #[test] + fn test_statediff_serialize() { + let t = StateDiff(map![ + 42.into() => AccountDiff { + balance: Diff::Same, + nonce: Diff::Born(1.into()), + code: Diff::Same, + storage: map![ + 42.into() => Diff::Same + ] + }, + 69.into() => AccountDiff { + balance: Diff::Same, + nonce: Diff::Changed(ChangedType { from: 1.into(), to: 0.into() }), + code: Diff::Died(vec![96].into()), + storage: map![], + } + ]); + let serialized = serde_json::to_string(&t).unwrap(); + assert_eq!(serialized, "{\"0x000000000000000000000000000000000000002a\":{\"balance\":{\"=\":[]},\"nonce\":{\"+\":\"0x01\"},\"code\":{\"=\":[]},\"storage\":{\"0x000000000000000000000000000000000000000000000000000000000000002a\":{\"=\":[]}}},\"0x0000000000000000000000000000000000000045\":{\"balance\":{\"=\":[]},\"nonce\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x00\"}},\"code\":{\"-\":\"0x60\"},\"storage\":{}}}"); + } + #[test] fn test_action_serialize() { let actions = vec![Action::Call(Call { From 2e56fbad2c4276084dc03a2885b695525a845fc4 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 8 Jun 2016 12:41:29 -0700 Subject: [PATCH 5/5] Use nicer strings for tests. --- rpc/src/v1/types/trace.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 12bcfa1cc..d6226aea0 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -487,7 +487,7 @@ mod tests { ] }; let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, "{\"code\":[0,1,2,3],\"ops\":[{\"pc\":0,\"cost\":10,\"ex\":null,\"sub\":null},{\"pc\":1,\"cost\":11,\"ex\":{\"used\":10,\"push\":[\"0x45\"],\"mem\":null,\"store\":null},\"sub\":{\"code\":[0],\"ops\":[{\"pc\":0,\"cost\":0,\"ex\":{\"used\":10,\"push\":[\"0x2a\"],\"mem\":{\"off\":42,\"data\":[1,2,3]},\"store\":{\"key\":\"0x45\",\"val\":\"0x2a\"}},\"sub\":null}]}}]}"); + assert_eq!(serialized, r#"{"code":[0,1,2,3],"ops":[{"pc":0,"cost":10,"ex":null,"sub":null},{"pc":1,"cost":11,"ex":{"used":10,"push":["0x45"],"mem":null,"store":null},"sub":{"code":[0],"ops":[{"pc":0,"cost":0,"ex":{"used":10,"push":["0x2a"],"mem":{"off":42,"data":[1,2,3]},"store":{"key":"0x45","val":"0x2a"}},"sub":null}]}}]}"#); } #[test] @@ -509,7 +509,7 @@ mod tests { } ]); let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, "{\"0x000000000000000000000000000000000000002a\":{\"balance\":{\"=\":[]},\"nonce\":{\"+\":\"0x01\"},\"code\":{\"=\":[]},\"storage\":{\"0x000000000000000000000000000000000000000000000000000000000000002a\":{\"=\":[]}}},\"0x0000000000000000000000000000000000000045\":{\"balance\":{\"=\":[]},\"nonce\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x00\"}},\"code\":{\"-\":\"0x60\"},\"storage\":{}}}"); + assert_eq!(serialized, r#"{"0x000000000000000000000000000000000000002a":{"balance":{"=":[]},"nonce":{"+":"0x01"},"code":{"=":[]},"storage":{"0x000000000000000000000000000000000000000000000000000000000000002a":{"=":[]}}},"0x0000000000000000000000000000000000000045":{"balance":{"=":[]},"nonce":{"*":{"from":"0x01","to":"0x00"}},"code":{"-":"0x60"},"storage":{}}}"#); } #[test]