diff --git a/parity/account.rs b/parity/account.rs index 26a974090..72a932315 100644 --- a/parity/account.rs +++ b/parity/account.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use ethcore::ethstore::{EthStore, import_accounts}; +use ethcore::ethstore::{EthStore, SecretStore, import_accounts, read_geth_accounts}; use ethcore::ethstore::dir::DiskDirectory; use ethcore::account_provider::AccountProvider; use helpers::{password_prompt, password_from_file}; @@ -24,6 +24,7 @@ pub enum AccountCmd { New(NewAccount), List(String), Import(ImportAccounts), + ImportFromGeth(ImportFromGethAccounts) } #[derive(Debug, PartialEq)] @@ -39,11 +40,18 @@ pub struct ImportAccounts { pub to: String, } +#[derive(Debug, PartialEq)] +pub struct ImportFromGethAccounts { + pub testnet: bool, + pub to: String, +} + pub fn execute(cmd: AccountCmd) -> Result { match cmd { AccountCmd::New(new_cmd) => new(new_cmd), AccountCmd::List(path) => list(path), AccountCmd::Import(import_cmd) => import(import_cmd), + AccountCmd::ImportFromGeth(import_geth_cmd) => import_geth(import_geth_cmd) } } @@ -86,3 +94,17 @@ fn import(i: ImportAccounts) -> Result { } Ok(format!("{}", imported)) } + +fn import_geth(i: ImportFromGethAccounts) -> Result { + use std::io::ErrorKind; + use ethcore::ethstore::Error; + + let dir = Box::new(try!(keys_dir(i.to))); + let secret_store = Box::new(EthStore::open(dir).unwrap()); + let geth_accounts = read_geth_accounts(i.testnet); + match secret_store.import_geth_accounts(geth_accounts, i.testnet) { + Ok(v) => Ok(format!("Successfully imported {} account(s) from geth.", v.len())), + Err(Error::Io(ref io_err)) if io_err.kind() == ErrorKind::NotFound => Err("Failed to find geth keys folder.".into()), + Err(err) => Err(format!("Import geth accounts failed. {}", err)) + } +} diff --git a/parity/configuration.rs b/parity/configuration.rs index 8eb617d2b..811ba6097 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -39,7 +39,7 @@ use signer::Configuration as SignerConfiguration; use run::RunCmd; use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat}; use presale::ImportWallet; -use account::{AccountCmd, NewAccount, ImportAccounts}; +use account::{AccountCmd, NewAccount, ImportAccounts, ImportFromGethAccounts}; use snapshot::{self, SnapshotCommand}; #[derive(Debug, PartialEq)] @@ -120,6 +120,14 @@ impl Configuration { unreachable!(); }; Cmd::Account(account_cmd) + } else if self.args.flag_import_geth_keys { + let account_cmd = AccountCmd::ImportFromGeth( + ImportFromGethAccounts { + to: dirs.keys, + testnet: self.args.flag_testnet + } + ); + Cmd::Account(account_cmd) } else if self.args.cmd_wallet { let presale_cmd = ImportWallet { iterations: self.args.flag_keys_iterations, @@ -319,7 +327,6 @@ impl Configuration { fn accounts_config(&self) -> Result { let cfg = AccountsConfig { iterations: self.args.flag_keys_iterations, - import_keys: self.args.flag_import_geth_keys, testnet: self.args.flag_testnet, password_files: self.args.flag_password.clone(), unlocked_accounts: try!(to_addresses(&self.args.flag_unlock)), diff --git a/parity/params.rs b/parity/params.rs index a1b28406a..faba029b2 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -142,7 +142,6 @@ impl str::FromStr for ResealPolicy { #[derive(Debug, PartialEq)] pub struct AccountsConfig { pub iterations: u32, - pub import_keys: bool, pub testnet: bool, pub password_files: Vec, pub unlocked_accounts: Vec
, @@ -152,7 +151,6 @@ impl Default for AccountsConfig { fn default() -> Self { AccountsConfig { iterations: 10240, - import_keys: false, testnet: false, password_files: Vec::new(), unlocked_accounts: Vec::new(), diff --git a/parity/run.rs b/parity/run.rs index ef84d75a2..528b207c6 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -15,7 +15,6 @@ // along with Parity. If not, see . use std::sync::{Arc, Mutex, Condvar}; -use std::io::ErrorKind; use ctrlc::CtrlC; use fdlimit::raise_fd_limit; use ethcore_logger::{Config as LogConfig, setup_log}; @@ -360,28 +359,11 @@ fn daemonize(_pid_file: String) -> Result<(), String> { } fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result { - use ethcore::ethstore::{import_accounts, EthStore}; - use ethcore::ethstore::dir::{GethDirectory, DirectoryType, DiskDirectory}; - use ethcore::ethstore::Error; + use ethcore::ethstore::EthStore; + use ethcore::ethstore::dir::DiskDirectory; let passwords = try!(passwords_from_files(cfg.password_files)); - if cfg.import_keys { - let t = if cfg.testnet { - DirectoryType::Testnet - } else { - DirectoryType::Main - }; - - let from = GethDirectory::open(t); - let to = try!(DiskDirectory::create(dirs.keys.clone()).map_err(|e| format!("Could not open keys directory: {}", e))); - match import_accounts(&from, &to) { - Ok(_) => {} - Err(Error::Io(ref io_err)) if io_err.kind() == ErrorKind::NotFound => {} - Err(err) => warn!("Import geth accounts failed. {}", err) - } - } - let dir = Box::new(try!(DiskDirectory::create(dirs.keys.clone()).map_err(|e| format!("Could not open keys directory: {}", e)))); let account_service = AccountProvider::new(Box::new( try!(EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e)))