From 5da24e5dc3d9bfa0bf7e26c240bee10d84cdbd6f Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 4 Aug 2016 09:22:54 +0200 Subject: [PATCH] fixed parsing export params, fixes #1826 --- parity/configuration.rs | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index da3c90ddd..449ce96f8 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -37,7 +37,7 @@ use dir::Directories; use dapps::Configuration as DappsConfiguration; use signer::Configuration as SignerConfiguration; use run::RunCmd; -use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain}; +use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat}; use presale::ImportWallet; use account::{AccountCmd, NewAccount, ImportAccounts}; @@ -88,6 +88,7 @@ impl Configuration { let signer_port = self.signer_port(); let dapps_conf = self.dapps_config(); let signer_conf = self.signer_config(); + let format = try!(self.format()); let cmd = if self.args.flag_version { Cmd::Version @@ -128,7 +129,7 @@ impl Configuration { cache_config: cache_config, dirs: dirs, file_path: self.args.arg_file.clone(), - format: None, + format: format, pruning: pruning, compaction: compaction, wal: wal, @@ -144,7 +145,7 @@ impl Configuration { cache_config: cache_config, dirs: dirs, file_path: self.args.arg_file.clone(), - format: None, + format: format, pruning: pruning, compaction: compaction, wal: wal, @@ -228,6 +229,13 @@ impl Configuration { to_address(self.args.flag_etherbase.clone().or(self.args.flag_author.clone())) } + fn format(&self) -> Result, String> { + match self.args.flag_format { + Some(ref f) => Ok(Some(try!(f.parse()))), + None => Ok(None), + } + } + fn cache_config(&self) -> CacheConfig { match self.args.flag_cache_size.or(self.args.flag_cache) { Some(size) => CacheConfig::new_with_total_cache_size(size), @@ -548,7 +556,7 @@ mod tests { use ethcore::client::{VMType, BlockID}; use helpers::{replace_home, default_network_config}; use run::RunCmd; - use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain}; + use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat}; use presale::ImportWallet; use account::{AccountCmd, NewAccount, ImportAccounts}; use devtools::{RandomTempPath}; @@ -623,7 +631,7 @@ mod tests { cache_config: Default::default(), dirs: Default::default(), file_path: Some("blockchain.json".into()), - format: None, + format: Default::default(), pruning: Default::default(), compaction: Default::default(), wal: true, @@ -654,6 +662,27 @@ mod tests { }))); } + #[test] + fn test_command_blockchain_export_with_custom_format() { + let args = vec!["parity", "export", "--format", "hex", "blockchain.json"]; + let conf = Configuration::parse(args).unwrap(); + assert_eq!(conf.into_command().unwrap(), Cmd::Blockchain(BlockchainCmd::Export(ExportBlockchain { + spec: Default::default(), + logger_config: Default::default(), + cache_config: Default::default(), + dirs: Default::default(), + file_path: Some("blockchain.json".into()), + pruning: Default::default(), + format: Some(DataFormat::Hex), + compaction: Default::default(), + wal: true, + mode: Default::default(), + tracing: Default::default(), + from_block: BlockID::Number(1), + to_block: BlockID::Latest, + }))); + } + #[test] fn test_command_signer_new_token() { let args = vec!["parity", "signer", "new-token"];