// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see .
use std::{net::SocketAddr, path::PathBuf};
use polkadot_service::{ChainSpec, ParaId, PrometheusConfig};
use sc_cli::{
CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
Result as CliResult, SharedParams, SubstrateCli,
};
use sc_service::BasePath;
#[derive(Debug, clap::Parser)]
#[command(
version,
propagate_version = true,
args_conflicts_with_subcommands = true,
subcommand_negates_reqs = true
)]
pub struct TestCollatorCli {
#[command(subcommand)]
pub subcommand: Option,
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,
#[arg(default_value_t = 2000u32)]
pub parachain_id: u32,
/// Relay chain arguments
#[arg(raw = true)]
pub relaychain_args: Vec,
#[arg(long)]
pub use_null_consensus: bool,
#[arg(long)]
pub disable_block_announcements: bool,
#[arg(long)]
pub fail_pov_recovery: bool,
}
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd),
/// Export the genesis state of the parachain.
ExportGenesisState(ExportGenesisStateCommand),
/// Export the genesis wasm of the parachain.
ExportGenesisWasm(ExportGenesisWasmCommand),
}
#[derive(Debug, clap::Parser)]
#[group(skip)]
pub struct ExportGenesisStateCommand {
#[arg(default_value_t = 2000u32)]
pub parachain_id: u32,
#[command(flatten)]
pub base: cumulus_client_cli::ExportGenesisStateCommand,
}
impl CliConfiguration for ExportGenesisStateCommand {
fn shared_params(&self) -> &SharedParams {
&self.base.shared_params
}
}
/// Command for exporting the genesis wasm file.
#[derive(Debug, clap::Parser)]
#[group(skip)]
pub struct ExportGenesisWasmCommand {
#[arg(default_value_t = 2000u32)]
pub parachain_id: u32,
#[command(flatten)]
pub base: cumulus_client_cli::ExportGenesisWasmCommand,
}
impl CliConfiguration for ExportGenesisWasmCommand {
fn shared_params(&self) -> &SharedParams {
&self.base.shared_params
}
}
#[derive(Debug)]
pub struct RelayChainCli {
/// The actual relay chain cli object.
pub base: polkadot_cli::RunCmd,
/// Optional chain id that should be passed to the relay chain.
pub chain_id: Option,
/// The base path that should be used by the relay chain.
pub base_path: Option,
}
impl RelayChainCli {
/// Parse the relay chain CLI parameters using the para chain `Configuration`.
pub fn new<'a>(
para_config: &sc_service::Configuration,
relay_chain_args: impl Iterator,
) -> Self {
let base_path = para_config.base_path.path().join("polkadot");
Self {
base_path: Some(base_path),
chain_id: None,
base: clap::Parser::parse_from(relay_chain_args),
}
}
}
impl CliConfiguration for RelayChainCli {
fn shared_params(&self) -> &SharedParams {
self.base.base.shared_params()
}
fn import_params(&self) -> Option<&ImportParams> {
self.base.base.import_params()
}
fn network_params(&self) -> Option<&NetworkParams> {
self.base.base.network_params()
}
fn keystore_params(&self) -> Option<&KeystoreParams> {
self.base.base.keystore_params()
}
fn base_path(&self) -> CliResult