diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index aa7b460db..b8b10ec1d 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -32,6 +32,8 @@ usage! { cmd_snapshot: bool, cmd_restore: bool, cmd_ui: bool, + cmd_tools: bool, + cmd_hash: bool, // Arguments arg_pid_file: String, @@ -441,6 +443,8 @@ mod tests { cmd_snapshot: false, cmd_restore: false, cmd_ui: false, + cmd_tools: false, + cmd_hash: false, // Arguments arg_pid_file: "".into(), diff --git a/parity/cli/usage.txt b/parity/cli/usage.txt index 1749cd4b7..a94f55a8d 100644 --- a/parity/cli/usage.txt +++ b/parity/cli/usage.txt @@ -14,6 +14,7 @@ Usage: parity signer new-token [options] parity snapshot [options] parity restore [ ] [options] + parity tools hash Operating Options: --mode MODE Set the operating mode. MODE can be one of: @@ -283,4 +284,3 @@ Miscellaneous Options: --no-color Don't use terminal color codes in output. (default: {flag_no_color}) -v --version Show information about version. -h --help Show this screen. - diff --git a/parity/configuration.rs b/parity/configuration.rs index 6ee89eb35..1aa338c26 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -51,6 +51,7 @@ pub enum Cmd { Blockchain(BlockchainCmd), SignerToken(String), Snapshot(SnapshotCommand), + Hash(Option), } #[derive(Debug, PartialEq)] @@ -94,8 +95,10 @@ impl Configuration { let cmd = if self.args.flag_version { Cmd::Version - } else if self.args.cmd_signer { + } else if self.args.cmd_signer && self.args.cmd_new_token { Cmd::SignerToken(dirs.signer) + } else if self.args.cmd_tools && self.args.cmd_hash { + Cmd::Hash(self.args.arg_file) } else if self.args.cmd_account { let account_cmd = if self.args.cmd_new { let new_acc = NewAccount { diff --git a/parity/main.rs b/parity/main.rs index 8cb348958..0cb466dc3 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -111,10 +111,23 @@ mod boot; mod stratum; use std::{process, env}; +use std::io::BufReader; +use std::fs::File; +use util::sha3::sha3; use cli::Args; use configuration::{Cmd, Configuration}; use deprecated::find_deprecated; +fn print_hash_of(maybe_file: Option) -> Result { + if let Some(file) = maybe_file { + let mut f = BufReader::new(try!(File::open(&file).map_err(|_| "Unable to open file".to_owned()))); + let hash = try!(sha3(&mut f).map_err(|_| "Unable to read from file".to_owned())); + Ok(hash.hex()) + } else { + Err("Streaming from standard input not yet supported. Specify a file.".to_owned()) + } +} + fn execute(command: Cmd) -> Result { match command { Cmd::Run(run_cmd) => { @@ -122,6 +135,7 @@ fn execute(command: Cmd) -> Result { Ok("".into()) }, Cmd::Version => Ok(Args::print_version()), + Cmd::Hash(maybe_file) => print_hash_of(maybe_file), Cmd::Account(account_cmd) => account::execute(account_cmd), Cmd::ImportPresaleWallet(presale_cmd) => presale::execute(presale_cmd), Cmd::Blockchain(blockchain_cmd) => blockchain::execute(blockchain_cmd),