bloom possibilities
This commit is contained in:
parent
89bc3e9153
commit
bae2682518
@ -57,7 +57,7 @@ pub struct Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Filter {
|
impl Filter {
|
||||||
/// Returns combinations of each of address topic.
|
/// Returns combinations of each address and topic.
|
||||||
pub fn bloom_possibilities(&self) -> Vec<H2048> {
|
pub fn bloom_possibilities(&self) -> Vec<H2048> {
|
||||||
let blooms = match self.address {
|
let blooms = match self.address {
|
||||||
Some(VariadicValue::Single(ref address)) => {
|
Some(VariadicValue::Single(ref address)) => {
|
||||||
@ -77,33 +77,21 @@ impl Filter {
|
|||||||
|
|
||||||
match self.topics {
|
match self.topics {
|
||||||
None => blooms,
|
None => blooms,
|
||||||
Some(ref topics) => blooms.into_iter().map(|bloom| {
|
Some(ref topics) => topics.iter().fold(blooms, | bs, topic | match *topic {
|
||||||
//for topic in topics {
|
VariadicValue::Null => bs,
|
||||||
//match topic {
|
VariadicValue::Single(ref topic) => bs.into_iter().map(|mut bloom| {
|
||||||
//VariadicValue::Single => {
|
bloom.shift_bloomed(&topic.sha3());
|
||||||
//bloom.shift_bloomed(&topic.sha3());
|
bloom
|
||||||
//bloom
|
}).collect(),
|
||||||
//}
|
VariadicValue::Multiple(ref topics) => bs.into_iter().map(|bloom| {
|
||||||
//}
|
topics.into_iter().map(|topic| {
|
||||||
//}
|
let mut b = bloom.clone();
|
||||||
}).collect()
|
b.shift_bloomed(&topic.sha3());
|
||||||
|
b
|
||||||
|
}).collect::<Vec<H2048>>()
|
||||||
|
}).flat_map(|m| m).collect::<Vec<H2048>>()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
//self.address.as_ref().map(|a| match *a {
|
|
||||||
//VariadicValue::Single(ref address) => {
|
|
||||||
//let mut bloom = H2048::new();
|
|
||||||
//bloom.shift_bloomed(&address.sha3());
|
|
||||||
//vec![bloom]
|
|
||||||
//},
|
|
||||||
//VariadicValue::Multiple(ref addresses) => {
|
|
||||||
//addresses.iter().map(|ref address| {
|
|
||||||
//let mut bloom = H2048::new();
|
|
||||||
//bloom.shift_bloomed(&address.sha3());
|
|
||||||
//bloom
|
|
||||||
//}).collect()
|
|
||||||
//},
|
|
||||||
//VariadicValue::Null => vec![H2048::new()]
|
|
||||||
//}.into_iter().map(|bloom| match self. {
|
|
||||||
//}).unwrap_or_else(Vec::new)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,4 +128,75 @@ mod tests {
|
|||||||
topics: None
|
topics: None
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bloom_possibilities_none() {
|
||||||
|
let none_filter = Filter {
|
||||||
|
from_block: None,
|
||||||
|
to_block: None,
|
||||||
|
address: None,
|
||||||
|
topics: None
|
||||||
|
};
|
||||||
|
|
||||||
|
let possibilities = none_filter.bloom_possibilities();
|
||||||
|
assert_eq!(possibilities, vec![H2048::new()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// block 399849
|
||||||
|
#[test]
|
||||||
|
fn test_bloom_possibilities_single_address_and_topic() {
|
||||||
|
let filter = Filter {
|
||||||
|
from_block: None,
|
||||||
|
to_block: None,
|
||||||
|
address: Some(VariadicValue::Single(Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap())),
|
||||||
|
topics: Some(vec![VariadicValue::Single(H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap())])
|
||||||
|
};
|
||||||
|
|
||||||
|
let possibilities = filter.bloom_possibilities();
|
||||||
|
assert_eq!(possibilities, vec![H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bloom_possibilities_single_address_and_many_topics() {
|
||||||
|
let filter = Filter {
|
||||||
|
from_block: None,
|
||||||
|
to_block: None,
|
||||||
|
address: Some(VariadicValue::Single(Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap())),
|
||||||
|
topics: Some(vec![
|
||||||
|
VariadicValue::Single(H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()),
|
||||||
|
VariadicValue::Single(H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap())
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
let possibilities = filter.bloom_possibilities();
|
||||||
|
assert_eq!(possibilities, vec![H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bloom_possibilites_multiple_addresses_and_topics() {
|
||||||
|
let filter = Filter {
|
||||||
|
from_block: None,
|
||||||
|
to_block: None,
|
||||||
|
address: Some(VariadicValue::Multiple(vec![
|
||||||
|
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(),
|
||||||
|
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()
|
||||||
|
])),
|
||||||
|
topics: Some(vec![
|
||||||
|
VariadicValue::Multiple(vec![
|
||||||
|
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(),
|
||||||
|
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()
|
||||||
|
]),
|
||||||
|
VariadicValue::Multiple(vec![
|
||||||
|
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(),
|
||||||
|
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()
|
||||||
|
]),
|
||||||
|
VariadicValue::Single(H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap())
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
// number of possibilites should be equal 2 * 2 * 2 * 1 = 8
|
||||||
|
let possibilities = filter.bloom_possibilities();
|
||||||
|
assert_eq!(possibilities.len(), 8);
|
||||||
|
assert_eq!(possibilities[0], H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user