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:
parent
f6105a16a7
commit
e0fddce9e9
|
@ -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<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
|
||||
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<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
|
||||
pub fn match_any<'a, I>(&self, block_hash: &BlockHash, query: I) -> Result<bool, Error>
|
||||
where
|
||||
|
|
Loading…
Reference in New Issue