Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Return error in case eth_call returns VM errors (#8448)
Browse files Browse the repository at this point in the history
* Add VMError generator

* Return executed exceptions in eth_call
  • Loading branch information
sorpaas authored and 5chdn committed Apr 21, 2018
1 parent 650948f commit c983efe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use jsonrpc_core::{futures, Error, ErrorCode, Value};
use rlp::DecoderError;
use transaction::Error as TransactionError;
use ethcore_private_tx::Error as PrivateTransactionError;
use vm::Error as VMError;

mod codes {
// NOTE [ToDr] Codes from [-32099, -32000]
Expand Down Expand Up @@ -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 {
Error {
code: ErrorCode::InvalidParams,
Expand Down
8 changes: 7 additions & 1 deletion rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Box::new(future::done(result
.map(|b| b.output.into())
.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())
))
}

Expand Down

0 comments on commit c983efe

Please sign in to comment.