use crate::{
error,
params::{BlockNumberOrHash, ImportParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use sc_client_api::{BlockBackend, HeaderBackend};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, sync::Arc};
#[derive(Debug, Clone, Parser)]
pub struct CheckBlockCmd {
#[arg(value_name = "HASH or NUMBER")]
pub input: BlockNumberOrHash,
#[arg(long, value_name = "COUNT")]
pub default_heap_pages: Option<u32>,
#[allow(missing_docs)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[clap(flatten)]
pub import_params: ImportParams,
}
impl CheckBlockCmd {
pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
where
B: BlockT + for<'de> serde::Deserialize<'de>,
C: BlockBackend<B> + HeaderBackend<B> + Send + Sync + 'static,
IQ: sc_service::ImportQueue<B> + 'static,
<B::Hash as FromStr>::Err: Debug,
<<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
let start = std::time::Instant::now();
sc_service::chain_ops::check_block(client, import_queue, self.input.parse()?).await?;
println!("Completed in {} ms.", start.elapsed().as_millis());
Ok(())
}
}
impl CliConfiguration for CheckBlockCmd {
fn shared_params(&self) -> &SharedParams {
&self.shared_params
}
fn import_params(&self) -> Option<&ImportParams> {
Some(&self.import_params)
}
}