From e0fddce9e93b245ef485ed132c40758485fb76f9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 9 Aug 2022 15:04:27 +1000 Subject: [PATCH] Refactor new_script_filter Refactor the `new_script_filter` by doing: - Put it directly below the `new` constructor - Improve docs - Remove unneeded scope - Correctly indent `where` keyword --- src/util/bip158.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/util/bip158.rs b/src/util/bip158.rs index 373e0f76..b38b9680 100644 --- a/src/util/bip158.rs +++ b/src/util/bip158.rs @@ -120,25 +120,27 @@ impl BlockFilter { BlockFilter { content: content.to_vec() } } + /// Computes a SCRIPT_FILTER that contains spent and output scripts. + pub fn new_script_filter(block: &Block, script_for_coin: M) -> Result + where + M: Fn(&OutPoint) -> Result + { + let mut out = Vec::new(); + let mut writer = BlockFilterWriter::new(&mut out, block); + + writer.add_output_scripts(); + writer.add_input_scripts(script_for_coin)?; + writer.finish()?; + + Ok(BlockFilter { content: out }) + } + /// compute this filter's id in a chain of filters pub fn filter_header(&self, previous_filter_header: &FilterHeader) -> FilterHeader { let filter_hash = FilterHash::hash(self.content.as_slice()); filter_hash.filter_header(previous_filter_header) } - /// Compute a SCRIPT_FILTER that contains spent and output scripts - pub fn new_script_filter(block: &Block, script_for_coin: M) -> Result - where M: Fn(&OutPoint) -> Result { - let mut out = Vec::new(); - { - let mut writer = BlockFilterWriter::new(&mut out, block); - writer.add_output_scripts(); - writer.add_input_scripts(script_for_coin)?; - writer.finish()?; - } - Ok(BlockFilter { content: out }) - } - /// match any query pattern pub fn match_any<'a, I>(&self, block_hash: &BlockHash, query: I) -> Result where