From fada9bb1baf3f63553535a4f5e96b1cf1a79c65e Mon Sep 17 00:00:00 2001 From: debris Date: Mon, 15 Feb 2016 13:18:26 +0100 Subject: [PATCH] eth_getLogs implementation --- rpc/src/v1/impls/eth.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index b595139f9..85afdd612 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . //! Eth rpc implementation. +use std::collections::HashSet; use std::sync::Arc; use ethsync::{EthSync, SyncState}; use jsonrpc_core::*; @@ -25,7 +26,7 @@ use ethcore::client::*; use ethcore::views::*; use ethcore::ethereum::denominations::shannon; use v1::traits::{Eth, EthFilter}; -use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, OptionalValue, Index}; +use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, OptionalValue, Index, Filter}; /// Eth rpc implementation. pub struct EthClient { @@ -197,6 +198,21 @@ impl Eth for EthClient { from_params::<(BlockNumber, Index)>(params) .and_then(|(number, index)| self.transaction(TransactionId::Location(number.into(), index.value()))) } + + fn logs(&self, params: Params) -> Result { + from_params::<(Filter,)>(params) + .and_then(|(filter,)| { + let possibilities = filter.bloom_possibilities(); + let from = filter.from_block.map_or_else(|| BlockId::Earliest, Into::into); + let to = filter.to_block.map_or_else(|| BlockId::Latest, Into::into); + let blocks: HashSet = possibilities.iter() + .map(|bloom| self.client.blocks_with_bloom(bloom, from.clone(), to.clone())) + .filter_map(|m| m) + .flat_map(|m| m) + .collect(); + to_value(&blocks) + }) + } }