Return error in case eth_call returns VM errors (#8448)
* Add VMError generator * Return executed exceptions in eth_call
This commit is contained in:
parent
650948feed
commit
c983efe895
@ -24,6 +24,7 @@ use jsonrpc_core::{futures, Error, ErrorCode, Value};
|
|||||||
use rlp::DecoderError;
|
use rlp::DecoderError;
|
||||||
use transaction::Error as TransactionError;
|
use transaction::Error as TransactionError;
|
||||||
use ethcore_private_tx::Error as PrivateTransactionError;
|
use ethcore_private_tx::Error as PrivateTransactionError;
|
||||||
|
use vm::Error as VMError;
|
||||||
|
|
||||||
mod codes {
|
mod codes {
|
||||||
// NOTE [ToDr] Codes from [-32099, -32000]
|
// NOTE [ToDr] Codes from [-32099, -32000]
|
||||||
@ -375,6 +376,21 @@ pub fn call(error: CallError) -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vm(error: &VMError, output: &[u8]) -> Error {
|
||||||
|
use rustc_hex::ToHex;
|
||||||
|
|
||||||
|
let data = match error {
|
||||||
|
&VMError::Reverted => format!("{} 0x{}", VMError::Reverted, output.to_hex()),
|
||||||
|
error => format!("{}", error),
|
||||||
|
};
|
||||||
|
|
||||||
|
Error {
|
||||||
|
code: ErrorCode::ServerError(codes::EXECUTION_ERROR),
|
||||||
|
message: "VM execution error.".into(),
|
||||||
|
data: Some(Value::String(data)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unknown_block() -> Error {
|
pub fn unknown_block() -> Error {
|
||||||
Error {
|
Error {
|
||||||
code: ErrorCode::InvalidParams,
|
code: ErrorCode::InvalidParams,
|
||||||
|
@ -859,8 +859,14 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
|
|||||||
let result = self.client.call(&signed, Default::default(), &mut state, &header);
|
let result = self.client.call(&signed, Default::default(), &mut state, &header);
|
||||||
|
|
||||||
Box::new(future::done(result
|
Box::new(future::done(result
|
||||||
.map(|b| b.output.into())
|
|
||||||
.map_err(errors::call)
|
.map_err(errors::call)
|
||||||
|
.and_then(|executed| {
|
||||||
|
match executed.exception {
|
||||||
|
Some(ref exception) => Err(errors::vm(exception, &executed.output)),
|
||||||
|
None => Ok(executed)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|b| b.output.into())
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user