Skip to main content

staging_node_inspect/
command.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Command ran by the CLI
20
21use crate::{
22	cli::{InspectCmd, InspectSubCmd},
23	Inspector,
24};
25use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
26use sc_service::Configuration;
27use sp_runtime::traits::Block;
28
29type HostFunctions =
30	(sp_io::SubstrateHostFunctions, sp_statement_store::runtime_api::HostFunctions);
31
32impl InspectCmd {
33	/// Run the inspect command, passing the inspector.
34	pub fn run<B, RA>(&self, config: Configuration) -> Result<()>
35	where
36		B: Block,
37		RA: Send + Sync + 'static,
38	{
39		let executor = sc_service::new_wasm_executor::<HostFunctions>(&config.executor);
40		let client =
41			sc_service::new_full_client::<B, RA, _>(&config, None, executor, Default::default())?;
42		let inspect = Inspector::<B>::new(client);
43
44		match &self.command {
45			InspectSubCmd::Block { input } => {
46				let input = input.parse()?;
47				let res = inspect.block(input).map_err(|e| e.to_string())?;
48				println!("{res}");
49				Ok(())
50			},
51			InspectSubCmd::Extrinsic { input } => {
52				let input = input.parse()?;
53				let res = inspect.extrinsic(input).map_err(|e| e.to_string())?;
54				println!("{res}");
55				Ok(())
56			},
57		}
58	}
59}
60
61impl CliConfiguration for InspectCmd {
62	fn shared_params(&self) -> &SharedParams {
63		&self.shared_params
64	}
65
66	fn import_params(&self) -> Option<&ImportParams> {
67		Some(&self.import_params)
68	}
69}