rpc, eth_filter: return error if the filter id does not exist (#8341)

This commit is contained in:
Wei Tang 2018-04-10 16:36:14 +08:00 committed by Marek Kotewicz
parent 8e7a08f865
commit d1487b3177
2 changed files with 12 additions and 3 deletions

View File

@ -399,6 +399,14 @@ pub fn deprecated<T: Into<Option<String>>>(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. // on-demand sender cancelled.
pub fn on_demand_cancel(_cancel: futures::sync::oneshot::Canceled) -> Error { pub fn on_demand_cancel(_cancel: futures::sync::oneshot::Canceled) -> Error {
internal("on-demand sender cancelled", "") internal("on-demand sender cancelled", "")

View File

@ -30,7 +30,7 @@ use jsonrpc_core::futures::{future, Future};
use jsonrpc_core::futures::future::Either; use jsonrpc_core::futures::future::Either;
use v1::traits::EthFilter; use v1::traits::EthFilter;
use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256}; 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; use v1::impls::eth::pending_logs;
/// Something which provides data that can be filtered over. /// Something which provides data that can be filtered over.
@ -127,7 +127,7 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
fn filter_changes(&self, index: Index) -> BoxFuture<FilterChanges> { fn filter_changes(&self, index: Index) -> BoxFuture<FilterChanges> {
let mut polls = self.polls().lock(); let mut polls = self.polls().lock();
Box::new(match polls.poll_mut(&index.value()) { 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 { Some(filter) => match *filter {
PollFilter::Block(ref mut block_number) => { PollFilter::Block(ref mut block_number) => {
// +1, cause we want to return hashes including current block hash. // +1, cause we want to return hashes including current block hash.
@ -217,7 +217,8 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
match polls.poll(&index.value()) { match polls.poll(&index.value()) {
Some(&PollFilter::Logs(ref _block_number, ref _previous_log, ref filter)) => filter.clone(), Some(&PollFilter::Logs(ref _block_number, ref _previous_log, ref filter)) => filter.clone(),
// just empty array // 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())),
} }
}; };