unique_repr, no default impl

This commit is contained in:
NikVolf 2017-02-16 23:04:39 +03:00
parent 444065e294
commit 92d8edc1a6
7 changed files with 23 additions and 4 deletions

View File

@ -225,7 +225,7 @@ impl<T> KeyDirectory for DiskDirectory<T> where T: KeyFileManager {
Some(self)
}
fn hash(&self) -> Result<u64, Error> {
fn unique_repr(&self) -> Result<u64, Error> {
self.files_hash()
}
}

View File

@ -95,4 +95,8 @@ impl KeyDirectory for GethDirectory {
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
self.dir.remove(account)
}
fn unique_repr(&self) -> Result<u64, Error> {
self.dir.unique_repr()
}
}

View File

@ -63,5 +63,12 @@ impl KeyDirectory for MemoryDirectory {
}
Ok(())
}
fn unique_repr(&self) -> Result<u64, Error> {
let mut val = 0u64;
let accounts = self.accounts.read();
for acc in accounts.keys() { val = val ^ ::util::FixedHash::low_u64(acc) }
Ok(val)
}
}

View File

@ -62,8 +62,8 @@ pub trait KeyDirectory: Send + Sync {
fn path(&self) -> Option<&PathBuf> { None }
/// Return vault provider, if available
fn as_vault_provider(&self) -> Option<&VaultKeyDirectoryProvider> { None }
/// Returns hash of the directory content, if supported
fn hash(&self) -> Result<u64, Error> { Ok(0u64) }
/// Unique representation of directory account collection
fn unique_repr(&self) -> Result<u64, Error>;
}
/// Vaults provider

View File

@ -74,4 +74,8 @@ impl KeyDirectory for ParityDirectory {
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
self.dir.remove(account)
}
fn unique_repr(&self) -> Result<u64, Error> {
self.dir.unique_repr()
}
}

View File

@ -253,7 +253,7 @@ impl EthMultiStore {
fn reload_if_changed(&self) -> Result<(), Error> {
let mut last_dir_hash = self.dir_hash.lock();
let dir_hash = Some(self.dir.hash()?);
let dir_hash = Some(self.dir.unique_repr()?);
if *last_dir_hash == dir_hash {
return Ok(())
}

View File

@ -74,4 +74,8 @@ impl KeyDirectory for TransientDir {
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
self.dir.remove(account)
}
fn unique_repr(&self) -> Result<u64, Error> {
self.dir.unique_repr()
}
}