This commit is contained in:
svyatonik 2016-10-04 11:44:47 +03:00
parent 48bb890045
commit cb0e0abc4a
4 changed files with 34 additions and 25 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use ethcore::ethstore::{EthStore, import_accounts}; use ethcore::ethstore::{EthStore, SecretStore, import_accounts, read_geth_accounts};
use ethcore::ethstore::dir::DiskDirectory; use ethcore::ethstore::dir::DiskDirectory;
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use helpers::{password_prompt, password_from_file}; use helpers::{password_prompt, password_from_file};
@ -24,6 +24,7 @@ pub enum AccountCmd {
New(NewAccount), New(NewAccount),
List(String), List(String),
Import(ImportAccounts), Import(ImportAccounts),
ImportFromGeth(ImportFromGethAccounts)
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -39,11 +40,18 @@ pub struct ImportAccounts {
pub to: String, pub to: String,
} }
#[derive(Debug, PartialEq)]
pub struct ImportFromGethAccounts {
pub testnet: bool,
pub to: String,
}
pub fn execute(cmd: AccountCmd) -> Result<String, String> { pub fn execute(cmd: AccountCmd) -> Result<String, String> {
match cmd { match cmd {
AccountCmd::New(new_cmd) => new(new_cmd), AccountCmd::New(new_cmd) => new(new_cmd),
AccountCmd::List(path) => list(path), AccountCmd::List(path) => list(path),
AccountCmd::Import(import_cmd) => import(import_cmd), 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<String, String> {
} }
Ok(format!("{}", imported)) Ok(format!("{}", imported))
} }
fn import_geth(i: ImportFromGethAccounts) -> Result<String, String> {
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))
}
}

View File

@ -39,7 +39,7 @@ use signer::Configuration as SignerConfiguration;
use run::RunCmd; use run::RunCmd;
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat}; use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet; use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ImportAccounts}; use account::{AccountCmd, NewAccount, ImportAccounts, ImportFromGethAccounts};
use snapshot::{self, SnapshotCommand}; use snapshot::{self, SnapshotCommand};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -120,6 +120,14 @@ impl Configuration {
unreachable!(); unreachable!();
}; };
Cmd::Account(account_cmd) 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 { } else if self.args.cmd_wallet {
let presale_cmd = ImportWallet { let presale_cmd = ImportWallet {
iterations: self.args.flag_keys_iterations, iterations: self.args.flag_keys_iterations,
@ -319,7 +327,6 @@ impl Configuration {
fn accounts_config(&self) -> Result<AccountsConfig, String> { fn accounts_config(&self) -> Result<AccountsConfig, String> {
let cfg = AccountsConfig { let cfg = AccountsConfig {
iterations: self.args.flag_keys_iterations, iterations: self.args.flag_keys_iterations,
import_keys: self.args.flag_import_geth_keys,
testnet: self.args.flag_testnet, testnet: self.args.flag_testnet,
password_files: self.args.flag_password.clone(), password_files: self.args.flag_password.clone(),
unlocked_accounts: try!(to_addresses(&self.args.flag_unlock)), unlocked_accounts: try!(to_addresses(&self.args.flag_unlock)),

View File

@ -142,7 +142,6 @@ impl str::FromStr for ResealPolicy {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct AccountsConfig { pub struct AccountsConfig {
pub iterations: u32, pub iterations: u32,
pub import_keys: bool,
pub testnet: bool, pub testnet: bool,
pub password_files: Vec<String>, pub password_files: Vec<String>,
pub unlocked_accounts: Vec<Address>, pub unlocked_accounts: Vec<Address>,
@ -152,7 +151,6 @@ impl Default for AccountsConfig {
fn default() -> Self { fn default() -> Self {
AccountsConfig { AccountsConfig {
iterations: 10240, iterations: 10240,
import_keys: false,
testnet: false, testnet: false,
password_files: Vec::new(), password_files: Vec::new(),
unlocked_accounts: Vec::new(), unlocked_accounts: Vec::new(),

View File

@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::{Arc, Mutex, Condvar}; use std::sync::{Arc, Mutex, Condvar};
use std::io::ErrorKind;
use ctrlc::CtrlC; use ctrlc::CtrlC;
use fdlimit::raise_fd_limit; use fdlimit::raise_fd_limit;
use ethcore_logger::{Config as LogConfig, setup_log}; 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<AccountProvider, String> { fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result<AccountProvider, String> {
use ethcore::ethstore::{import_accounts, EthStore}; use ethcore::ethstore::EthStore;
use ethcore::ethstore::dir::{GethDirectory, DirectoryType, DiskDirectory}; use ethcore::ethstore::dir::DiskDirectory;
use ethcore::ethstore::Error;
let passwords = try!(passwords_from_files(cfg.password_files)); 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 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( 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))) try!(EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e)))