pub(crate) fn for_blocks<B, F>(&mut self, blockhashes: B, mut func: F) -> Result<()>
    where
        B: IntoIterator<Item = BlockHash>,
        F: FnMut(BlockHash, Block),
    {
        let blockhashes = Vec::from_iter(blockhashes);
        if blockhashes.is_empty() {
            return Ok(());
        }
        self.blocks_duration.observe_duration("send", || {
            debug!("loading {} blocks", blockhashes.len());
            self.req_send.send(Request::get_blocks(&blockhashes))
        })?;

        for hash in blockhashes {
            let block = self.blocks_duration.observe_duration("recv", || {
                self.blocks_recv
                    .recv()
                    .with_context(|| format!("failed to get block {}", hash))
            })?;

            self.blocks_duration.observe_duration("process", || {
                ensure!(block.block_hash() == hash, "got unexpected block");
                func(hash, block);
                Ok(())
            })?;
        }
        Ok(())
    }
/// Request and process the specified blocks (in the specified order).
/// See https://en.bitcoin.it/wiki/Protocol_documentation#getblocks for details.
/// Defined as `&mut self` to prevent concurrent invocations (https://github.com/romanz/electrs/pull/526#issuecomment-934685515).
Request and process the specified blocks (in the specified order).
Request and process the specified blocks ( in the specified order ) .
pub(crate) fn for_blocks<B, F>(&mut self, blockhashes: B, mut func: F) -> Result<()>
    where
        B: IntoIterator<Item = BlockHash>,
        F: FnMut(BlockHash, Block),
    {
        let blockhashes = Vec::from_iter(blockhashes);
        if blockhashes.is_empty() {
            return Ok(());
        }
        self.blocks_duration.observe_duration("send", || {
            debug!("loading {} blocks", blockhashes.len());
            self.req_send.send(Request::get_blocks(&blockhashes))
        })?;
        for hash in blockhashes {
            let block = self.blocks_duration.observe_duration("recv", || {
                self.blocks_recv
                    .recv()
                    .with_context(|| format!("failed to get block {}", hash))
            })?;
            self.blocks_duration.observe_duration("process", || {
                ensure!(block.block_hash() == hash, "got unexpected block");
                func(hash, block);
                Ok(())
            })?;
        }
        Ok(())
    }
pub ( crate ) fn for_blocks < B , F > ( & mut self , blockhashes : B , mut func : F ) -> Result < ( ) > where B : IntoIterator < Item = BlockHash > , F : FnMut ( BlockHash , Block ) , { let blockhashes = Vec :: from_iter ( blockhashes ) ; if blockhashes . is_empty ( ) { return Ok ( ( ) ) ; } self . blocks_duration . observe_duration ( " " , | | { debug ! ( " " blockhashes len ( ) ) ; self . req_send . send ( Request :: get_blocks ( & blockhashes ) ) } ) ? ; for hash in blockhashes { let block = self . blocks_duration . observe_duration ( " " , | | { self . blocks_recv . recv ( ) . with_context ( | | format ! ( " " hash ) ) } ) ? ; self . blocks_duration . observe_duration ( " " , | | { ensure ! ( block block_hash ( ) hash " " ) ; func ( hash , block ) ; Ok ( ( ) ) } ) ? ; } Ok ( ( ) ) }
Request and process the specified blocks (in the specified order).
Request and process the specified blocks ( in the specified order ) .
&mut self
blockhashes
B
func
F
&mut self
blockhashes
B
func
F