@@ -1,6 +1,10 @@
|
||||
#![feature(plugin)]
|
||||
//#![plugin(docopt_macros)]
|
||||
|
||||
extern crate docopt;
|
||||
extern crate rustc_serialize;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate ethcore;
|
||||
extern crate rustc_serialize;
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
@@ -14,8 +18,27 @@ use ethcore::service::ClientService;
|
||||
use ethcore::ethereum;
|
||||
use ethcore::blockchain::CacheSize;
|
||||
use ethcore::sync::*;
|
||||
use docopt::Docopt;
|
||||
|
||||
fn setup_log() {
|
||||
const USAGE: &'static str = "
|
||||
Parity. Ethereum Client.
|
||||
|
||||
Usage:
|
||||
parity [options]
|
||||
parity [options] <enode>...
|
||||
|
||||
Options:
|
||||
-l --logging LOGGING Specify the logging level
|
||||
-h --help Show this screen.
|
||||
";
|
||||
|
||||
#[derive(Debug, RustcDecodable)]
|
||||
struct Args {
|
||||
arg_enode: Option<Vec<String>>,
|
||||
flag_logging: Option<String>,
|
||||
}
|
||||
|
||||
fn setup_log(init: &Option<String>) {
|
||||
let mut builder = LogBuilder::new();
|
||||
builder.filter(None, LogLevelFilter::Info);
|
||||
|
||||
@@ -23,14 +46,28 @@ fn setup_log() {
|
||||
builder.parse(&env::var("RUST_LOG").unwrap());
|
||||
}
|
||||
|
||||
if let &Some(ref x) = init {
|
||||
builder.parse(x);
|
||||
}
|
||||
|
||||
builder.init().unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
setup_log();
|
||||
let args: Args = Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit());
|
||||
|
||||
setup_log(&args.flag_logging);
|
||||
|
||||
let spec = ethereum::new_frontier();
|
||||
let mut service = ClientService::start(spec).unwrap();
|
||||
|
||||
let init_nodes = match &args.arg_enode {
|
||||
&None => spec.nodes().clone(),
|
||||
&Some(ref enodes) => enodes.clone(),
|
||||
};
|
||||
|
||||
let mut service = ClientService::start(spec, &init_nodes).unwrap();
|
||||
let io_handler = Box::new(ClientIoHandler { client: service.client(), timer: 0, info: Default::default() });
|
||||
|
||||
service.io().register_handler(io_handler).expect("Error registering IO handler");
|
||||
loop {
|
||||
let mut cmd = String::new();
|
||||
|
||||
@@ -89,6 +89,8 @@ extern crate evmjit;
|
||||
#[macro_use]
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
// NOTE: Add doc parser exception for these pub declarations.
|
||||
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod common;
|
||||
/// TODO [Tomusdrw] Please document me
|
||||
|
||||
@@ -13,8 +13,8 @@ pub struct ClientService {
|
||||
|
||||
impl ClientService {
|
||||
/// Start the service in a separate thread.
|
||||
pub fn start(spec: Spec) -> Result<ClientService, Error> {
|
||||
let mut net_service = try!(NetworkService::start());
|
||||
pub fn start(spec: Spec, init_nodes: &Vec<String>) -> Result<ClientService, Error> {
|
||||
let mut net_service = try!(NetworkService::start(init_nodes));
|
||||
info!("Starting {}", net_service.host_info());
|
||||
info!("Configured for {} using {} engine", spec.name, spec.engine_name);
|
||||
let mut dir = env::home_dir().unwrap();
|
||||
@@ -33,6 +33,11 @@ impl ClientService {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the network service.
|
||||
pub fn add_node(&mut self, _enode: &str) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// TODO [arkpar] Please document me
|
||||
pub fn io(&mut self) -> &mut IoService<NetSyncMessage> {
|
||||
self.net_service.io()
|
||||
|
||||
12
src/spec.rs
12
src/spec.rs
@@ -73,6 +73,9 @@ pub struct Spec {
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub engine_name: String,
|
||||
|
||||
/// Known nodes on the network in enode format.
|
||||
pub nodes: Vec<String>,
|
||||
|
||||
// Parameters concerning operation of the specific engine we're using.
|
||||
// Name -> RLP-encoded value
|
||||
/// TODO [Gav Wood] Please document me
|
||||
@@ -127,6 +130,9 @@ impl Spec {
|
||||
self.state_root_memo.read().unwrap().as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Get the known knodes of the network in enode format.
|
||||
pub fn nodes(&self) -> &Vec<String> { &self.nodes }
|
||||
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub fn genesis_header(&self) -> Header {
|
||||
Header {
|
||||
@@ -196,6 +202,10 @@ impl FromJson for Spec {
|
||||
}
|
||||
}
|
||||
|
||||
let nodes = if let Some(&Json::Array(ref ns)) = json.find("nodes") {
|
||||
ns.iter().filter_map(|n| if let &Json::String(ref s) = n { Some(s.to_string()) } else {None}).collect()
|
||||
} else { Vec::new() };
|
||||
|
||||
let genesis = &json["genesis"];//.as_object().expect("No genesis object in JSON");
|
||||
|
||||
let (seal_fields, seal_rlp) = {
|
||||
@@ -212,12 +222,12 @@ impl FromJson for Spec {
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Spec {
|
||||
name: json.find("name").map(|j| j.as_string().unwrap()).unwrap_or("unknown").to_string(),
|
||||
engine_name: json["engineName"].as_string().unwrap().to_string(),
|
||||
engine_params: json_to_rlp_map(&json["params"]),
|
||||
nodes: nodes,
|
||||
builtins: builtins,
|
||||
parent_hash: H256::from_str(&genesis["parentHash"].as_string().unwrap()[2..]).unwrap(),
|
||||
author: Address::from_str(&genesis["author"].as_string().unwrap()[2..]).unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user