fixed script iteration in bloom filter
This commit is contained in:
parent
b0ebed0cfb
commit
590528b7c3
|
@ -91,9 +91,7 @@ impl BloomFilter {
|
||||||
let script = Script::new(output.script_pubkey.clone());
|
let script = Script::new(output.script_pubkey.clone());
|
||||||
let is_update_needed = self.filter_flags == types::FilterFlags::All
|
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()));
|
|| (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 contains_any_instruction_data(&*bloom, script) {
|
||||||
if let Some(instruction_data) = instruction.data {
|
|
||||||
if bloom.contains(instruction_data) {
|
|
||||||
is_match = true;
|
is_match = true;
|
||||||
|
|
||||||
if is_update_needed {
|
if is_update_needed {
|
||||||
|
@ -104,8 +102,6 @@ impl BloomFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter is updated only above => we can early-return from now
|
// filter is updated only above => we can early-return from now
|
||||||
if is_match {
|
if is_match {
|
||||||
|
@ -128,20 +124,10 @@ impl BloomFilter {
|
||||||
|
|
||||||
// check if match any arbitrary script data element in any scriptSig in tx
|
// check if match any arbitrary script data element in any scriptSig in tx
|
||||||
let script = Script::new(input.script_sig.clone());
|
let script = Script::new(input.script_sig.clone());
|
||||||
for instruction in script.iter() {
|
if contains_any_instruction_data(&*bloom, script) {
|
||||||
match instruction {
|
|
||||||
Err(_) => break,
|
|
||||||
Ok(instruction) => {
|
|
||||||
if let Some(instruction_data) = instruction.data {
|
|
||||||
is_match = bloom.contains(&*instruction_data);
|
|
||||||
if is_match {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no matches
|
// no matches
|
||||||
false
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate test_data;
|
extern crate test_data;
|
||||||
|
|
Loading…
Reference in New Issue