Implement EIP234 block_hash for eth_getLogs (#9256)
* Implement EIP234 * Make filter conversion returns error if both blockHash and from/toBlock is found This also changes PollFilter to store the EthFilter type, instead of the jsonrpc one, saving repeated conversion. * Return error if block filtering target is not found in eth_getLogs Use the old behavior (unwrap_or_default) for anywhere else. * fix test: secret_store * Fix weird indentation * Make client log filter return error in case a block cannot be found * Return blockId error in rpc * test_client: allow return error on logs * Add a mocked test for eth_getLogs error * fix: should return error if from_block/to_block greater than best block number * Add notes on pending * Add comment for UNSUPPORTED_REQUEST * Address grumbles * Return err if from > to
This commit is contained in:
@@ -20,6 +20,7 @@ use std::fmt;
|
||||
|
||||
use ethcore::account_provider::{SignError as AccountError};
|
||||
use ethcore::error::{Error as EthcoreError, ErrorKind, CallError};
|
||||
use ethcore::client::BlockId;
|
||||
use jsonrpc_core::{futures, Error, ErrorCode, Value};
|
||||
use rlp::DecoderError;
|
||||
use transaction::Error as TransactionError;
|
||||
@@ -422,6 +423,19 @@ 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(),
|
||||
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(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
// on-demand sender cancelled.
|
||||
pub fn on_demand_cancel(_cancel: futures::sync::oneshot::Canceled) -> Error {
|
||||
internal("on-demand sender cancelled", "")
|
||||
|
||||
@@ -22,7 +22,8 @@ use std::{
|
||||
};
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::Mutex;
|
||||
use v1::types::{Filter, Log};
|
||||
use ethcore::filter::Filter;
|
||||
use v1::types::Log;
|
||||
|
||||
pub type BlockNumber = u64;
|
||||
|
||||
@@ -52,7 +53,13 @@ pub enum PollFilter {
|
||||
/// Hashes of all pending transactions the client knows about.
|
||||
PendingTransaction(BTreeSet<H256>),
|
||||
/// Number of From block number, last seen block hash, pending logs and log filter itself.
|
||||
Logs(BlockNumber, Option<H256>, HashSet<Log>, Filter)
|
||||
Logs {
|
||||
block_number: BlockNumber,
|
||||
last_block_hash: Option<H256>,
|
||||
previous_logs: HashSet<Log>,
|
||||
filter: Filter,
|
||||
include_pending: bool,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns only last `n` logs
|
||||
|
||||
Reference in New Issue
Block a user