Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fixing RPC Filter conversion to EthFilter #2500

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/src/types/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use client::BlockID;
use log_entry::LogEntry;

/// Blockchain Filter.
#[derive(Binary)]
#[derive(Binary, Debug, PartialEq)]
pub struct Filter {
/// Blockchain will be searched from this block.
pub from_block: BlockID,
Expand Down
41 changes: 39 additions & 2 deletions rpc/src/v1/types/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ impl Into<EthFilter> for Filter {
VariadicValue::Null => None,
VariadicValue::Single(t) => Some(vec![t.into()]),
VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
}).filter_map(|m| m).collect()).into_iter();
vec![iter.next(), iter.next(), iter.next(), iter.next()]
}).collect()).into_iter();

vec![
iter.next().unwrap_or(None),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why iter.next().unwrap_or(None) instead of just iter.next()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iter.next() returns Option<Option<Vec>> we need Option<Vec>

iter.next().unwrap_or(None),
iter.next().unwrap_or(None),
iter.next().unwrap_or(None)
]
},
limit: self.limit,
}
Expand Down Expand Up @@ -121,6 +127,8 @@ mod tests {
use util::hash::*;
use super::*;
use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID;

#[test]
fn topic_deserialization() {
Expand Down Expand Up @@ -148,4 +156,33 @@ mod tests {
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,
});
}
}