From 92d8edc1a6b06886cb0ed8eee274de158cfa772f Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 16 Feb 2017 23:04:39 +0300 Subject: [PATCH] unique_repr, no default impl --- ethstore/src/dir/disk.rs | 2 +- ethstore/src/dir/geth.rs | 4 ++++ ethstore/src/dir/memory.rs | 7 +++++++ ethstore/src/dir/mod.rs | 4 ++-- ethstore/src/dir/parity.rs | 4 ++++ ethstore/src/ethstore.rs | 2 +- ethstore/tests/util/transient_dir.rs | 4 ++++ 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ethstore/src/dir/disk.rs b/ethstore/src/dir/disk.rs index f8d8345e7..afca0955d 100755 --- a/ethstore/src/dir/disk.rs +++ b/ethstore/src/dir/disk.rs @@ -225,7 +225,7 @@ impl KeyDirectory for DiskDirectory where T: KeyFileManager { Some(self) } - fn hash(&self) -> Result { + fn unique_repr(&self) -> Result { self.files_hash() } } diff --git a/ethstore/src/dir/geth.rs b/ethstore/src/dir/geth.rs index 1058e433f..0dfa2e6b2 100755 --- a/ethstore/src/dir/geth.rs +++ b/ethstore/src/dir/geth.rs @@ -95,4 +95,8 @@ impl KeyDirectory for GethDirectory { fn remove(&self, account: &SafeAccount) -> Result<(), Error> { self.dir.remove(account) } + + fn unique_repr(&self) -> Result { + self.dir.unique_repr() + } } diff --git a/ethstore/src/dir/memory.rs b/ethstore/src/dir/memory.rs index 941795efc..87d12794e 100644 --- a/ethstore/src/dir/memory.rs +++ b/ethstore/src/dir/memory.rs @@ -63,5 +63,12 @@ impl KeyDirectory for MemoryDirectory { } Ok(()) } + + fn unique_repr(&self) -> Result { + let mut val = 0u64; + let accounts = self.accounts.read(); + for acc in accounts.keys() { val = val ^ ::util::FixedHash::low_u64(acc) } + Ok(val) + } } diff --git a/ethstore/src/dir/mod.rs b/ethstore/src/dir/mod.rs index 5fbf5fb8b..83e978707 100755 --- a/ethstore/src/dir/mod.rs +++ b/ethstore/src/dir/mod.rs @@ -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 { Ok(0u64) } + /// Unique representation of directory account collection + fn unique_repr(&self) -> Result; } /// Vaults provider diff --git a/ethstore/src/dir/parity.rs b/ethstore/src/dir/parity.rs index 198e50165..df03260d3 100755 --- a/ethstore/src/dir/parity.rs +++ b/ethstore/src/dir/parity.rs @@ -74,4 +74,8 @@ impl KeyDirectory for ParityDirectory { fn remove(&self, account: &SafeAccount) -> Result<(), Error> { self.dir.remove(account) } + + fn unique_repr(&self) -> Result { + self.dir.unique_repr() + } } diff --git a/ethstore/src/ethstore.rs b/ethstore/src/ethstore.rs index 401630ba8..3cdf0e643 100755 --- a/ethstore/src/ethstore.rs +++ b/ethstore/src/ethstore.rs @@ -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(()) } diff --git a/ethstore/tests/util/transient_dir.rs b/ethstore/tests/util/transient_dir.rs index 150ae8108..45e2aab09 100755 --- a/ethstore/tests/util/transient_dir.rs +++ b/ethstore/tests/util/transient_dir.rs @@ -74,4 +74,8 @@ impl KeyDirectory for TransientDir { fn remove(&self, account: &SafeAccount) -> Result<(), Error> { self.dir.remove(account) } + + fn unique_repr(&self) -> Result { + self.dir.unique_repr() + } }