Make *ID names consistent with std Rust (Id)

This commit is contained in:
Gav Wood
2016-12-09 23:01:43 +01:00
parent 2226324495
commit 5f1fcf95e0
46 changed files with 389 additions and 389 deletions

View File

@@ -20,7 +20,7 @@ use std::collections::HashMap;
use time;
use ethkey::Address;
use {json, SafeAccount, Error};
use json::UUID;
use json::Uuid;
use super::KeyDirectory;
const IGNORED_FILES: &'static [&'static str] = &["thumbs.db", "address_book.json"];
@@ -113,7 +113,7 @@ impl KeyDirectory for DiskDirectory {
// build file path
let filename = account.filename.as_ref().cloned().unwrap_or_else(|| {
let timestamp = time::strftime("%Y-%m-%dT%H-%M-%S", &time::now_utc()).expect("Time-format string is valid.");
format!("UTC--{}Z--{}", timestamp, UUID::from(account.id))
format!("UTC--{}Z--{}", timestamp, Uuid::from(account.id))
});
// update account filename

View File

@@ -24,7 +24,7 @@ use dir::KeyDirectory;
use account::SafeAccount;
use {Error, SecretStore};
use json;
use json::UUID;
use json::Uuid;
use parking_lot::RwLock;
use presale::PresaleWallet;
use import;
@@ -154,7 +154,7 @@ impl SecretStore for EthStore {
account.public(password)
}
fn uuid(&self, address: &Address) -> Result<UUID, Error> {
fn uuid(&self, address: &Address) -> Result<Uuid, Error> {
let account = try!(self.get(address));
Ok(account.id.into())
}

View File

@@ -21,7 +21,7 @@ pub enum Error {
UnsupportedCipher,
InvalidCipherParams,
UnsupportedKdf,
InvalidUUID,
InvalidUuid,
UnsupportedVersion,
InvalidCiphertext,
InvalidH256,
@@ -31,7 +31,7 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
Error::InvalidUUID => write!(f, "Invalid UUID"),
Error::InvalidUuid => write!(f, "Invalid Uuid"),
Error::UnsupportedVersion => write!(f, "Unsupported version"),
Error::UnsupportedKdf => write!(f, "Unsupported kdf"),
Error::InvalidCiphertext => write!(f, "Invalid ciphertext"),

View File

@@ -23,15 +23,15 @@ use super::Error;
/// Universaly unique identifier.
#[derive(Debug, PartialEq)]
pub struct UUID([u8; 16]);
pub struct Uuid([u8; 16]);
impl From<[u8; 16]> for UUID {
impl From<[u8; 16]> for Uuid {
fn from(uuid: [u8; 16]) -> Self {
UUID(uuid)
Uuid(uuid)
}
}
impl<'a> Into<String> for &'a UUID {
impl<'a> Into<String> for &'a Uuid {
fn into(self) -> String {
let d1 = &self.0[0..4];
let d2 = &self.0[4..6];
@@ -42,44 +42,44 @@ impl<'a> Into<String> for &'a UUID {
}
}
impl Into<String> for UUID {
impl Into<String> for Uuid {
fn into(self) -> String {
Into::into(&self)
}
}
impl Into<[u8; 16]> for UUID {
impl Into<[u8; 16]> for Uuid {
fn into(self) -> [u8; 16] {
self.0
}
}
impl fmt::Display for UUID {
impl fmt::Display for Uuid {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let s: String = (self as &UUID).into();
let s: String = (self as &Uuid).into();
write!(f, "{}", s)
}
}
fn copy_into(from: &str, into: &mut [u8]) -> Result<(), Error> {
let from = try!(from.from_hex().map_err(|_| Error::InvalidUUID));
let from = try!(from.from_hex().map_err(|_| Error::InvalidUuid));
if from.len() != into.len() {
return Err(Error::InvalidUUID);
return Err(Error::InvalidUuid);
}
into.copy_from_slice(&from);
Ok(())
}
impl str::FromStr for UUID {
impl str::FromStr for Uuid {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = s.split("-").collect();
if parts.len() != 5 {
return Err(Error::InvalidUUID);
return Err(Error::InvalidUuid);
}
let mut uuid = [0u8; 16];
@@ -90,17 +90,17 @@ impl str::FromStr for UUID {
try!(copy_into(parts[3], &mut uuid[8..10]));
try!(copy_into(parts[4], &mut uuid[10..16]));
Ok(UUID(uuid))
Ok(Uuid(uuid))
}
}
impl From<&'static str> for UUID {
impl From<&'static str> for Uuid {
fn from(s: &'static str) -> Self {
s.parse().expect(&format!("invalid string literal for {}: '{}'", stringify!(Self), s))
}
}
impl Serialize for UUID {
impl Serialize for Uuid {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer {
let s: String = self.into();
@@ -108,17 +108,17 @@ impl Serialize for UUID {
}
}
impl Deserialize for UUID {
impl Deserialize for Uuid {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: Deserializer {
deserializer.deserialize(UUIDVisitor)
deserializer.deserialize(UuidVisitor)
}
}
struct UUIDVisitor;
struct UuidVisitor;
impl Visitor for UUIDVisitor {
type Value = UUID;
impl Visitor for UuidVisitor {
type Value = Uuid;
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: SerdeError {
value.parse().map_err(SerdeError::custom)
@@ -131,18 +131,18 @@ impl Visitor for UUIDVisitor {
#[cfg(test)]
mod tests {
use super::UUID;
use super::Uuid;
#[test]
fn uuid_from_str() {
let uuid: UUID = "3198bc9c-6672-5ab3-d995-4942343ae5b6".into();
assert_eq!(uuid, UUID::from([0x31, 0x98, 0xbc, 0x9c, 0x66, 0x72, 0x5a, 0xb3, 0xd9, 0x95, 0x49, 0x42, 0x34, 0x3a, 0xe5, 0xb6]));
let uuid: Uuid = "3198bc9c-6672-5ab3-d995-4942343ae5b6".into();
assert_eq!(uuid, Uuid::from([0x31, 0x98, 0xbc, 0x9c, 0x66, 0x72, 0x5a, 0xb3, 0xd9, 0x95, 0x49, 0x42, 0x34, 0x3a, 0xe5, 0xb6]));
}
#[test]
fn uuid_from_and_to_str() {
let from = "3198bc9c-6672-5ab3-d995-4942343ae5b6";
let uuid: UUID = from.into();
let uuid: Uuid = from.into();
let to: String = uuid.into();
assert_eq!(from, &to);
}

View File

@@ -18,11 +18,11 @@ use std::io::{Read, Write};
use serde::{Deserialize, Deserializer, Error};
use serde::de::{Visitor, MapVisitor};
use serde_json;
use super::{UUID, Version, Crypto, H160};
use super::{Uuid, Version, Crypto, H160};
#[derive(Debug, PartialEq, Serialize)]
pub struct KeyFile {
pub id: UUID,
pub id: Uuid,
pub version: Version,
pub crypto: Crypto,
pub address: H160,
@@ -31,7 +31,7 @@ pub struct KeyFile {
}
enum KeyFileField {
ID,
Id,
Version,
Crypto,
Address,
@@ -56,7 +56,7 @@ impl Visitor for KeyFileFieldVisitor {
where E: Error
{
match value {
"id" => Ok(KeyFileField::ID),
"id" => Ok(KeyFileField::Id),
"version" => Ok(KeyFileField::Version),
"crypto" => Ok(KeyFileField::Crypto),
"Crypto" => Ok(KeyFileField::Crypto),
@@ -94,7 +94,7 @@ impl Visitor for KeyFileVisitor {
loop {
match try!(visitor.visit_key()) {
Some(KeyFileField::ID) => { id = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Id) => { id = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Version) => { version = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Crypto) => { crypto = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Address) => { address = Some(try!(visitor.visit_value())); }
@@ -153,7 +153,7 @@ impl KeyFile {
mod tests {
use std::str::FromStr;
use serde_json;
use json::{KeyFile, UUID, Version, Crypto, Cipher, Aes128Ctr, Kdf, Scrypt};
use json::{KeyFile, Uuid, Version, Crypto, Cipher, Aes128Ctr, Kdf, Scrypt};
#[test]
fn basic_keyfile() {
@@ -183,7 +183,7 @@ mod tests {
}"#;
let expected = KeyFile {
id: UUID::from_str("8777d9f6-7860-4b9b-88b7-0b57ee6b3a73").unwrap(),
id: Uuid::from_str("8777d9f6-7860-4b9b-88b7-0b57ee6b3a73").unwrap(),
version: Version::V3,
address: "6edddfc6349aff20bc6467ccf276c5b52487f7a8".into(),
crypto: Crypto {

View File

@@ -14,7 +14,7 @@ pub use self::cipher::{Cipher, CipherSer, CipherSerParams, Aes128Ctr};
pub use self::crypto::{Crypto, CipherText};
pub use self::error::Error;
pub use self::hash::{H128, H160, H256};
pub use self::id::UUID;
pub use self::id::Uuid;
pub use self::kdf::{Kdf, KdfSer, Prf, Pbkdf2, Scrypt, KdfSerParams};
pub use self::key_file::KeyFile;
pub use self::presale::{PresaleWallet, Encseed};

View File

@@ -16,7 +16,7 @@
use ethkey::{Address, Message, Signature, Secret, Public};
use Error;
use json::UUID;
use json::Uuid;
pub trait SecretStore: Send + Sync {
fn insert_account(&self, secret: Secret, password: &str) -> Result<Address, Error>;
@@ -30,7 +30,7 @@ pub trait SecretStore: Send + Sync {
fn public(&self, account: &Address, password: &str) -> Result<Public, Error>;
fn accounts(&self) -> Result<Vec<Address>, Error>;
fn uuid(&self, account: &Address) -> Result<UUID, Error>;
fn uuid(&self, account: &Address) -> Result<Uuid, Error>;
fn name(&self, account: &Address) -> Result<String, Error>;
fn meta(&self, account: &Address) -> Result<String, Error>;