sc_cli/commands/
import_blocks_cmd.rs1use crate::{
20 error,
21 params::{ImportParams, SharedParams},
22 CliConfiguration,
23};
24use clap::Parser;
25use sc_client_api::HeaderBackend;
26use sc_service::chain_ops::import_blocks;
27use sp_runtime::traits::Block as BlockT;
28use std::{
29 fmt::Debug,
30 fs,
31 io::{self, Read},
32 path::PathBuf,
33 sync::Arc,
34};
35
36#[derive(Debug, Parser)]
38pub struct ImportBlocksCmd {
39 #[arg()]
41 pub input: Option<PathBuf>,
42
43 #[arg(long, value_name = "COUNT")]
46 pub default_heap_pages: Option<u32>,
47
48 #[arg(long)]
50 pub binary: bool,
51
52 #[allow(missing_docs)]
53 #[clap(flatten)]
54 pub shared_params: SharedParams,
55
56 #[allow(missing_docs)]
57 #[clap(flatten)]
58 pub import_params: ImportParams,
59}
60
61impl ImportBlocksCmd {
62 pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
64 where
65 C: HeaderBackend<B> + Send + Sync + 'static,
66 B: BlockT + for<'de> serde::Deserialize<'de>,
67 IQ: sc_service::ImportQueue<B> + 'static,
68 {
69 let file: Box<dyn Read + Send> = match &self.input {
70 Some(filename) => Box::new(fs::File::open(filename)?),
71 None => Box::new(io::stdin()),
72 };
73
74 import_blocks(client, import_queue, file, false, self.binary)
75 .await
76 .map_err(Into::into)
77 }
78}
79
80impl CliConfiguration for ImportBlocksCmd {
81 fn shared_params(&self) -> &SharedParams {
82 &self.shared_params
83 }
84
85 fn import_params(&self) -> Option<&ImportParams> {
86 Some(&self.import_params)
87 }
88}