Skip to content
Snippets Groups Projects
Commit 8ffa85fd authored by Wei Tang's avatar Wei Tang
Browse files

Add a cli mod

parent 61e079dc
Branches
No related merge requests found
This diff is collapsed.
......@@ -10,6 +10,7 @@ members = [
"service",
"network",
"transaction-pool",
"cli",
"util/ssz",
"util/ssz-derive",
"util/shuffling",
......
[package]
name = "cli"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
log = "0.4"
tokio = "0.1.7"
exit-future = "0.1"
substrate-cli = { git = "https://github.com/paritytech/substrate" }
shasper-service = { path = "../service" }
name: shasper-node
author: "Parity Team <admin@parity.io>"
about: Substrate Shasper Node Rust Implementation
args:
- log:
short: l
value_name: LOG_PATTERN
help: Sets a custom logging
takes_value: true
subcommands:
- validator:
about: Run validator node
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Initialization errors.
use client;
error_chain! {
foreign_links {
Io(::std::io::Error) #[doc="IO error"];
Cli(::clap::Error) #[doc="CLI error"];
}
links {
Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
}
}
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Substrate CLI library.
#![warn(missing_docs)]
#![warn(unused_extern_crates)]
extern crate tokio;
extern crate substrate_cli as cli;
extern crate shasper_service as service;
extern crate exit_future;
#[macro_use]
extern crate log;
pub use cli::error;
use tokio::runtime::Runtime;
pub use service::{Components as ServiceComponents, Service, ServiceFactory};
pub use cli::{VersionInfo, IntoExit};
/// The chain specification option.
#[derive(Clone, Debug)]
pub enum ChainSpec {
/// Whatever the current runtime is, with just Alice as an auth.
Development,
}
/// Get a chain config from a spec setting.
impl ChainSpec {
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
Ok(match self {
ChainSpec::Development => service::chain_spec::development_config(),
})
}
pub(crate) fn from(s: &str) -> Option<Self> {
match s {
"dev" => Some(ChainSpec::Development),
_ => None,
}
}
}
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
})
}
/// Parse command line arguments into service configuration.
pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Result<()> where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
E: IntoExit,
{
match cli::prepare_execution::<service::Factory, _, _, _, _>(args, exit, version, load_spec, "substrate-node")? {
cli::Action::ExecutedInternally => (),
cli::Action::RunService((config, exit)) => {
info!("Substrate Node");
info!(" version {}", config.full_version());
info!(" by Parity Technologies, 2017, 2018");
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);
let mut runtime = Runtime::new()?;
let executor = runtime.executor();
match config.roles == service::Roles::LIGHT {
true => run_until_exit(&mut runtime, service::Factory::new_light(config, executor)?, exit)?,
false => run_until_exit(&mut runtime, service::Factory::new_full(config, executor)?, exit)?,
}
}
}
Ok(())
}
fn run_until_exit<C, E>(
runtime: &mut Runtime,
service: service::Service<C>,
e: E,
) -> error::Result<()>
where
C: service::Components,
E: IntoExit,
{
let (exit_send, exit) = exit_future::signal();
let executor = runtime.executor();
cli::informant::start(&service, exit.clone(), executor.clone());
let _ = runtime.block_on(e.into_exit());
exit_send.fire();
Ok(())
}
......@@ -5,6 +5,7 @@ authors = ["Parity Team <admin@parity.io>"]
[dependencies]
tokio = "0.1.7"
parity-codec = "2.0"
shasper-runtime = { path = "../runtime" }
shasper-network = { path = "../network" }
shasper-executor = { path = "../executor" }
......
use primitives::storage::well_known_keys;
use runtime_primitives::StorageMap;
use codec::Joiner;
use service::ChainSpec;
fn development_genesis() -> StorageMap {
let wasm_runtime = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/shasper_runtime.compact.wasm").to_vec();
let mut map = StorageMap::new();
map.insert(well_known_keys::CODE.into(), wasm_runtime);
map.insert(well_known_keys::HEAP_PAGES.into(), vec![].and(&(16 as u64)));
map.insert(well_known_keys::AUTHORITY_COUNT.into(), vec![].and(&(1 as u32)));
map
}
pub fn development_config() -> ChainSpec<StorageMap> {
ChainSpec::from_genesis("Shasper Development", "shasper_dev", development_genesis, vec![], None, None)
}
......@@ -6,20 +6,27 @@ extern crate sr_primitives as runtime_primitives;
extern crate substrate_primitives as primitives;
extern crate substrate_client as client;
extern crate substrate_service as service;
extern crate parity_codec as codec;
extern crate tokio;
pub mod chain_spec;
use runtime::Block;
use network::Protocol;
use primitives::H256;
use transaction_pool::TransactionPool;
use service::TransactionPoolOptions;
use runtime_primitives::StorageMap;
use tokio::runtime::TaskExecutor;
use std::sync::Arc;
pub type ChainSpec = service::ChainSpec<StorageMap>;
/// All configuration for the node.
pub type Configuration = service::FactoryFullConfiguration<Factory>;
pub use service::{
Roles, PruningMode, TransactionPoolOptions, ServiceFactory,
ErrorKind, Error, ComponentBlock, LightComponents, FullComponents, Components};
pub struct Factory;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment