From 2891b7b4eafc60d791881a592f0975298dd86a4e Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 30 Jun 2016 00:15:34 +0300 Subject: [PATCH] sorting filters & ranges --- ethcore/src/client/client.rs.in | 2 +- ethcore/src/client/mod.rs | 2 +- ethcore/src/client/trace.rs | 11 +------ ethcore/src/lib.rs | 1 - ethcore/src/{ => types}/filter.rs | 24 +++++++++----- ethcore/src/types/mod.rs.in | 2 ++ ethcore/src/types/trace_filter.rs | 33 +++++++++++++++++++ .../src/types/transaction_import_result.rs | 2 +- ipc/rpc/src/binary.rs | 27 +++++++++++++-- 9 files changed, 80 insertions(+), 24 deletions(-) rename ethcore/src/{ => types}/filter.rs (95%) create mode 100644 ethcore/src/types/trace_filter.rs diff --git a/ethcore/src/client/client.rs.in b/ethcore/src/client/client.rs.in index 6aae81650..4d497876a 100644 --- a/ethcore/src/client/client.rs.in +++ b/ethcore/src/client/client.rs.in @@ -57,7 +57,7 @@ use verification::{PreverifiedBlock, Verifier}; use block::*; use transaction::{LocalizedTransaction, SignedTransaction, Action}; use blockchain::extras::TransactionAddress; -use filter::Filter; +use types::filter::Filter; use log_entry::LocalizedLogEntry; use block_queue::{BlockQueue, BlockQueueInfo}; use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute}; diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 838e4ecee..04b2c23c7 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -27,7 +27,7 @@ pub use self::config::{ClientConfig, DatabaseCompactionProfile, BlockQueueConfig pub use self::error::Error; pub use types::ids::*; pub use self::test_client::{TestBlockChainClient, EachBlockWith}; -pub use self::trace::Filter as TraceFilter; +pub use types::trace_filter::Filter as TraceFilter; pub use executive::{Executed, Executive, TransactOptions}; pub use env_info::{LastHashes, EnvInfo}; diff --git a/ethcore/src/client/trace.rs b/ethcore/src/client/trace.rs index 15920dea9..42e5d4104 100644 --- a/ethcore/src/client/trace.rs +++ b/ethcore/src/client/trace.rs @@ -8,6 +8,7 @@ use trace::DatabaseExtras as TraceDatabaseExtras; use blockchain::{BlockChain, BlockProvider}; use blockchain::extras::TransactionAddress; use super::BlockID; +pub use types::trace_filter::Filter; impl TraceDatabaseExtras for BlockChain { fn block_hash(&self, block_number: BlockNumber) -> Option { @@ -26,13 +27,3 @@ impl TraceDatabaseExtras for BlockChain { .map(|tx| tx.hash()) } } - -/// Easy to use trace filter. -pub struct Filter { - /// Range of filtering. - pub range: Range, - /// From address. - pub from_address: Vec
, - /// To address. - pub to_address: Vec
, -} diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 2379e6805..766d86254 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -104,7 +104,6 @@ pub mod block_queue; pub mod client; pub mod error; pub mod ethereum; -pub mod filter; pub mod header; pub mod service; pub mod trace; diff --git a/ethcore/src/filter.rs b/ethcore/src/types/filter.rs similarity index 95% rename from ethcore/src/filter.rs rename to ethcore/src/types/filter.rs index d99f80050..7d9b25071 100644 --- a/ethcore/src/filter.rs +++ b/ethcore/src/types/filter.rs @@ -20,6 +20,9 @@ use util::hash::*; use util::sha3::*; use client::BlockID; use log_entry::LogEntry; +use ipc::binary::BinaryConvertError; +use std::mem; +use std::collections::VecDeque; /// Blockchain Filter. pub struct Filter { @@ -29,22 +32,27 @@ pub struct Filter { /// Till this block. pub to_block: BlockID, - /// Search addresses. - /// + /// Search addresses. + /// /// If None, match all. /// If specified, log must be produced by one of these addresses. pub address: Option>, /// Search topics. - /// + /// /// If None, match all. /// If specified, log must contain one of these topics. - pub topics: [Option>; 4], + pub topics: Vec>>, } impl Clone for Filter { fn clone(&self) -> Self { - let mut topics = [None, None, None, None]; + let mut topics = [ + None, + None, + None, + None, + ]; for i in 0..4 { topics[i] = self.topics[i].clone(); } @@ -53,13 +61,13 @@ impl Clone for Filter { from_block: self.from_block.clone(), to_block: self.to_block.clone(), address: self.address.clone(), - topics: topics + topics: topics[..].to_vec() } } } impl Filter { - /// Returns combinations of each address and topic. + /// Returns combinations of each address and topic. pub fn bloom_possibilities(&self) -> Vec { let blooms = match self.address { Some(ref addresses) if !addresses.is_empty() => @@ -71,7 +79,7 @@ impl Filter { _ => vec![H2048::new()] }; - self.topics.iter().fold(blooms, | bs, topic | match *topic { + self.topics.iter().fold(blooms, |bs, topic| match *topic { None => bs, Some(ref topics) => bs.into_iter().flat_map(|bloom| { topics.into_iter().map(|topic| { diff --git a/ethcore/src/types/mod.rs.in b/ethcore/src/types/mod.rs.in index 7f00550ff..183812ed9 100644 --- a/ethcore/src/types/mod.rs.in +++ b/ethcore/src/types/mod.rs.in @@ -27,3 +27,5 @@ pub mod account_diff; pub mod state_diff; pub mod block_queue_info; pub mod transaction_import_result; +pub mod filter; +pub mod trace_filter; diff --git a/ethcore/src/types/trace_filter.rs b/ethcore/src/types/trace_filter.rs new file mode 100644 index 000000000..c374f7273 --- /dev/null +++ b/ethcore/src/types/trace_filter.rs @@ -0,0 +1,33 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +use std::mem; +use ipc::binary::{BinaryConvertError, BinaryConvertable}; +use std::collections::VecDeque; +use std::ops::Range; +use util::{Address, H256}; +use types::ids::BlockID; + +/// Easy to use trace filter. +#[derive(Binary)] +pub struct Filter { + /// Range of filtering. + pub range: Range, + /// From address. + pub from_address: Vec
, + /// To address. + pub to_address: Vec
, +} diff --git a/ethcore/src/types/transaction_import_result.rs b/ethcore/src/types/transaction_import_result.rs index 81d4c3d32..c2068b0bc 100644 --- a/ethcore/src/types/transaction_import_result.rs +++ b/ethcore/src/types/transaction_import_result.rs @@ -18,7 +18,7 @@ use std::mem; use ipc::binary::BinaryConvertError; use std::collections::VecDeque; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Binary)] /// Represents the result of importing transaction. pub enum TransactionImportResult { /// Transaction was imported to current queue. diff --git a/ipc/rpc/src/binary.rs b/ipc/rpc/src/binary.rs index ea49b3454..aabe19ed1 100644 --- a/ipc/rpc/src/binary.rs +++ b/ipc/rpc/src/binary.rs @@ -319,6 +319,31 @@ impl BinaryConvertable for String { } } +impl BinaryConvertable for Range where T: BinaryConvertable { + fn size(&self) -> usize { + mem::size_of::() * 2 + } + + fn from_empty_bytes() -> Result { + Err(BinaryConvertError) + } + + fn to_bytes(&self, buffer: &mut[u8], length_stack: &mut VecDeque) -> Result<(), BinaryConvertError> { + try!(self.start.to_bytes(&mut buffer[..mem::size_of::()], length_stack)); + try!(self.end.to_bytes(&mut buffer[mem::size_of::() + 1..], length_stack)); + Ok(()) + } + + fn from_bytes(buffer: &[u8], length_stack: &mut VecDeque) -> Result { + Ok(try!(T::from_bytes(&buffer[..mem::size_of::()], length_stack))..try!(T::from_bytes(&buffer[mem::size_of::()+1..], length_stack))) + } + + fn len_params() -> usize { + assert_eq!(0, T::len_params()); + 0 + } +} + impl BinaryConvertable for ::std::cell::RefCell where T: BinaryConvertable { fn size(&self) -> usize { self.borrow().size() @@ -543,8 +568,6 @@ binary_fixed_size!(U512); binary_fixed_size!(H256); binary_fixed_size!(H2048); binary_fixed_size!(Address); -binary_fixed_size!(Range); -binary_fixed_size!(Range); #[test] fn vec_serialize() {