From e987a492dc952ff458b697925ef4dcc7d296f2e6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 15:51:48 +0100 Subject: [PATCH 1/2] --chain option for setting which network to go on. Add contents function to util. --- Cargo.toml | 1 + parity/main.rs | 38 ++++++++++++++++++++++++++++++++------ util/src/misc.rs | 9 +++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1eac83ac3..836967631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ ethcore = { path = "ethcore" } ethsync = { path = "sync" } ethcore-rpc = { path = "rpc", optional = true } fdlimit = { path = "util/fdlimit" } +target_info = "0.1" [features] default = ["rpc"] diff --git a/parity/main.rs b/parity/main.rs index d423caa64..43a249886 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -29,6 +29,7 @@ extern crate log as rlog; extern crate env_logger; extern crate ctrlc; extern crate fdlimit; +extern crate target_info; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; @@ -39,23 +40,25 @@ use rlog::{LogLevelFilter}; use env_logger::LogBuilder; use ctrlc::CtrlC; use util::*; +use ethcore::spec::*; use ethcore::client::*; use ethcore::service::{ClientService, NetSyncMessage}; use ethcore::ethereum; use ethcore::blockchain::CacheSize; use ethsync::EthSync; +use target_info::Target; docopt!(Args derive Debug, " Parity. Ethereum Client. + By Wood/Paronyan/Kotewicz/Drwięga/Volf. + Copyright 2015, 2016 Ethcore (UK) Limited Usage: - parity [options] - parity [options] ... + parity [options] [ ... ] Options: - -l --logging LOGGING Specify the logging level. - -j --jsonrpc Enable the JSON-RPC API sever. - --jsonrpc-url URL Specify URL for JSON-RPC API server [default: 127.0.0.1:8545]. + --chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file + or frontier, mainnet, morden, or testnet [default: frontier]. --listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304]. --public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304]. @@ -64,6 +67,11 @@ Options: --cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes [default: 16384]. --cache-max-size BYTES Specify the maximum size of the blockchain cache in bytes [default: 262144]. + -j --jsonrpc Enable the JSON-RPC API sever. + --jsonrpc-url URL Specify URL for JSON-RPC API server [default: 127.0.0.1:8545]. + + -l --logging LOGGING Specify the logging level. + -v --version Show information about version. -h --help Show this screen. ", flag_cache_pref_size: usize, flag_cache_max_size: usize, flag_address: Option); @@ -100,10 +108,28 @@ fn setup_rpc_server(_client: Arc, _sync: Arc, _url: &str) { fn main() { let args: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); + if args.flag_version { + println!(" +Parity version {} ({}-{}-{}) +Copyright 2015, 2016 Ethcore (UK) Limited +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + +By Wood/Paronyan/Kotewicz/Drwięga/Volf. +", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os()); + return; + } + setup_log(&args.flag_logging); unsafe { ::fdlimit::raise_fd_limit(); } - let spec = ethereum::new_frontier(); + let spec = match args.flag_chain.as_ref() { + "frontier" | "mainnet" => ethereum::new_frontier(), + "morden" | "testnet" => ethereum::new_morden(), + "olympic" => ethereum::new_olympic(), + f => Spec::from_json_utf8(contents(f).expect("Couldn't read chain specification file. Sure it exists?").as_ref()), + }; let init_nodes = match args.arg_enode.len() { 0 => spec.nodes().clone(), _ => args.arg_enode.clone(), diff --git a/util/src/misc.rs b/util/src/misc.rs index 43027015e..6e2240d33 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -16,6 +16,7 @@ //! Diff misc. +use std::fs::File; use common::*; #[derive(Debug,Clone,PartialEq,Eq)] @@ -53,3 +54,11 @@ pub enum Filth { /// Data has been changed. Dirty, } + +/// Read the whole contents of a file `name`. +pub fn contents(name: &str) -> Result { + let mut file = try!(File::open(name)); + let mut ret: Vec = Vec::new(); + try!(file.read_to_end(&mut ret)); + Ok(ret) +} From 8be5340385f72a4b7fa8c60f6028cfe84fb61934 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 16:19:12 +0100 Subject: [PATCH 2/2] Tabs! --- util/src/misc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/src/misc.rs b/util/src/misc.rs index 6e2240d33..ae3dbc5bf 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -58,7 +58,7 @@ pub enum Filth { /// Read the whole contents of a file `name`. pub fn contents(name: &str) -> Result { let mut file = try!(File::open(name)); - let mut ret: Vec = Vec::new(); - try!(file.read_to_end(&mut ret)); - Ok(ret) + let mut ret: Vec = Vec::new(); + try!(file.read_to_end(&mut ret)); + Ok(ret) }