Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
unique_repr, no default impl
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Feb 16, 2017
1 parent 444065e commit 92d8edc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ethstore/src/dir/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
4 changes: 4 additions & 0 deletions ethstore/src/dir/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
7 changes: 7 additions & 0 deletions ethstore/src/dir/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

4 changes: 2 additions & 2 deletions ethstore/src/dir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ethstore/src/dir/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion ethstore/src/ethstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
4 changes: 4 additions & 0 deletions ethstore/tests/util/transient_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 92d8edc

Please sign in to comment.