From b12d0f690d2020a88e41415e7c5f9866f9f7d33a Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 9 Feb 2016 17:45:39 +0100 Subject: [PATCH] fixed filter deserialization --- rpc/src/v1/types/filter.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs index ef2d8b29e..9b21cf8e7 100644 --- a/rpc/src/v1/types/filter.rs +++ b/rpc/src/v1/types/filter.rs @@ -42,14 +42,14 @@ impl Deserialize for Topic { } } -#[derive(Debug, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] pub struct Filter { #[serde(rename="fromBlock")] - pub from_block: BlockNumber, + pub from_block: Option, #[serde(rename="toBlock")] - pub to_block: BlockNumber, - pub address: Address, - pub topics: Vec + pub to_block: Option, + pub address: Option
, + pub topics: Option> } #[cfg(test)] @@ -58,9 +58,10 @@ mod tests { use std::str::FromStr; use util::hash::*; use super::*; + use v1::types::BlockNumber; #[test] - fn filter_deserialization() { + fn topic_deserialization() { let s = r#"["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]"#; let deserialized: Vec = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, vec![ @@ -72,4 +73,16 @@ mod tests { ]) ]); } + + #[test] + fn filter_deserialization() { + let s = r#"{"fromBlock":"earliest","toBlock":"latest"}"#; + let deserialized: Filter = serde_json::from_str(s).unwrap(); + assert_eq!(deserialized, Filter { + from_block: Some(BlockNumber::Earliest), + to_block: Some(BlockNumber::Latest), + address: None, + topics: None + }); + } }