fixed script iteration in bloom filter

This commit is contained in:
Svyatoslav Nikolsky 2019-03-12 15:39:04 +03:00
parent b0ebed0cfb
commit 590528b7c3
1 changed files with 26 additions and 23 deletions

View File

@ -91,9 +91,7 @@ impl BloomFilter {
let script = Script::new(output.script_pubkey.clone());
let is_update_needed = self.filter_flags == types::FilterFlags::All
|| (self.filter_flags == types::FilterFlags::PubKeyOnly && (script.is_pay_to_public_key() || script.is_multisig_script()));
for instruction in script.iter().filter_map(|i| i.ok()) {
if let Some(instruction_data) = instruction.data {
if bloom.contains(instruction_data) {
if contains_any_instruction_data(&*bloom, script) {
is_match = true;
if is_update_needed {
@ -104,8 +102,6 @@ impl BloomFilter {
}
}
}
}
}
// filter is updated only above => we can early-return from now
if is_match {
@ -128,20 +124,10 @@ impl BloomFilter {
// check if match any arbitrary script data element in any scriptSig in tx
let script = Script::new(input.script_sig.clone());
for instruction in script.iter() {
match instruction {
Err(_) => break,
Ok(instruction) => {
if let Some(instruction_data) = instruction.data {
is_match = bloom.contains(&*instruction_data);
if is_match {
if contains_any_instruction_data(&*bloom, script) {
return true;
}
}
}
}
}
}
// no matches
false
@ -184,6 +170,23 @@ impl BloomFilterData {
}
}
fn contains_any_instruction_data(bloom: &BloomFilterData, script: Script) -> bool {
for instruction in script.iter() {
match instruction {
Err(_) => break,
Ok(instruction) => {
if let Some(instruction_data) = instruction.data {
if bloom.contains(&*instruction_data) {
return true;
}
}
},
}
}
false
}
#[cfg(test)]
mod tests {
extern crate test_data;