trace filters binary ser
This commit is contained in:
parent
c622fc62d5
commit
f9c08df235
@ -21,34 +21,40 @@ use util::sha3::Hashable;
|
||||
use basic_types::LogBloom;
|
||||
use trace::flat::FlatTrace;
|
||||
use types::trace_types::trace::Action;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Addresses filter.
|
||||
///
|
||||
/// Used to create bloom possibilities and match filters.
|
||||
pub struct AddressesFilter(Vec<Address>);
|
||||
#[derive(Binary)]
|
||||
pub struct AddressesFilter {
|
||||
list: Vec<Address>
|
||||
}
|
||||
|
||||
impl From<Vec<Address>> for AddressesFilter {
|
||||
fn from(addresses: Vec<Address>) -> Self {
|
||||
AddressesFilter(addresses)
|
||||
AddressesFilter { list: addresses }
|
||||
}
|
||||
}
|
||||
|
||||
impl AddressesFilter {
|
||||
/// Returns true if address matches one of the searched addresses.
|
||||
pub fn matches(&self, address: &Address) -> bool {
|
||||
self.matches_all() || self.0.contains(address)
|
||||
self.matches_all() || self.list.contains(address)
|
||||
}
|
||||
|
||||
/// Returns true if this address filter matches everything.
|
||||
pub fn matches_all(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
self.list.is_empty()
|
||||
}
|
||||
|
||||
/// Returns blooms of this addresses filter.
|
||||
pub fn blooms(&self) -> Vec<LogBloom> {
|
||||
match self.0.is_empty() {
|
||||
match self.list.is_empty() {
|
||||
true => vec![LogBloom::new()],
|
||||
false => self.0.iter()
|
||||
false => self.list.iter()
|
||||
.map(|address| LogBloom::from_bloomed(&address.sha3()))
|
||||
.collect()
|
||||
}
|
||||
@ -56,11 +62,11 @@ impl AddressesFilter {
|
||||
|
||||
/// Returns vector of blooms zipped with blooms of this addresses filter.
|
||||
pub fn with_blooms(&self, blooms: Vec<LogBloom>) -> Vec<LogBloom> {
|
||||
match self.0.is_empty() {
|
||||
match self.list.is_empty() {
|
||||
true => blooms,
|
||||
false => blooms
|
||||
.into_iter()
|
||||
.flat_map(|bloom| self.0.iter()
|
||||
.flat_map(|bloom| self.list.iter()
|
||||
.map(|address| bloom.with_bloomed(&address.sha3()))
|
||||
.collect::<Vec<_>>())
|
||||
.collect()
|
||||
@ -68,6 +74,7 @@ impl AddressesFilter {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Binary)]
|
||||
/// Traces filter.
|
||||
pub struct Filter {
|
||||
/// Block range.
|
||||
|
@ -17,9 +17,12 @@
|
||||
use util::H256;
|
||||
use super::trace::{Action, Res};
|
||||
use header::BlockNumber;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Localized trace.
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Binary)]
|
||||
pub struct LocalizedTrace {
|
||||
/// Type of action performed by a transaction.
|
||||
pub action: Action,
|
||||
|
@ -20,6 +20,7 @@ use util::bytes::Populatable;
|
||||
use util::numbers::{U256, H256, H2048, Address};
|
||||
use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
use std::ops::Range;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BinaryConvertError;
|
||||
@ -366,7 +367,7 @@ pub fn serialize<T: BinaryConvertable>(t: &T) -> Result<Vec<u8>, BinaryConvertEr
|
||||
}
|
||||
|
||||
macro_rules! binary_fixed_size {
|
||||
($target_ty: ident) => {
|
||||
($target_ty: ty) => {
|
||||
impl BinaryConvertable for $target_ty {
|
||||
fn from_bytes(bytes: &[u8], _length_stack: &mut VecDeque<usize>) -> Result<Self, BinaryConvertError> {
|
||||
match bytes.len().cmp(&::std::mem::size_of::<$target_ty>()) {
|
||||
@ -401,6 +402,8 @@ binary_fixed_size!(U256);
|
||||
binary_fixed_size!(H256);
|
||||
binary_fixed_size!(H2048);
|
||||
binary_fixed_size!(Address);
|
||||
binary_fixed_size!(Range<usize>);
|
||||
binary_fixed_size!(Range<u64>);
|
||||
|
||||
#[test]
|
||||
fn vec_serialize() {
|
||||
|
Loading…
Reference in New Issue
Block a user