Deprecate eth_compile* RPCs (#4577)

* Deprecate eth_compile* RPCs

* Add deprecation doc comments
This commit is contained in:
Robert Habermeier 2017-02-17 12:00:33 +01:00 committed by Gav Wood
parent aca808b021
commit 54c48d14ec
4 changed files with 23 additions and 55 deletions

View File

@ -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<String>) -> Error {
@ -92,14 +92,6 @@ pub fn account<T: fmt::Debug>(error: &str, details: T) -> Error {
}
}
pub fn compilation<T: fmt::Debug>(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<T: fmt::Debug>(error: &str, data: T) -> Error {
Error {
code: ErrorCode::InternalError,
@ -317,3 +309,11 @@ pub fn no_light_peers() -> Error {
data: None,
}
}
pub fn deprecated<T: Into<Option<String>>>(message: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::DEPRECATED),
message: "Method deprecated".into(),
data: message.into().map(Value::String),
}
}

View File

@ -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<C>(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<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
C: MiningBlockChainClient + 'static,
SN: SnapshotService + 'static,
@ -509,12 +501,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
}
fn compilers(&self) -> Result<Vec<String>, 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<Vec<Log>, Error> {
@ -642,37 +629,14 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
}
fn compile_lll(&self, _: String) -> Result<Bytes, Error> {
rpc_unimplemented!()
Err(errors::deprecated("Compilation of LLL via RPC is deprecated".to_string()))
}
fn compile_serpent(&self, _: String) -> Result<Bytes, Error> {
rpc_unimplemented!()
Err(errors::deprecated("Compilation of Serpent via RPC is deprecated".to_string()))
}
fn compile_solidity(&self, code: String) -> Result<Bytes, Error> {
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<Bytes, Error> {
Err(errors::deprecated("Compilation of Solidity via RPC is deprecated".to_string()))
}
}

View File

@ -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()));
}

View File

@ -142,18 +142,22 @@ build_rpc_trait! {
fn uncle_by_block_number_and_index(&self, BlockNumber, Index) -> Result<Option<RichBlock>, Error>;
/// Returns available compilers.
/// @deprecated
#[rpc(name = "eth_getCompilers")]
fn compilers(&self) -> Result<Vec<String>, Error>;
/// Compiles lll code.
/// @deprecated
#[rpc(name = "eth_compileLLL")]
fn compile_lll(&self, String) -> Result<Bytes, Error>;
/// Compiles solidity.
/// @deprecated
#[rpc(name = "eth_compileSolidity")]
fn compile_solidity(&self, String) -> Result<Bytes, Error>;
/// Compiles serpent.
/// @deprecated
#[rpc(name = "eth_compileSerpent")]
fn compile_serpent(&self, String) -> Result<Bytes, Error>;