From d1487b31770fdd511bb5d9a539f014ff41d8ea85 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 10 Apr 2018 16:36:14 +0800 Subject: [PATCH] rpc, eth_filter: return error if the filter id does not exist (#8341) --- rpc/src/v1/helpers/errors.rs | 8 ++++++++ rpc/src/v1/impls/eth_filter.rs | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index e86ab630f..6e8836c20 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -399,6 +399,14 @@ pub fn deprecated>>(message: T) -> Error { } } +pub fn filter_not_found() -> Error { + Error { + code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST), + message: "Filter not found".into(), + data: None, + } +} + // on-demand sender cancelled. pub fn on_demand_cancel(_cancel: futures::sync::oneshot::Canceled) -> Error { internal("on-demand sender cancelled", "") diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 6c3d6837e..9e2f2f888 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -30,7 +30,7 @@ use jsonrpc_core::futures::{future, Future}; use jsonrpc_core::futures::future::Either; use v1::traits::EthFilter; use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256}; -use v1::helpers::{PollFilter, PollManager, limit_logs}; +use v1::helpers::{errors, PollFilter, PollManager, limit_logs}; use v1::impls::eth::pending_logs; /// Something which provides data that can be filtered over. @@ -127,7 +127,7 @@ impl EthFilter for T { fn filter_changes(&self, index: Index) -> BoxFuture { let mut polls = self.polls().lock(); Box::new(match polls.poll_mut(&index.value()) { - None => Either::A(future::ok(FilterChanges::Empty)), + None => Either::A(future::err(errors::filter_not_found())), Some(filter) => match *filter { PollFilter::Block(ref mut block_number) => { // +1, cause we want to return hashes including current block hash. @@ -217,7 +217,8 @@ impl EthFilter for T { match polls.poll(&index.value()) { Some(&PollFilter::Logs(ref _block_number, ref _previous_log, ref filter)) => filter.clone(), // just empty array - _ => return Box::new(future::ok(Vec::new())), + Some(_) => return Box::new(future::ok(Vec::new())), + None => return Box::new(future::err(errors::filter_not_found())), } };