Add error for sendRawTransaction and estimateGas (#3194)
* sendRawTransaction invalid RLP error * Returning proper error for estimate_gas
This commit is contained in:
parent
2563189316
commit
501b2cdd18
@ -21,6 +21,7 @@ macro_rules! rpc_unimplemented {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use rlp::DecoderError;
|
||||||
use ethcore::error::{Error as EthcoreError, CallError};
|
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;
|
||||||
@ -271,6 +272,14 @@ pub fn from_transaction_error(error: EthcoreError) -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_rlp_error(error: DecoderError) -> Error {
|
||||||
|
Error {
|
||||||
|
code: ErrorCode::InvalidParams,
|
||||||
|
message: "Invalid RLP.".into(),
|
||||||
|
data: Some(Value::String(format!("{:?}", error))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_call_error(error: CallError) -> Error {
|
pub fn from_call_error(error: CallError) -> Error {
|
||||||
match error {
|
match error {
|
||||||
CallError::StatePruned => state_pruned(),
|
CallError::StatePruned => state_pruned(),
|
||||||
|
@ -611,7 +611,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
|||||||
let raw_transaction = raw.to_vec();
|
let raw_transaction = raw.to_vec();
|
||||||
match UntrustedRlp::new(&raw_transaction).as_val() {
|
match UntrustedRlp::new(&raw_transaction).as_val() {
|
||||||
Ok(signed_transaction) => dispatch_transaction(&*take_weak!(self.client), &*take_weak!(self.miner), signed_transaction),
|
Ok(signed_transaction) => dispatch_transaction(&*take_weak!(self.client), &*take_weak!(self.miner), signed_transaction),
|
||||||
Err(_) => Ok(RpcH256::from(H256::from(0))),
|
Err(e) => Err(errors::from_rlp_error(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,15 +621,15 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
|||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try!(self.sign_call(request));
|
let signed = try!(self.sign_call(request));
|
||||||
|
|
||||||
let r = match num.0 {
|
let result = match num.0 {
|
||||||
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||||
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
||||||
};
|
};
|
||||||
|
|
||||||
match r {
|
|
||||||
Ok(b) => Ok(Bytes(b.output)),
|
result
|
||||||
Err(e) => Err(errors::from_call_error(e)),
|
.map(|b| b.output.into())
|
||||||
}
|
.map_err(errors::from_call_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> Result<RpcU256, Error> {
|
fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> Result<RpcU256, Error> {
|
||||||
@ -637,12 +637,14 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
|||||||
|
|
||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try!(self.sign_call(request));
|
let signed = try!(self.sign_call(request));
|
||||||
let r = match num.0 {
|
let result = match num.0 {
|
||||||
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||||
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))))
|
result
|
||||||
|
.map(|res| (res.gas_used + res.refunded).into())
|
||||||
|
.map_err(errors::from_call_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_lll(&self, _: String) -> Result<Bytes, Error> {
|
fn compile_lll(&self, _: String) -> Result<Bytes, Error> {
|
||||||
|
@ -805,6 +805,23 @@ fn rpc_eth_send_transaction_error() {
|
|||||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rpc_eth_send_raw_transaction_error() {
|
||||||
|
let tester = EthTester::default();
|
||||||
|
|
||||||
|
let req = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "eth_sendRawTransaction",
|
||||||
|
"params": [
|
||||||
|
"0x0123"
|
||||||
|
],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
let res = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid RLP.","data":"RlpIncorrectListLen"},"id":1}"#.into();
|
||||||
|
|
||||||
|
assert_eq!(tester.io.handle_request_sync(&req), Some(res));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_eth_send_raw_transaction() {
|
fn rpc_eth_send_raw_transaction() {
|
||||||
let tester = EthTester::default();
|
let tester = EthTester::default();
|
||||||
|
Loading…
Reference in New Issue
Block a user