/// Parse command line arguments into service configuration.
Parse command line arguments into service configuration.
Parse command line arguments into service configuration .
pub fn run() -> Result<()> {
	let cli = Cli::from_args();
	match &cli.subcommand {
		Some(Subcommand::Base(subcommand)) => {
			let runner = cli.create_runner(subcommand)?;
			runner.run_subcommand(subcommand, |mut config| {
				let params = crate::service::new_partial::<
					parachain_runtime::RuntimeApi,
					crate::service::RuntimeExecutor,
				>(&mut config)?;
				Ok((
					params.client,
					params.backend,
					params.import_queue,
					params.task_manager,
				))
			})
		}
		Some(Subcommand::ExportGenesisState(params)) => {
			sc_cli::init_logger("");
			let block = generate_genesis_state(&load_spec(
				&params.chain.clone().unwrap_or_default(),
				params.parachain_id.into(),
			)?)?;
			let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
			if let Some(output) = &params.output {
				std::fs::write(output, header_hex)?;
			} else {
				print!("{}", header_hex);
			}
			Ok(())
		}
		Some(Subcommand::ExportGenesisWasm(params)) => {
			sc_cli::init_logger("");
			let wasm_file =
				extract_genesis_wasm(&cli.load_spec(&params.chain.clone().unwrap_or_default())?)?;
			if let Some(output) = &params.output {
				std::fs::write(output, wasm_file)?;
			} else {
				std::io::stdout().write_all(&wasm_file)?;
			}
			Ok(())
		}
		None => {
			let runner = cli.create_runner(&*cli.run)?;
			runner.run_node_until_exit(|config| {
				// TODO
				let key = Arc::new(sp_core::Pair::generate().0);
				let extension = chain_spec::Extensions::try_get(&config.chain_spec);
				let relay_chain_id = extension.map(|e| e.relay_chain.clone());
				let para_id = extension.map(|e| e.para_id);
				let polkadot_cli = RelayChainCli::new(
					config.base_path.as_ref().map(|x| x.path().join("polkadot")),
					relay_chain_id,
					[RelayChainCli::executable_name().to_string()]
						.iter()
						.chain(cli.relaychain_args.iter()),
				);
				let id = ParaId::from(cli.run.parachain_id.or(para_id).unwrap_or(200));
				let parachain_account =
					AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
				let block =
					generate_genesis_state(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
				let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
				let task_executor = config.task_executor.clone();
				let polkadot_config =
					SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, task_executor)
						.map_err(|err| format!("Relay chain argument error: {}", err))?;
				info!("Parachain id: {:?}", id);
				info!("Parachain Account: {}", parachain_account);
				info!("Parachain genesis state: {}", genesis_state);
				info!(
					"Is collating: {}",
					if cli.run.base.validator { "yes" } else { "no" }
				);
				crate::service::start_node(
					config,
					key,
					polkadot_config,
					id,
					cli.run.base.validator,
				)
				.map(|r| r.0)
			})
		}
	}
}
pub fn run ( ) -> Result < ( ) > { let cli = Cli :: from_args ( ) ; match & cli . subcommand { Some ( Subcommand :: Base ( subcommand ) ) => { let runner = cli . create_runner ( subcommand ) ? ; runner . run_subcommand ( subcommand , | mut config | { let params = crate :: service :: new_partial :: < parachain_runtime :: RuntimeApi , crate :: service :: RuntimeExecutor , > ( & mut config ) ? ; Ok ( ( params . client , params . backend , params . import_queue , params . task_manager , ) ) } ) } Some ( Subcommand :: ExportGenesisState ( params ) ) => { sc_cli :: init_logger ( " " ) ; let block = generate_genesis_state ( & load_spec ( & params . chain . clone ( ) . unwrap_or_default ( ) , params . parachain_id . into ( ) , ) ? ) ? ; let header_hex = format ! ( " " HexDisplay from ( block header ( ) encode ( ) ) ) ; if let Some ( output ) = & params . output { std :: fs :: write ( output , header_hex ) ? ; } else { print ! ( " " header_hex ) ; } Ok ( ( ) ) } Some ( Subcommand :: ExportGenesisWasm ( params ) ) => { sc_cli :: init_logger ( " " ) ; let wasm_file = extract_genesis_wasm ( & cli . load_spec ( & params . chain . clone ( ) . unwrap_or_default ( ) ) ? ) ? ; if let Some ( output ) = & params . output { std :: fs :: write ( output , wasm_file ) ? ; } else { std :: io :: stdout ( ) . write_all ( & wasm_file ) ? ; } Ok ( ( ) ) } None => { let runner = cli . create_runner ( & * cli . run ) ? ; runner . run_node_until_exit ( | config | { // TODO let key = Arc :: new ( sp_core :: Pair :: generate ( ) . 0 ) ; let extension = chain_spec :: Extensions :: try_get ( & config . chain_spec ) ; let relay_chain_id = extension . map ( | e | e . relay_chain . clone ( ) ) ; let para_id = extension . map ( | e | e . para_id ) ; let polkadot_cli = RelayChainCli :: new ( config . base_path . as_ref ( ) . map ( | x | x . path ( ) . join ( " " ) ) , relay_chain_id , [ RelayChainCli :: executable_name ( ) . to_string ( ) ] . iter ( ) . chain ( cli . relaychain_args . iter ( ) ) , ) ; let id = ParaId :: from ( cli . run . parachain_id . or ( para_id ) . unwrap_or ( 200 ) ) ; let parachain_account = AccountIdConversion :: < polkadot_primitives :: v0 :: AccountId > :: into_account ( & id ) ; let block = generate_genesis_state ( & config . chain_spec ) . map_err ( | e | format ! ( " " e ) ) ? ; let genesis_state = format ! ( " " HexDisplay from ( block header ( ) encode ( ) ) ) ; let task_executor = config . task_executor . clone ( ) ; let polkadot_config = SubstrateCli :: create_configuration ( & polkadot_cli , & polkadot_cli , task_executor ) . map_err ( | err | format ! ( " " err ) ) ? ; info ! ( " " id ) ; info ! ( " " parachain_account ) ; info ! ( " " genesis_state ) ; info ! ( " " if cli run base validator { " " } else { " " } ) ; crate :: service :: start_node ( config , key , polkadot_config , id , cli . run . base . validator , ) . map ( | r | r . 0 ) } ) } } }
Parse command line arguments into service configuration.
Parse command line arguments into service configuration .