Fixing account naming (#1810)

* Fixing account naming

* Using geth format for files. Avoid re-importing existing keys with different names.

* Adding expect for time format
This commit is contained in:
Tomasz Drwięga
2016-08-03 17:58:22 +02:00
committed by Gav Wood
parent 8c88e2a8cc
commit 40a304b177
5 changed files with 84 additions and 45 deletions

View File

@@ -47,21 +47,25 @@ pub fn execute(cmd: AccountCmd) -> Result<String, String> {
}
}
fn keys_dir(path: String) -> Result<DiskDirectory, String> {
DiskDirectory::create(path).map_err(|e| format!("Could not open keys directory: {}", e))
}
fn new(n: NewAccount) -> Result<String, String> {
let password: String = match n.password_file {
Some(file) => try!(password_from_file(file)),
None => try!(password_prompt()),
};
let dir = Box::new(DiskDirectory::create(n.path).unwrap());
let dir = Box::new(try!(keys_dir(n.path)));
let secret_store = Box::new(EthStore::open_with_iterations(dir, n.iterations).unwrap());
let acc_provider = AccountProvider::new(secret_store);
let new_account = acc_provider.new_account(&password).unwrap();
let new_account = try!(acc_provider.new_account(&password).map_err(|e| format!("Could not create new account: {}", e)));
Ok(format!("{:?}", new_account))
}
fn list(path: String) -> Result<String, String> {
let dir = Box::new(DiskDirectory::create(path).unwrap());
let dir = Box::new(try!(keys_dir(path)));
let secret_store = Box::new(EthStore::open(dir).unwrap());
let acc_provider = AccountProvider::new(secret_store);
let accounts = acc_provider.accounts();
@@ -74,7 +78,7 @@ fn list(path: String) -> Result<String, String> {
}
fn import(i: ImportAccounts) -> Result<String, String> {
let to = DiskDirectory::create(i.to).unwrap();
let to = try!(keys_dir(i.to));
let mut imported = 0;
for path in &i.from {
let from = DiskDirectory::at(path);

View File

@@ -298,7 +298,7 @@ fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result<A
};
let from = GethDirectory::open(t);
let to = DiskDirectory::create(dirs.keys.clone()).unwrap();
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 => {}
@@ -306,8 +306,10 @@ fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result<A
}
}
let dir = Box::new(DiskDirectory::create(dirs.keys.clone()).unwrap());
let account_service = AccountProvider::new(Box::new(EthStore::open_with_iterations(dir, cfg.iterations).unwrap()));
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)))
));
for a in cfg.unlocked_accounts {
if passwords.iter().find(|p| account_service.unlock_account_permanently(a, (*p).clone()).is_ok()).is_none() {