referrerpolicy=no-referrer-when-downgrade

sc_cli/commands/
key.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//! Key related CLI utilities
20
21use super::{
22	generate::GenerateCmd, generate_node_key::GenerateNodeKeyCmd, insert_key::InsertKeyCmd,
23	inspect_key::InspectKeyCmd, inspect_node_key::InspectNodeKeyCmd,
24};
25use crate::{Error, SubstrateCli};
26
27/// Key utilities for the cli.
28#[derive(Debug, clap::Subcommand)]
29pub enum KeySubcommand {
30	/// Generate a random node key, write it to a file or stdout and write the
31	/// corresponding peer-id to stderr
32	GenerateNodeKey(GenerateNodeKeyCmd),
33
34	/// Generate a random account
35	Generate(GenerateCmd),
36
37	/// Gets a public key and a SS58 address from the provided Secret URI
38	Inspect(InspectKeyCmd),
39
40	/// Load a node key from a file or stdin and print the corresponding peer-id
41	InspectNodeKey(InspectNodeKeyCmd),
42
43	/// Insert a key to the keystore of a node.
44	Insert(InsertKeyCmd),
45}
46
47impl KeySubcommand {
48	/// run the key subcommands
49	pub fn run<C: SubstrateCli>(&self, cli: &C) -> Result<(), Error> {
50		match self {
51			KeySubcommand::GenerateNodeKey(cmd) => {
52				let chain_spec = cli.load_spec(cmd.chain.as_deref().unwrap_or(""))?;
53				cmd.run(chain_spec.id(), &C::executable_name())
54			},
55			KeySubcommand::Generate(cmd) => cmd.run(),
56			KeySubcommand::Inspect(cmd) => cmd.run(),
57			KeySubcommand::Insert(cmd) => cmd.run(cli),
58			KeySubcommand::InspectNodeKey(cmd) => cmd.run(),
59		}
60	}
61}