eth_getLogs implementation

This commit is contained in:
debris 2016-02-15 13:18:26 +01:00
parent bae2682518
commit fada9bb1ba

View File

@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Eth rpc implementation. //! Eth rpc implementation.
use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
use ethsync::{EthSync, SyncState}; use ethsync::{EthSync, SyncState};
use jsonrpc_core::*; use jsonrpc_core::*;
@ -25,7 +26,7 @@ use ethcore::client::*;
use ethcore::views::*; use ethcore::views::*;
use ethcore::ethereum::denominations::shannon; use ethcore::ethereum::denominations::shannon;
use v1::traits::{Eth, EthFilter}; 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. /// Eth rpc implementation.
pub struct EthClient { pub struct EthClient {
@ -197,6 +198,21 @@ impl Eth for EthClient {
from_params::<(BlockNumber, Index)>(params) from_params::<(BlockNumber, Index)>(params)
.and_then(|(number, index)| self.transaction(TransactionId::Location(number.into(), index.value()))) .and_then(|(number, index)| self.transaction(TransactionId::Location(number.into(), index.value())))
} }
fn logs(&self, params: Params) -> Result<Value, Error> {
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<u64> = 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)
})
}
} }