diff --git a/Cargo.toml b/Cargo.toml index b74ab4e0a..82658c6ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ time = "0.1" evmjit = { path = "rust-evmjit", optional = true } ethash = { path = "ethash" } num_cpus = "0.2" +docopt = "0.6" ctrlc = "1.0" clippy = "0.0.37" diff --git a/res/ethereum/frontier.json b/res/ethereum/frontier.json index eaf0ef4c1..9cb456ce8 100644 --- a/res/ethereum/frontier.json +++ b/res/ethereum/frontier.json @@ -26,6 +26,11 @@ "gasLimit": "0x1388", "stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544" }, + "nodes": [ + "enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303", + "enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303", + "enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303" + ], "accounts": { "0000000000000000000000000000000000000001": { "builtin": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, "0000000000000000000000000000000000000002": { "builtin": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs index ff81aae31..31bb79d8e 100644 --- a/src/bin/client/main.rs +++ b/src/bin/client/main.rs @@ -1,6 +1,11 @@ +#![feature(plugin)] +// TODO: uncomment once this can be made to work. +//#![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; extern crate ctrlc; @@ -15,8 +20,27 @@ use ethcore::service::{ClientService, NetSyncMessage}; use ethcore::ethereum; use ethcore::blockchain::CacheSize; use ethcore::sync::EthSync; +use docopt::Docopt; -fn setup_log() { +const USAGE: &'static str = " +Parity. Ethereum Client. + +Usage: + parity [options] + parity [options] ... + +Options: + -l --logging LOGGING Specify the logging level + -h --help Show this screen. +"; + +#[derive(Debug, RustcDecodable)] +struct Args { + arg_enode: Option>, + flag_logging: Option, +} + +fn setup_log(init: &Option) { let mut builder = LogBuilder::new(); builder.filter(None, LogLevelFilter::Info); @@ -24,18 +48,25 @@ 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 spec = ethereum::new_frontier(); - let mut net_settings = NetworkConfiguration::new(); - let args: Vec<_> = env::args().collect(); - if args.len() == 2 { - net_settings.boot_nodes = Some(vec! [args[1].trim_matches('\"').to_string()]); - } + 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 init_nodes = match &args.arg_enode { + &None => spec.nodes().clone(), + &Some(ref enodes) => enodes.clone(), + }; + let mut net_settings = NetworkConfiguration::new(); + net_settings.boot_nodes = init_nodes; let mut service = ClientService::start(spec, net_settings).unwrap(); let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: service.sync() }); service.io().register_handler(io_handler).expect("Error registering IO handler"); diff --git a/src/lib.rs b/src/lib.rs index ca5bbcb84..262f8682f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,6 +91,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 diff --git a/src/service.rs b/src/service.rs index ce2c30720..8c900d20a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -47,6 +47,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 { self.net_service.io() diff --git a/src/spec.rs b/src/spec.rs index 086b76339..9f98d5e2a 100644 --- a/src/spec.rs +++ b/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, + // Parameters concerning operation of the specific engine we're using. // Name -> RLP-encoded value /// TODO [Gav Wood] Please document me @@ -128,6 +131,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 { &self.nodes } + /// TODO [Gav Wood] Please document me pub fn genesis_header(&self) -> Header { Header { @@ -197,6 +203,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.clone()) } else {None}).collect() + } else { Vec::new() }; + let genesis = &json["genesis"];//.as_object().expect("No genesis object in JSON"); let (seal_fields, seal_rlp) = { @@ -213,12 +223,12 @@ impl FromJson for Spec { ) } }; - Spec { name: json.find("name").map_or("unknown", |j| j.as_string().unwrap()).to_owned(), engine_name: json["engineName"].as_string().unwrap().to_owned(), 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(), diff --git a/util/src/network/host.rs b/util/src/network/host.rs index 67338b83f..6f306ecb0 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -42,7 +42,7 @@ pub struct NetworkConfiguration { /// Pin to boot nodes only pub pin: bool, /// List of initial node addresses - pub boot_nodes: Option>, + pub boot_nodes: Vec, /// Use provided node key instead of default pub use_secret: Option, } @@ -56,7 +56,7 @@ impl NetworkConfiguration { nat_enabled: true, discovery_enabled: true, pin: false, - boot_nodes: None, + boot_nodes: Vec::new(), use_secret: None, } } @@ -304,16 +304,8 @@ impl Host where Message: Send + Sync + Clone { */ let boot_nodes = host.info.read().unwrap().config.boot_nodes.clone(); - if boot_nodes.is_none() { - // GO bootnodes - host.add_node("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303"); // IE - host.add_node("enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303"); // BR - host.add_node("enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303"); // SG - } - else { - for n in boot_nodes.unwrap() { - host.add_node(&n); - } + for n in boot_nodes { + host.add_node(&n); } host }