Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub fn filter_not_found() -> Error {
pub fn filter_block_not_found(id: BlockId) -> Error {
Error {
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST), // Specified in EIP-234.
message: "One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found".into(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer having a separate message for that error, something like that:

pub fn filter_block_error(id: BlockId, msg: &str) -> Error {
	Error {
		code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST), // Specified in EIP-234.
		message: msg.into(),
		data: Some(Value::String(match id {
			BlockId::Hash(hash) => format!("0x{:x}", hash),
			BlockId::Number(number) => format!("0x{:x}", number),
			BlockId::Earliest => "earliest".to_string(),
			BlockId::Latest => "latest".to_string(),
		})),
	}
}
pub fn filter_block_not_found(id: BlockId) -> Error {
	filter_block_error(id, "One of ...")
}
pub fn filter_block_out_of_order(id: BlockId) -> Error {
	filter_block_error(id, "fromBlock and toBlock are out of order")
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a custom error type in ethcore, and we cannot use ? syntax any more for the Client::logs function. Not sure it would worth it or not, but let me give a try.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would indeed need some amounts of change in Client error types, or we would need to duplicate the checks in Client::logs in RPC again (which I don't think is a good idea). For the former, I think it may be better to fix this together with a Client and Blockchain struct error type overhaul, so that we can preserve using ? syntax there. So I'm going to temporarily close this.

I created an issue #9373.

message: "One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found, or fromBlock and toBlock are out of order".into(),
data: Some(Value::String(match id {
BlockId::Hash(hash) => format!("0x{:x}", hash),
BlockId::Number(number) => format!("0x{:x}", number),
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn rpc_eth_logs_error() {
let tester = EthTester::default();
tester.client.set_error_on_logs(Some(BlockId::Hash(H256::from([5u8].as_ref()))));
let request = r#"{"jsonrpc": "2.0", "method": "eth_getLogs", "params": [{"limit":1,"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found","data":"0x0500000000000000000000000000000000000000000000000000000000000000"},"id":1}"#;
let response = r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found, or fromBlock and toBlock are out of order","data":"0x0500000000000000000000000000000000000000000000000000000000000000"},"id":1}"#;
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

Expand Down