diff --git a/parity/main.rs b/parity/main.rs index 731bba9a1..12dd569a3 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -39,6 +39,7 @@ extern crate rpassword; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; +use std::fs::File; use std::net::{SocketAddr, IpAddr}; use std::env; use std::process::exit; @@ -89,6 +90,11 @@ Protocol Options: [default: $HOME/.web3/keys]. --identity NAME Specify your node's name. +Account Options: + --unlock ACCOUNT Unlock ACCOUNT for the duration of the execution. + --password FILE Provide a file containing a password for unlocking + an account. + Networking Options: --port PORT Override the port on which the node should listen [default: 30303]. @@ -176,6 +182,8 @@ struct Args { flag_chain: String, flag_db_path: String, flag_identity: String, + flag_unlock: Vec, + flag_password: Vec, flag_cache: Option, flag_keys_path: String, flag_bootnodes: Option, @@ -490,6 +498,26 @@ impl Configuration { } } + fn account_service(&self) -> AccountService { + // Secret Store + let passwords = self.args.flag_password.iter().map(|filename| { + let mut buffer = String::new(); + File::open(filename).and_then(|mut f| f.read_to_string(&mut buffer)).unwrap_or_else(|_| die!("{} Unable to read password file. Ensure it exists and permissions are correct.", filename)); + buffer + }).collect::>(); + + let account_service = AccountService::new(); + for d in &self.args.flag_unlock { + let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| { + die!("{}: Invalid address for --unlock. Must be 40 hex characters, without the 0x at the beginning.", d) + }); + if passwords.iter().find(|p| account_service.unlock_account(&a, p).is_ok()).is_none() { + die!("No password given to unlock account {}. Pass the password using `--password`.", a); + } + } + account_service + } + #[cfg_attr(feature="dev", allow(useless_format))] fn execute_client(&self) { // Setup panic handler @@ -504,6 +532,9 @@ impl Configuration { let net_settings = self.net_settings(&spec); let sync_config = self.sync_config(&spec); + // Secret Store + let account_service = Arc::new(self.account_service()); + // Build client let mut service = ClientService::start(self.client_config(), spec, net_settings, &Path::new(&self.path())).unwrap(); panic_handler.forward_from(&service); @@ -519,9 +550,6 @@ impl Configuration { // Sync let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone()); - // Secret Store - let account_service = Arc::new(AccountService::new()); - // Setup rpc if self.args.flag_jsonrpc || self.args.flag_rpc { let url = format!("{}:{}",