extended keys with accont meta

This commit is contained in:
Nikolay Volf
2016-02-21 23:23:46 +03:00
parent 6448d073a7
commit 5b05cbb128
9 changed files with 114 additions and 7 deletions

View File

@@ -333,7 +333,9 @@ pub struct KeyFileContent {
/// Holds cypher and decrypt function settings.
pub crypto: KeyFileCrypto,
/// The identifier.
pub id: Uuid
pub id: Uuid,
/// Account (if present)
pub account: Option<Address>,
}
#[derive(Debug)]
@@ -374,7 +376,8 @@ impl KeyFileContent {
KeyFileContent {
id: new_uuid(),
version: KeyFileVersion::V3(3),
crypto: crypto
crypto: crypto,
account: None
}
}
@@ -407,6 +410,9 @@ impl KeyFileContent {
Ok(id) => id
};
let account = as_object.get("account").and_then(|json| json.as_string()).and_then(
|account_text| match Address::from_str(account_text) { Ok(account) => Some(account), Err(_) => None });
let crypto = match as_object.get("crypto") {
None => { return Err(KeyFileParseError::NoCryptoSection); }
Some(crypto_json) => match KeyFileCrypto::from_json(crypto_json) {
@@ -418,7 +424,8 @@ impl KeyFileContent {
Ok(KeyFileContent {
version: version,
id: id.clone(),
crypto: crypto
crypto: crypto,
account: account
})
}

View File

@@ -63,12 +63,22 @@ impl SecretStore {
/// new instance of Secret Store
pub fn new() -> SecretStore {
let mut path = ::std::env::home_dir().expect("Failed to get home dir");
path.push(".keys");
path.push("keystore");
SecretStore {
directory: KeyDirectory::new(&path)
}
}
pub fn accounts(&self) -> Result<Vec<(Address, H128)>, ::std::io::Error> {
let accounts = try!(self.directory.list()).iter().map(|key_id| self.directory.get(key_id))
.filter(|key| key.is_some())
.map(|key| { let some_key = key.unwrap(); (some_key.account, some_key.id) })
.filter(|&(ref account, _)| account.is_some())
.map(|(account, id)| (account.unwrap(), id))
.collect::<Vec<(Address, H128)>>();
Ok(accounts)
}
#[cfg(test)]
fn new_test(path: &::devtools::RandomTempPath) -> SecretStore {
SecretStore {