sc_cli/commands/
check_block_cmd.rs1use crate::{
20 error,
21 params::{BlockNumberOrHash, ImportParams, SharedParams},
22 CliConfiguration,
23};
24use clap::Parser;
25use sc_client_api::{BlockBackend, HeaderBackend};
26use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
27use std::{fmt::Debug, str::FromStr, sync::Arc};
28
29#[derive(Debug, Clone, Parser)]
31pub struct CheckBlockCmd {
32 #[arg(value_name = "HASH or NUMBER")]
34 pub input: BlockNumberOrHash,
35
36 #[arg(long, value_name = "COUNT")]
39 pub default_heap_pages: Option<u32>,
40
41 #[allow(missing_docs)]
42 #[clap(flatten)]
43 pub shared_params: SharedParams,
44
45 #[allow(missing_docs)]
46 #[clap(flatten)]
47 pub import_params: ImportParams,
48}
49
50impl CheckBlockCmd {
51 pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
53 where
54 B: BlockT + for<'de> serde::Deserialize<'de>,
55 C: BlockBackend<B> + HeaderBackend<B> + Send + Sync + 'static,
56 IQ: sc_service::ImportQueue<B> + 'static,
57 <B::Hash as FromStr>::Err: Debug,
58 <<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
59 {
60 let start = std::time::Instant::now();
61 sc_service::chain_ops::check_block(client, import_queue, self.input.parse()?).await?;
62 println!("Completed in {} ms.", start.elapsed().as_millis());
63
64 Ok(())
65 }
66}
67
68impl CliConfiguration for CheckBlockCmd {
69 fn shared_params(&self) -> &SharedParams {
70 &self.shared_params
71 }
72
73 fn import_params(&self) -> Option<&ImportParams> {
74 Some(&self.import_params)
75 }
76}