Fixing RPC Filter conversion to EthFilter (#2500)
This commit is contained in:
parent
0c7a28779d
commit
d9ca01cb6b
@ -22,7 +22,7 @@ use client::BlockID;
|
|||||||
use log_entry::LogEntry;
|
use log_entry::LogEntry;
|
||||||
|
|
||||||
/// Blockchain Filter.
|
/// Blockchain Filter.
|
||||||
#[derive(Binary)]
|
#[derive(Binary, Debug, PartialEq)]
|
||||||
pub struct Filter {
|
pub struct Filter {
|
||||||
/// Blockchain will be searched from this block.
|
/// Blockchain will be searched from this block.
|
||||||
pub from_block: BlockID,
|
pub from_block: BlockID,
|
||||||
|
@ -85,8 +85,14 @@ impl Into<EthFilter> for Filter {
|
|||||||
VariadicValue::Null => None,
|
VariadicValue::Null => None,
|
||||||
VariadicValue::Single(t) => Some(vec![t.into()]),
|
VariadicValue::Single(t) => Some(vec![t.into()]),
|
||||||
VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
|
VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
|
||||||
}).filter_map(|m| m).collect()).into_iter();
|
}).collect()).into_iter();
|
||||||
vec![iter.next(), iter.next(), iter.next(), iter.next()]
|
|
||||||
|
vec![
|
||||||
|
iter.next().unwrap_or(None),
|
||||||
|
iter.next().unwrap_or(None),
|
||||||
|
iter.next().unwrap_or(None),
|
||||||
|
iter.next().unwrap_or(None)
|
||||||
|
]
|
||||||
},
|
},
|
||||||
limit: self.limit,
|
limit: self.limit,
|
||||||
}
|
}
|
||||||
@ -121,6 +127,8 @@ mod tests {
|
|||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
use v1::types::BlockNumber;
|
use v1::types::BlockNumber;
|
||||||
|
use ethcore::filter::Filter as EthFilter;
|
||||||
|
use ethcore::client::BlockID;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn topic_deserialization() {
|
fn topic_deserialization() {
|
||||||
@ -148,4 +156,33 @@ mod tests {
|
|||||||
limit: None,
|
limit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn filter_conversion() {
|
||||||
|
let filter = Filter {
|
||||||
|
from_block: Some(BlockNumber::Earliest),
|
||||||
|
to_block: Some(BlockNumber::Latest),
|
||||||
|
address: Some(VariadicValue::Multiple(vec![])),
|
||||||
|
topics: Some(vec![
|
||||||
|
VariadicValue::Null,
|
||||||
|
VariadicValue::Single("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()),
|
||||||
|
VariadicValue::Null,
|
||||||
|
]),
|
||||||
|
limit: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let eth_filter: EthFilter = filter.into();
|
||||||
|
assert_eq!(eth_filter, EthFilter {
|
||||||
|
from_block: BlockID::Earliest,
|
||||||
|
to_block: BlockID::Latest,
|
||||||
|
address: Some(vec![]),
|
||||||
|
topics: vec![
|
||||||
|
None,
|
||||||
|
Some(vec!["000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()]),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
],
|
||||||
|
limit: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user