[beta] Fixing RPC Filter conversion to EthFilter (#2501)

* Fixing RPC Filter conversion to EthFilter

Conflicts:
	rpc/src/v1/impls/eth.rs
	rpc/src/v1/types/filter.rs

* Removing limit

* Fixing rpc tests
This commit is contained in:
Tomasz Drwięga 2016-10-07 13:16:09 +02:00 committed by Gav Wood
parent 73a3dac38c
commit 8031910892
3 changed files with 40 additions and 4 deletions

View File

@ -25,7 +25,7 @@ use std::mem;
use std::collections::VecDeque; use std::collections::VecDeque;
/// 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,

View File

@ -60,6 +60,7 @@ fn miner_service(spec: &Spec, accounts: Arc<AccountProvider>) -> Arc<Miner> {
tx_queue_size: 1024, tx_queue_size: 1024,
tx_queue_strategy: PrioritizationStrategy::GasPriceOnly, tx_queue_strategy: PrioritizationStrategy::GasPriceOnly,
tx_gas_limit: !U256::zero(), tx_gas_limit: !U256::zero(),
tx_queue_strategy: PrioritizationStrategy::GasPriceOnly,
pending_set: PendingSet::SealingOrElseQueue, pending_set: PendingSet::SealingOrElseQueue,
reseal_min_period: Duration::from_secs(0), reseal_min_period: Duration::from_secs(0),
work_queue_size: 50, work_queue_size: 50,

View File

@ -83,9 +83,15 @@ 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)
]
},
} }
} }
} }
@ -97,6 +103,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() {
@ -123,4 +131,31 @@ mod tests {
topics: None topics: 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,
]),
};
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,
],
});
}
} }