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
This commit is contained in:
Tobin C. Harding 2022-08-09 15:04:27 +10:00
parent f6105a16a7
commit e0fddce9e9
1 changed files with 15 additions and 13 deletions

View File

@ -120,25 +120,27 @@ impl BlockFilter {
BlockFilter { content: content.to_vec() } BlockFilter { content: content.to_vec() }
} }
/// Computes a SCRIPT_FILTER that contains spent and output scripts.
pub fn new_script_filter<M>(block: &Block, script_for_coin: M) -> Result<BlockFilter, Error>
where
M: Fn(&OutPoint) -> Result<Script, Error>
{
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 /// compute this filter's id in a chain of filters
pub fn filter_header(&self, previous_filter_header: &FilterHeader) -> FilterHeader { pub fn filter_header(&self, previous_filter_header: &FilterHeader) -> FilterHeader {
let filter_hash = FilterHash::hash(self.content.as_slice()); let filter_hash = FilterHash::hash(self.content.as_slice());
filter_hash.filter_header(previous_filter_header) filter_hash.filter_header(previous_filter_header)
} }
/// Compute a SCRIPT_FILTER that contains spent and output scripts
pub fn new_script_filter<M>(block: &Block, script_for_coin: M) -> Result<BlockFilter, Error>
where M: Fn(&OutPoint) -> Result<Script, Error> {
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 /// match any query pattern
pub fn match_any<'a, I>(&self, block_hash: &BlockHash, query: I) -> Result<bool, Error> pub fn match_any<'a, I>(&self, block_hash: &BlockHash, query: I) -> Result<bool, Error>
where where