pub async fn download_or_read_blocks(
    client: &mut Client,
    storage: &mut Storage,
    url: &str,
    highest_block: Option<&BlockIdentifier>,
    progress_fn: impl Fn() + Send + Sync,
) -> Result<(usize, usize), anyhow::Error> {
    let mut new_blocks_downloaded = 0;
    let mut blocks_read_from_disk = 0;
    let mut maybe_next_block_hash_and_source = match highest_block.as_ref() {
        Some(block_identifier) => {
            download_or_read_block_and_extract_parent_hash(client, storage, url, *block_identifier)
                .await?
        }
        // Get the highest block.
        None => get_block_and_download(client, storage, url, None)
            .await?
            .map(|block_hash| (block_hash, BlockSource::Http)),
    };
    while let Some((next_block_hash, source)) = maybe_next_block_hash_and_source.as_ref() {
        match source {
            BlockSource::Http => {
                new_blocks_downloaded += 1;
            }
            BlockSource::Storage => {
                blocks_read_from_disk += 1;
            }
        }
        maybe_next_block_hash_and_source = download_or_read_block_and_extract_parent_hash(
            client,
            storage,
            url,
            &BlockIdentifier::Hash(*next_block_hash),
        )
        .await?;
        progress_fn();
    }
    Ok((new_blocks_downloaded, blocks_read_from_disk))
}
/// Download block files from the highest (provided) block hash to genesis.
Download block files from the highest (provided) block hash to genesis.
Download block files from the highest ( provided ) block hash to genesis .
pub async fn download_or_read_blocks(
    client: &mut Client,
    storage: &mut Storage,
    url: &str,
    highest_block: Option<&BlockIdentifier>,
    progress_fn: impl Fn() + Send + Sync,
) -> Result<(usize, usize), anyhow::Error> {
    let mut new_blocks_downloaded = 0;
    let mut blocks_read_from_disk = 0;
    let mut maybe_next_block_hash_and_source = match highest_block.as_ref() {
        Some(block_identifier) => {
            download_or_read_block_and_extract_parent_hash(client, storage, url, *block_identifier)
                .await?
        }
        // Get the highest block.
        None => get_block_and_download(client, storage, url, None)
            .await?
            .map(|block_hash| (block_hash, BlockSource::Http)),
    };
    while let Some((next_block_hash, source)) = maybe_next_block_hash_and_source.as_ref() {
        match source {
            BlockSource::Http => {
                new_blocks_downloaded += 1;
            }
            BlockSource::Storage => {
                blocks_read_from_disk += 1;
            }
        }
        maybe_next_block_hash_and_source = download_or_read_block_and_extract_parent_hash(
            client,
            storage,
            url,
            &BlockIdentifier::Hash(*next_block_hash),
        )
        .await?;
        progress_fn();
    }
    Ok((new_blocks_downloaded, blocks_read_from_disk))
}
pub async fn download_or_read_blocks ( client : & mut Client , storage : & mut Storage , url : & str , highest_block : Option < & BlockIdentifier > , progress_fn : impl Fn ( ) + Send + Sync , ) -> Result < ( usize , usize ) , anyhow :: Error > { let mut new_blocks_downloaded = 0 ; let mut blocks_read_from_disk = 0 ; let mut maybe_next_block_hash_and_source = match highest_block . as_ref ( ) { Some ( block_identifier ) => { download_or_read_block_and_extract_parent_hash ( client , storage , url , * block_identifier ) . await ? } // Get the highest block. None => get_block_and_download ( client , storage , url , None ) . await ? . map ( | block_hash | ( block_hash , BlockSource :: Http ) ) , } ; while let Some ( ( next_block_hash , source ) ) = maybe_next_block_hash_and_source . as_ref ( ) { match source { BlockSource :: Http => { new_blocks_downloaded += 1 ; } BlockSource :: Storage => { blocks_read_from_disk += 1 ; } } maybe_next_block_hash_and_source = download_or_read_block_and_extract_parent_hash ( client , storage , url , & BlockIdentifier :: Hash ( * next_block_hash ) , ) . await ? ; progress_fn ( ) ; } Ok ( ( new_blocks_downloaded , blocks_read_from_disk ) ) }
Download block files from the highest (provided) block hash to genesis.
Download block files from the highest ( provided ) block hash to genesis .
client
&mut Client
storage
&mut Storage
url
&str
highest_block
Option<&BlockIdentifier>
progress_fn
impl Fn() + Send + Sync
client
&mut Client
storage
&mut Storage
url
&str
highest_block
Option<&BlockIdentifier>
progress_fn
impl Fn() + Send + Sync