pub fn fetch_block(
    peer: Peer,
    hash: HeaderHash,
    logger: &Logger,
) -> Result<Block, FetchBlockError> {
    info!(logger, "fetching block {}", hash);
    let runtime = Runtime::new().map_err(|e| FetchBlockError::RuntimeInit { source: e })?;
    let fetch = connect(peer.address(), None, runtime.executor())
        .map_err(|err| FetchBlockError::Connect { source: err })
        .and_then(move |client: Connection| {
            client
                .ready()
                .map_err(|err| FetchBlockError::ClientNotReady { source: err })
        })
        .and_then(move |mut client| {
            client
                .get_blocks(slice::from_ref(&hash))
                .map_err(|err| FetchBlockError::GetBlocks { source: err })
        })
        .and_then(move |stream| {
            stream
                .into_future()
                .map_err(|(err, _)| FetchBlockError::GetBlocksStream { source: err })
        })
        .and_then(|(maybe_block, _)| match maybe_block {
            None => Err(FetchBlockError::NoBlocks),
            Some(block) => Ok(block),
        });
    runtime.block_on_all(fetch)
}
// Fetches a block from a network peer in a one-off, blocking call.
// This function is used during node bootstrap to fetch the genesis block.
Fetches a block from a network peer in a one-off, blocking call.
This function is used during node bootstrap to fetch the genesis block.
Fetches a block from a network peer in a one - off blocking call . This function is used during node bootstrap to fetch the genesis block .
pub fn fetch_block(
    peer: Peer,
    hash: HeaderHash,
    logger: &Logger,
) -> Result<Block, FetchBlockError> {
    info!(logger, "fetching block {}", hash);
    let runtime = Runtime::new().map_err(|e| FetchBlockError::RuntimeInit { source: e })?;
    let fetch = connect(peer.address(), None, runtime.executor())
        .map_err(|err| FetchBlockError::Connect { source: err })
        .and_then(move |client: Connection| {
            client
                .ready()
                .map_err(|err| FetchBlockError::ClientNotReady { source: err })
        })
        .and_then(move |mut client| {
            client
                .get_blocks(slice::from_ref(&hash))
                .map_err(|err| FetchBlockError::GetBlocks { source: err })
        })
        .and_then(move |stream| {
            stream
                .into_future()
                .map_err(|(err, _)| FetchBlockError::GetBlocksStream { source: err })
        })
        .and_then(|(maybe_block, _)| match maybe_block {
            None => Err(FetchBlockError::NoBlocks),
            Some(block) => Ok(block),
        });
    runtime.block_on_all(fetch)
}
pub fn fetch_block ( peer : Peer , hash : HeaderHash , logger : & Logger , ) -> Result < Block , FetchBlockError > { info ! ( logger " " hash ) ; let runtime = Runtime :: new ( ) . map_err ( | e | FetchBlockError :: RuntimeInit { source : e } ) ? ; let fetch = connect ( peer . address ( ) , None , runtime . executor ( ) ) . map_err ( | err | FetchBlockError :: Connect { source : err } ) . and_then ( move | client : Connection | { client . ready ( ) . map_err ( | err | FetchBlockError :: ClientNotReady { source : err } ) } ) . and_then ( move | mut client | { client . get_blocks ( slice :: from_ref ( & hash ) ) . map_err ( | err | FetchBlockError :: GetBlocks { source : err } ) } ) . and_then ( move | stream | { stream . into_future ( ) . map_err ( | ( err , _ ) | FetchBlockError :: GetBlocksStream { source : err } ) } ) . and_then ( | ( maybe_block , _ ) | match maybe_block { None => Err ( FetchBlockError :: NoBlocks ) , Some ( block ) => Ok ( block ) , } ) ; runtime . block_on_all ( fetch ) }
Fetches a block from a network peer in a one-off, blocking call.
Fetches a block from a network peer in a one - off blocking call .
peer
Peer
hash
HeaderHash
logger
&Logger
peer
Peer
hash
HeaderHash
logger
&Logger