diff --git a/polkadot/cli/src/cli.rs b/polkadot/cli/src/cli.rs index bc5b80f9a945e35d784502212b52c34a0d50f03a..3b3600dc38f53657967eb01f953efe43f5bb450e 100644 --- a/polkadot/cli/src/cli.rs +++ b/polkadot/cli/src/cli.rs @@ -25,6 +25,7 @@ use std::path::PathBuf; #[derive(Debug, Parser)] pub enum Subcommand { /// Build a chain specification. + #[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")] BuildSpec(sc_cli::BuildSpecCmd), /// Export the chain specification. diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs index abecdc0bc098721e651f4e27e8b1822b233938ba..cb7a35f1e53b00743c9cba604e71772af193a599 100644 --- a/polkadot/cli/src/command.rs +++ b/polkadot/cli/src/command.rs @@ -287,14 +287,15 @@ pub fn run() -> Result<()> { None, polkadot_node_metrics::logger_hook(), ), + #[allow(deprecated)] Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?) }, Some(Subcommand::ExportChainSpec(cmd)) => { // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(spec).map_err(Into::into) + let runner = cli.create_runner(cmd)?; + Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?) }, Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?; diff --git a/substrate/bin/node/cli/src/cli.rs b/substrate/bin/node/cli/src/cli.rs index 0403779cde850a6fc2bb8a6b6de473485a42adc3..098b3d5ccccac25e29eb38702471f5fd5d023a61 100644 --- a/substrate/bin/node/cli/src/cli.rs +++ b/substrate/bin/node/cli/src/cli.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use polkadot_sdk::{sc_cli::ExportChainSpecCmd, *}; +use polkadot_sdk::*; /// An overarching CLI command definition. #[derive(Debug, clap::Parser)] @@ -78,10 +78,11 @@ pub enum Subcommand { Sign(sc_cli::SignCmd), /// Build a chain specification. + #[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")] BuildSpec(sc_cli::BuildSpecCmd), /// Export the chain specification. - ExportChainSpec(ExportChainSpecCmd), + ExportChainSpec(sc_cli::ExportChainSpecCmd), /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/substrate/bin/node/cli/src/command.rs b/substrate/bin/node/cli/src/command.rs index c55f9deae86d1b217f8bf489dd530d77440887ec..16a8ffa5ebf6d9c48213081754177eabe8dc2b52 100644 --- a/substrate/bin/node/cli/src/command.rs +++ b/substrate/bin/node/cli/src/command.rs @@ -95,8 +95,8 @@ pub fn run() -> Result<()> { }, Some(Subcommand::ExportChainSpec(cmd)) => { // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(spec) + let runner = cli.create_runner(cmd)?; + Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?) }, Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -178,6 +178,7 @@ pub fn run() -> Result<()> { Some(Subcommand::Sign(cmd)) => cmd.run(), Some(Subcommand::Verify(cmd)) => cmd.run(), Some(Subcommand::Vanity(cmd)) => cmd.run(), + #[allow(deprecated)] Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) diff --git a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs index c865ead3e7f8bc52b35fab9f0b871833bdfdb2ae..5537c3f07910f3982056aa5bd6ebd68b75ca0dea 100644 --- a/substrate/client/cli/src/commands/export_chain_spec_cmd.rs +++ b/substrate/client/cli/src/commands/export_chain_spec_cmd.rs @@ -23,8 +23,8 @@ use std::{ io::{self, Write}, path::PathBuf, }; - -use crate::{error::Result, SharedParams}; +use std::thread::sleep; +use crate::{error::Result, BuildSpecCmd, CliConfiguration, NodeKeyParams, SharedParams}; /// Export a chain-spec to a JSON file in plain or in raw storage format. /// @@ -42,9 +42,8 @@ use crate::{error::Result, SharedParams}; #[derive(Debug, Clone, Parser)] pub struct ExportChainSpecCmd { /// The chain spec identifier to export. - #[allow(missing_docs)] - #[clap(flatten)] - pub shared_params: SharedParams, + #[arg(long, default_value = "local")] + pub chain: String, /// `chain-spec` JSON file path. If omitted, prints to stdout. #[arg(long)] @@ -69,3 +68,15 @@ impl ExportChainSpecCmd { Ok(()) } } +impl CliConfiguration for ExportChainSpecCmd { + + // If ExportChainSpecCmd doesn’t have shared_params, you must provide some implementation. + fn shared_params(&self) -> &SharedParams { + unimplemented!("ExportChainSpecCmd does not implement shared_params") + } + + // Implement the chain_id method to return the chain identifier. + fn chain_id(&self, _is_dev: bool) -> Result<String> { + Ok(self.chain.clone()) + } +} diff --git a/templates/minimal/node/src/cli.rs b/templates/minimal/node/src/cli.rs index 8ddd7d4fd258ddfaf5201e9e98f3bd8d51784ef6..c07e74acc04dc4ac319034142142d73f259ed25e 100644 --- a/templates/minimal/node/src/cli.rs +++ b/templates/minimal/node/src/cli.rs @@ -15,10 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use polkadot_sdk::{ - sc_cli::{ExportChainSpecCmd, RunCmd}, - *, -}; +use polkadot_sdk::*; #[derive(Debug, Clone)] pub enum Consensus { @@ -52,7 +49,7 @@ pub struct Cli { pub consensus: Consensus, #[clap(flatten)] - pub run: RunCmd, + pub run: sc_cli::RunCmd, } #[derive(Debug, clap::Subcommand)] @@ -62,10 +59,11 @@ pub enum Subcommand { Key(sc_cli::KeySubcommand), /// Build a chain specification. + #[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")] BuildSpec(sc_cli::BuildSpecCmd), /// Export the chain specification. - ExportChainSpec(ExportChainSpecCmd), + ExportChainSpec(sc_cli::ExportChainSpecCmd), /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/minimal/node/src/command.rs b/templates/minimal/node/src/command.rs index ea5684b5f7d7d370cd9eb52fcb9e2628ddc36c0f..5b221272dc1e2c1e305f23751e5bad67bbfc3822 100644 --- a/templates/minimal/node/src/command.rs +++ b/templates/minimal/node/src/command.rs @@ -62,6 +62,7 @@ pub fn run() -> sc_cli::Result<()> { match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli), + #[allow(deprecated)] Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) @@ -76,8 +77,8 @@ pub fn run() -> sc_cli::Result<()> { }, Some(Subcommand::ExportChainSpec(cmd)) => { // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(&*spec) + let runner = cli.create_runner(cmd)?; + Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?) }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index dcd431646078203411d59446ec942a1fbd2a2ede..d0ce913641433254ba8b19fd9b3c6dcef2010c3f 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,4 +1,4 @@ -use polkadot_sdk::{sc_cli::ExportChainSpecCmd, *}; +use polkadot_sdk::*; use std::path::PathBuf; /// Sub-commands supported by the collator. @@ -6,10 +6,11 @@ use std::path::PathBuf; #[derive(Debug, clap::Subcommand)] pub enum Subcommand { /// Build a chain specification. + #[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")] BuildSpec(sc_cli::BuildSpecCmd), /// Export the chain specification. - ExportChainSpec(ExportChainSpecCmd), + ExportChainSpec(sc_cli::ExportChainSpecCmd), /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 983d9ecd0046a89c6be37189b22b622698e8160e..eec37292c2977fa3bd096910bffdd9862b9ca866 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -114,6 +114,7 @@ pub fn run() -> Result<()> { let cli = Cli::from_args(); match &cli.subcommand { + #[allow(deprecated)] Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) @@ -124,9 +125,8 @@ pub fn run() -> Result<()> { }) }, Some(Subcommand::ExportChainSpec(cmd)) => { - // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(&*spec) + let runner = cli.create_runner(cmd)?; + Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?) }, Some(Subcommand::ExportBlocks(cmd)) => { construct_async_run!(|components, cli, cmd, config| { diff --git a/templates/solochain/node/src/cli.rs b/templates/solochain/node/src/cli.rs index ba5dc2caf625eec9ed5ead83f4ae4cb036c3226f..d7edc2850fe353da8b007ab5ccfa6e5622d4f95e 100644 --- a/templates/solochain/node/src/cli.rs +++ b/templates/solochain/node/src/cli.rs @@ -1,12 +1,10 @@ -use sc_cli::{ExportChainSpecCmd, RunCmd}; - #[derive(Debug, clap::Parser)] pub struct Cli { #[command(subcommand)] pub subcommand: Option<Subcommand>, #[clap(flatten)] - pub run: RunCmd, + pub run: sc_cli::RunCmd, } #[derive(Debug, clap::Subcommand)] @@ -17,10 +15,11 @@ pub enum Subcommand { Key(sc_cli::KeySubcommand), /// Build a chain specification. + #[deprecated(note = "build-spec will be removed after 1/04/2026. Use export-chain-spec instead")] BuildSpec(sc_cli::BuildSpecCmd), /// Export the chain specification. - ExportChainSpec(ExportChainSpecCmd), + ExportChainSpec(sc_cli::ExportChainSpecCmd), /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index 5d7cd61a90d5250516b92ab48116e559cf1416c2..6520c862480fcaea9752b6540fe14ef2e53bcaa7 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -51,6 +51,7 @@ pub fn run() -> sc_cli::Result<()> { match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli), + #[allow(deprecated)] Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) @@ -65,8 +66,8 @@ pub fn run() -> sc_cli::Result<()> { }, Some(Subcommand::ExportChainSpec(cmd)) => { // Directly load the embedded chain spec using the CLI’s load_spec method. - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(&*spec) + let runner = cli.create_runner(cmd)?; + Ok(runner.sync_run(|config| cmd.run(config.chain_spec))?) }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?;