extended keys with accont meta
This commit is contained in:
@@ -235,7 +235,7 @@ macro_rules! impl_hash {
|
||||
}
|
||||
|
||||
impl serde::Serialize for $from {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: serde::Serializer {
|
||||
let mut hex = "0x".to_owned();
|
||||
hex.push_str(self.to_hex().as_ref());
|
||||
@@ -250,7 +250,7 @@ macro_rules! impl_hash {
|
||||
|
||||
impl serde::de::Visitor for HashVisitor {
|
||||
type Value = $from;
|
||||
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
|
||||
// 0x + len
|
||||
if value.len() != 2 + $size * 2 {
|
||||
@@ -719,4 +719,3 @@ mod tests {
|
||||
assert_eq!(r, u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user