From 7610d308e83056dce4e1d0961c1d8562d0f26637 Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 14 Jun 2016 15:17:17 +0200 Subject: [PATCH] fixed #1255 --- rpc/src/v1/impls/eth.rs | 11 ++++++++++- rpc/src/v1/tests/mocked/eth.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index b0d6abcf0..ac123c565 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -212,6 +212,7 @@ fn from_params_default_third(params: Params) -> Result<(F1, F2, BlockNum // must be in range [-32099, -32000] const UNSUPPORTED_REQUEST_CODE: i64 = -32000; +const NO_WORK_CODE: i64 = -32001; fn make_unsupported_err() -> Error { Error { @@ -221,6 +222,14 @@ fn make_unsupported_err() -> Error { } } +fn no_work_err() -> Error { + Error { + code: ErrorCode::ServerError(NO_WORK_CODE), + message: "Mining not ready.".into(), + data: None + } +} + impl Eth for EthClient where C: MiningBlockChainClient + 'static, S: SyncProvider + 'static, @@ -460,7 +469,7 @@ impl Eth for EthClient where //let sync = take_weak!(self.sync); if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); - return to_value(&(String::new(), String::new(), String::new())); + return Err(no_work_err()); } } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 34708e232..801a74f1d 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -732,7 +732,7 @@ fn returns_no_work_if_cant_mine() { eth_tester.client.set_queue_size(10); let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Mining not ready.","data":null},"id":1}"#; assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned())); }