From 54c48d14eceeae96e5120a1dda42161972a0be3f Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Fri, 17 Feb 2017 12:00:33 +0100 Subject: [PATCH] Deprecate eth_compile* RPCs (#4577) * Deprecate eth_compile* RPCs * Add deprecation doc comments --- rpc/src/v1/helpers/errors.rs | 18 ++++++------- rpc/src/v1/impls/eth.rs | 48 +++++----------------------------- rpc/src/v1/tests/mocked/eth.rs | 8 +++--- rpc/src/v1/traits/eth.rs | 4 +++ 4 files changed, 23 insertions(+), 55 deletions(-) diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index b58999f84..93d23b1aa 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -46,10 +46,10 @@ mod codes { pub const REQUEST_REJECTED: i64 = -32040; pub const REQUEST_REJECTED_LIMIT: i64 = -32041; pub const REQUEST_NOT_FOUND: i64 = -32042; - pub const COMPILATION_ERROR: i64 = -32050; pub const ENCRYPTION_ERROR: i64 = -32055; pub const FETCH_ERROR: i64 = -32060; pub const NO_LIGHT_PEERS: i64 = -32065; + pub const DEPRECATED: i64 = -32070; } pub fn unimplemented(details: Option) -> Error { @@ -92,14 +92,6 @@ pub fn account(error: &str, details: T) -> Error { } } -pub fn compilation(error: T) -> Error { - Error { - code: ErrorCode::ServerError(codes::COMPILATION_ERROR), - message: "Error while compiling code.".into(), - data: Some(Value::String(format!("{:?}", error))), - } -} - pub fn internal(error: &str, data: T) -> Error { Error { code: ErrorCode::InternalError, @@ -317,3 +309,11 @@ pub fn no_light_peers() -> Error { data: None, } } + +pub fn deprecated>>(message: T) -> Error { + Error { + code: ErrorCode::ServerError(codes::DEPRECATED), + message: "Method deprecated".into(), + data: message.into().map(Value::String), + } +} diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index d763db836..9ad8196fe 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -16,8 +16,6 @@ //! Eth rpc implementation. -use std::io::{Write}; -use std::process::{Command, Stdio}; use std::thread; use std::time::{Instant, Duration}; use std::sync::{Arc, Weak}; @@ -27,7 +25,7 @@ use rlp::{self, UntrustedRlp, View}; use time::get_time; use util::{H160, H256, Address, FixedHash, U256, H64, Uint}; use util::sha3::Hashable; -use util::{FromHex, Mutex}; +use util::Mutex; use ethash::SeedHashCompute; use ethcore::account_provider::{AccountProvider, DappId}; @@ -258,12 +256,6 @@ fn check_known(client: &C, number: BlockNumber) -> Result<(), Error> where C: const MAX_QUEUE_SIZE_TO_MINE_ON: usize = 4; // because uncles go back 6. -#[cfg(windows)] -static SOLC: &'static str = "solc.exe"; - -#[cfg(not(windows))] -static SOLC: &'static str = "solc"; - impl Eth for EthClient where C: MiningBlockChainClient + 'static, SN: SnapshotService + 'static, @@ -509,12 +501,7 @@ impl Eth for EthClient where } fn compilers(&self) -> Result, Error> { - let mut compilers = vec![]; - if Command::new(SOLC).output().is_ok() { - compilers.push("solidity".to_owned()) - } - - Ok(compilers) + Err(errors::deprecated("Compilation functionality is deprecated.".to_string())) } fn logs(&self, filter: Filter) -> Result, Error> { @@ -642,37 +629,14 @@ impl Eth for EthClient where } fn compile_lll(&self, _: String) -> Result { - rpc_unimplemented!() + Err(errors::deprecated("Compilation of LLL via RPC is deprecated".to_string())) } fn compile_serpent(&self, _: String) -> Result { - rpc_unimplemented!() + Err(errors::deprecated("Compilation of Serpent via RPC is deprecated".to_string())) } - fn compile_solidity(&self, code: String) -> Result { - let maybe_child = Command::new(SOLC) - .arg("--bin") - .arg("--optimize") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn(); - - maybe_child - .map_err(errors::compilation) - .and_then(|mut child| { - child.stdin.as_mut() - .expect("we called child.stdin(Stdio::piped()) before spawn; qed") - .write_all(code.as_bytes()) - .map_err(errors::compilation)?; - let output = child.wait_with_output().map_err(errors::compilation)?; - - let s = String::from_utf8_lossy(&output.stdout); - if let Some(hex) = s.lines().skip_while(|ref l| !l.contains("Binary")).skip(1).next() { - Ok(Bytes::new(hex.from_hex().unwrap_or(vec![]))) - } else { - Err(errors::compilation("Unexpected output.")) - } - }) + fn compile_solidity(&self, _: String) -> Result { + Err(errors::deprecated("Compilation of Solidity via RPC is deprecated".to_string())) } } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 3b668b030..40ae8c38c 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -1020,7 +1020,7 @@ fn rpc_eth_transaction_receipt_null() { #[test] fn rpc_eth_compilers() { let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32070,"message":"Method deprecated","data":"Compilation functionality is deprecated."},"id":1}"#; assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned())); } @@ -1029,7 +1029,7 @@ fn rpc_eth_compilers() { #[test] fn rpc_eth_compile_lll() { let request = r#"{"jsonrpc": "2.0", "method": "eth_compileLLL", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32070,"message":"Method deprecated","data":"Compilation of LLL via RPC is deprecated"},"id":1}"#; assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned())); } @@ -1038,7 +1038,7 @@ fn rpc_eth_compile_lll() { #[test] fn rpc_eth_compile_solidity() { let request = r#"{"jsonrpc": "2.0", "method": "eth_compileSolidity", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32070,"message":"Method deprecated","data":"Compilation of Solidity via RPC is deprecated"},"id":1}"#; assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned())); } @@ -1047,7 +1047,7 @@ fn rpc_eth_compile_solidity() { #[test] fn rpc_eth_compile_serpent() { let request = r#"{"jsonrpc": "2.0", "method": "eth_compileSerpent", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32070,"message":"Method deprecated","data":"Compilation of Serpent via RPC is deprecated"},"id":1}"#; assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned())); } diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index a50188bf0..eaf608c60 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -142,18 +142,22 @@ build_rpc_trait! { fn uncle_by_block_number_and_index(&self, BlockNumber, Index) -> Result, Error>; /// Returns available compilers. + /// @deprecated #[rpc(name = "eth_getCompilers")] fn compilers(&self) -> Result, Error>; /// Compiles lll code. + /// @deprecated #[rpc(name = "eth_compileLLL")] fn compile_lll(&self, String) -> Result; /// Compiles solidity. + /// @deprecated #[rpc(name = "eth_compileSolidity")] fn compile_solidity(&self, String) -> Result; /// Compiles serpent. + /// @deprecated #[rpc(name = "eth_compileSerpent")] fn compile_serpent(&self, String) -> Result;