diff --git a/ethtools/Cargo.toml b/ethtools/Cargo.toml deleted file mode 100644 index 87e101b4d..000000000 --- a/ethtools/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -description = "Ethcore Ethereum tools" -homepage = "http://ethcore.io" -license = "GPL-3.0" -name = "ethtools" -version = "0.9.99" -authors = ["Ethcore "] - -[dependencies] -ethcore-util = { path = "../util" } -rustc-serialize = "0.3" -ethcore-devtools = { path = "../devtools" } -log = "0.3" diff --git a/ethtools/README.md b/ethtools/README.md deleted file mode 100644 index f3e852ff5..000000000 --- a/ethtools/README.md +++ /dev/null @@ -1 +0,0 @@ -# ethtools diff --git a/ethtools/src/lib.rs b/ethtools/src/lib.rs deleted file mode 100644 index 4cf365f5f..000000000 --- a/ethtools/src/lib.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -//! Ethereum Tools Library - -extern crate ethcore_util as util; -extern crate rustc_serialize; -extern crate ethcore_devtools as devtools; -#[macro_use] extern crate log; - -pub mod geth_keys; diff --git a/ethtools/res/geth_keystore/UTC--2016-02-17T09-20-45.721400158Z--3f49624084b67849c7b4e805c5988c21a430f9d9 b/util/res/geth_keystore/UTC--2016-02-17T09-20-45.721400158Z--3f49624084b67849c7b4e805c5988c21a430f9d9 similarity index 100% rename from ethtools/res/geth_keystore/UTC--2016-02-17T09-20-45.721400158Z--3f49624084b67849c7b4e805c5988c21a430f9d9 rename to util/res/geth_keystore/UTC--2016-02-17T09-20-45.721400158Z--3f49624084b67849c7b4e805c5988c21a430f9d9 diff --git a/ethtools/res/geth_keystore/UTC--2016-02-20T09-33-03.984382741Z--5ba4dcf897e97c2bdf8315b9ef26c13c085988cf b/util/res/geth_keystore/UTC--2016-02-20T09-33-03.984382741Z--5ba4dcf897e97c2bdf8315b9ef26c13c085988cf similarity index 100% rename from ethtools/res/geth_keystore/UTC--2016-02-20T09-33-03.984382741Z--5ba4dcf897e97c2bdf8315b9ef26c13c085988cf rename to util/res/geth_keystore/UTC--2016-02-20T09-33-03.984382741Z--5ba4dcf897e97c2bdf8315b9ef26c13c085988cf diff --git a/util/src/keys/directory.rs b/util/src/keys/directory.rs index 233b8b974..7fe6fb1ee 100644 --- a/util/src/keys/directory.rs +++ b/util/src/keys/directory.rs @@ -618,6 +618,8 @@ impl KeyDirectory { Err(_) => Err(KeyFileLoadError::ParseError(KeyFileParseError::InvalidJson)) } } + + } diff --git a/ethtools/src/geth_keys.rs b/util/src/keys/geth_import.rs similarity index 91% rename from ethtools/src/geth_keys.rs rename to util/src/keys/geth_import.rs index 1a6fb75d4..61df88589 100644 --- a/ethtools/src/geth_keys.rs +++ b/util/src/keys/geth_import.rs @@ -16,16 +16,9 @@ //! Geth keys import/export tool -use util::hash::*; -use util::keys::store::SecretStore; -use util::keys::directory::KeyFileContent; -use std::path::{Path, PathBuf}; -use std::result::*; -use std::fs; -use std::str::FromStr; -use std::io; -use std::io::Read; -use rustc_serialize::json::Json; +use common::*; +use keys::store::SecretStore; +use keys::directory::KeyFileContent; /// Enumerates all geth keys in the directory and returns collection of tuples `(accountId, filename)` pub fn enumerate_geth_keys(path: &Path) -> Result, io::Error> { @@ -86,6 +79,7 @@ pub fn import_geth_key(secret_store: &mut SecretStore, geth_keyfile_path: &Path) /// Imports all geth keys in the directory pub fn import_geth_keys(secret_store: &mut SecretStore, geth_keyfiles_directory: &Path) -> Result<(), ImportError> { + use std::path::PathBuf; let geth_files = try!(enumerate_geth_keys(geth_keyfiles_directory)); for &(ref address, ref file_path) in geth_files.iter() { let mut path = PathBuf::new(); @@ -101,10 +95,9 @@ pub fn import_geth_keys(secret_store: &mut SecretStore, geth_keyfiles_directory: #[cfg(test)] mod tests { use super::*; - use std::path::Path; - use util::hash::*; - use util::keys::store::SecretStore; - use std::str::FromStr; + use common::*; + use keys::store::SecretStore; + #[test] fn can_enumerate() { @@ -136,7 +129,7 @@ mod tests { #[test] fn imports_as_scrypt_keys() { - use util::keys::directory::{KeyDirectory, KeyFileKdf}; + use keys::directory::{KeyDirectory, KeyFileKdf}; let temp = ::devtools::RandomTempPath::create_dir(); { let mut secret_store = SecretStore::new_in(temp.as_path()); @@ -158,8 +151,7 @@ mod tests { #[test] fn can_decrypt_with_imported() { - use util::keys::store::EncryptedHashMap; - use util::bytes::*; + use keys::store::EncryptedHashMap; let temp = ::devtools::RandomTempPath::create_dir(); let mut secret_store = SecretStore::new_in(temp.as_path()); diff --git a/util/src/keys/mod.rs b/util/src/keys/mod.rs index fd52136d7..b9c9dcb08 100644 --- a/util/src/keys/mod.rs +++ b/util/src/keys/mod.rs @@ -18,3 +18,4 @@ pub mod directory; pub mod store; +mod geth_import; diff --git a/util/src/keys/store.rs b/util/src/keys/store.rs index 3c2aef7c3..3b1ca4727 100644 --- a/util/src/keys/store.rs +++ b/util/src/keys/store.rs @@ -75,6 +75,20 @@ impl SecretStore { } } + /// trys to import keys in the known locations + pub fn try_import_existing(&mut self) { + use std::path::PathBuf; + use keys::geth_import; + + let mut import_path = PathBuf::new(); + import_path.push(::std::env::home_dir().expect("Failed to get home dir")); + import_path.push(".ethereum"); + import_path.push("keystore"); + if let Err(e) = geth_import::import_geth_keys(self, &import_path) { + warn!(target: "sstore", "Error retrieving geth keys: {:?}", e) + } + } + /// Lists all accounts and corresponding key ids pub fn accounts(&self) -> Result, ::std::io::Error> { let accounts = try!(self.directory.list()).iter().map(|key_id| self.directory.get(key_id))