Merge pull request #1834 from ethcore/fixed_export_hex

fixed parsing export params, fixes #1826
This commit is contained in:
Marek Kotewicz 2016-08-04 10:34:08 +02:00 committed by GitHub
commit d1fc57d15c

View File

@ -37,7 +37,7 @@ use dir::Directories;
use dapps::Configuration as DappsConfiguration; use dapps::Configuration as DappsConfiguration;
use signer::Configuration as SignerConfiguration; use signer::Configuration as SignerConfiguration;
use run::RunCmd; use run::RunCmd;
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain}; use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet; use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ImportAccounts}; use account::{AccountCmd, NewAccount, ImportAccounts};
@ -88,6 +88,7 @@ impl Configuration {
let signer_port = self.signer_port(); let signer_port = self.signer_port();
let dapps_conf = self.dapps_config(); let dapps_conf = self.dapps_config();
let signer_conf = self.signer_config(); let signer_conf = self.signer_config();
let format = try!(self.format());
let cmd = if self.args.flag_version { let cmd = if self.args.flag_version {
Cmd::Version Cmd::Version
@ -128,7 +129,7 @@ impl Configuration {
cache_config: cache_config, cache_config: cache_config,
dirs: dirs, dirs: dirs,
file_path: self.args.arg_file.clone(), file_path: self.args.arg_file.clone(),
format: None, format: format,
pruning: pruning, pruning: pruning,
compaction: compaction, compaction: compaction,
wal: wal, wal: wal,
@ -144,7 +145,7 @@ impl Configuration {
cache_config: cache_config, cache_config: cache_config,
dirs: dirs, dirs: dirs,
file_path: self.args.arg_file.clone(), file_path: self.args.arg_file.clone(),
format: None, format: format,
pruning: pruning, pruning: pruning,
compaction: compaction, compaction: compaction,
wal: wal, wal: wal,
@ -228,6 +229,13 @@ impl Configuration {
to_address(self.args.flag_etherbase.clone().or(self.args.flag_author.clone())) to_address(self.args.flag_etherbase.clone().or(self.args.flag_author.clone()))
} }
fn format(&self) -> Result<Option<DataFormat>, String> {
match self.args.flag_format {
Some(ref f) => Ok(Some(try!(f.parse()))),
None => Ok(None),
}
}
fn cache_config(&self) -> CacheConfig { fn cache_config(&self) -> CacheConfig {
match self.args.flag_cache_size.or(self.args.flag_cache) { match self.args.flag_cache_size.or(self.args.flag_cache) {
Some(size) => CacheConfig::new_with_total_cache_size(size), Some(size) => CacheConfig::new_with_total_cache_size(size),
@ -548,7 +556,7 @@ mod tests {
use ethcore::client::{VMType, BlockID}; use ethcore::client::{VMType, BlockID};
use helpers::{replace_home, default_network_config}; use helpers::{replace_home, default_network_config};
use run::RunCmd; use run::RunCmd;
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain}; use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet; use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ImportAccounts}; use account::{AccountCmd, NewAccount, ImportAccounts};
use devtools::{RandomTempPath}; use devtools::{RandomTempPath};
@ -623,7 +631,7 @@ mod tests {
cache_config: Default::default(), cache_config: Default::default(),
dirs: Default::default(), dirs: Default::default(),
file_path: Some("blockchain.json".into()), file_path: Some("blockchain.json".into()),
format: None, format: Default::default(),
pruning: Default::default(), pruning: Default::default(),
compaction: Default::default(), compaction: Default::default(),
wal: true, 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] #[test]
fn test_command_signer_new_token() { fn test_command_signer_new_token() {
let args = vec!["parity", "signer", "new-token"]; let args = vec!["parity", "signer", "new-token"];