Return errors from eth_call RPC (#2498)
* propagate call errors * add error code for execution error
This commit is contained in:
parent
d6cad29f49
commit
271bcf4d5d
@ -21,7 +21,7 @@ macro_rules! rpc_unimplemented {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use ethcore::error::Error as EthcoreError;
|
use ethcore::error::{Error as EthcoreError, CallError};
|
||||||
use ethcore::account_provider::{Error as AccountError};
|
use ethcore::account_provider::{Error as AccountError};
|
||||||
use fetch::FetchError;
|
use fetch::FetchError;
|
||||||
use jsonrpc_core::{Error, ErrorCode, Value};
|
use jsonrpc_core::{Error, ErrorCode, Value};
|
||||||
@ -34,6 +34,7 @@ mod codes {
|
|||||||
pub const NO_NEW_WORK: i64 = -32003;
|
pub const NO_NEW_WORK: i64 = -32003;
|
||||||
pub const UNKNOWN_ERROR: i64 = -32009;
|
pub const UNKNOWN_ERROR: i64 = -32009;
|
||||||
pub const TRANSACTION_ERROR: i64 = -32010;
|
pub const TRANSACTION_ERROR: i64 = -32010;
|
||||||
|
pub const EXECUTION_ERROR: i64 = -32015;
|
||||||
pub const ACCOUNT_LOCKED: i64 = -32020;
|
pub const ACCOUNT_LOCKED: i64 = -32020;
|
||||||
pub const PASSWORD_INVALID: i64 = -32021;
|
pub const PASSWORD_INVALID: i64 = -32021;
|
||||||
pub const ACCOUNT_ERROR: i64 = -32023;
|
pub const ACCOUNT_ERROR: i64 = -32023;
|
||||||
@ -109,6 +110,14 @@ pub fn invalid_params<T: fmt::Debug>(param: &str, details: T) -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn execution<T: fmt::Debug>(data: T) -> Error {
|
||||||
|
Error {
|
||||||
|
code: ErrorCode::ServerError(codes::EXECUTION_ERROR),
|
||||||
|
message: "Transaction execution error.".into(),
|
||||||
|
data: Some(Value::String(format!("{:?}", data))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn state_pruned() -> Error {
|
pub fn state_pruned() -> Error {
|
||||||
Error {
|
Error {
|
||||||
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
|
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
|
||||||
@ -219,4 +228,10 @@ pub fn from_transaction_error(error: EthcoreError) -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_call_error(error: CallError) -> Error {
|
||||||
|
match error {
|
||||||
|
CallError::StatePruned => state_pruned(),
|
||||||
|
CallError::Execution(e) => execution(e),
|
||||||
|
CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -593,7 +593,10 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![])))
|
match r {
|
||||||
|
Ok(b) => Ok(Bytes(b.output)),
|
||||||
|
Err(e) => Err(errors::from_call_error(e)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> Result<RpcU256, Error> {
|
fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> Result<RpcU256, Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user