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

Replace deprecated hashdb trait names #1394

Merged
merged 3 commits into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ethcore/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ impl Account {
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == Some(SHA3_EMPTY))
}

/// Provide a database to lookup `code_hash`. Should not be called if it is a contract without code.
/// Provide a database to get `code_hash`. Should not be called if it is a contract without code.
pub fn cache_code(&mut self, db: &AccountDB) -> bool {
// TODO: fill out self.code_cache;
trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
self.is_cached() ||
match self.code_hash {
Some(ref h) => match db.lookup(h) {
Some(ref h) => match db.get(h) {
Some(x) => { self.code_cache = x.to_vec(); true },
_ => {
warn!("Failed reverse lookup of {}", h);
warn!("Failed reverse get of {}", h);
false
},
},
Expand Down
22 changes: 11 additions & 11 deletions ethcore/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ impl<'db> HashDB for AccountDB<'db>{
unimplemented!()
}

fn lookup(&self, key: &H256) -> Option<&[u8]> {
fn get(&self, key: &H256) -> Option<&[u8]> {
if key == &SHA3_NULL_RLP {
return Some(&NULL_RLP_STATIC);
}
self.db.lookup(&combine_key(&self.address, key))
self.db.get(&combine_key(&self.address, key))
}

fn exists(&self, key: &H256) -> bool {
fn contains(&self, key: &H256) -> bool {
if key == &SHA3_NULL_RLP {
return true;
}
self.db.exists(&combine_key(&self.address, key))
self.db.contains(&combine_key(&self.address, key))
}

fn insert(&mut self, _value: &[u8]) -> H256 {
Expand All @@ -52,7 +52,7 @@ impl<'db> HashDB for AccountDB<'db>{
unimplemented!()
}

fn kill(&mut self, _key: &H256) {
fn remove(&mut self, _key: &H256) {
unimplemented!()
}
}
Expand Down Expand Up @@ -82,18 +82,18 @@ impl<'db> HashDB for AccountDBMut<'db>{
unimplemented!()
}

fn lookup(&self, key: &H256) -> Option<&[u8]> {
fn get(&self, key: &H256) -> Option<&[u8]> {
if key == &SHA3_NULL_RLP {
return Some(&NULL_RLP_STATIC);
}
self.db.lookup(&combine_key(&self.address, key))
self.db.get(&combine_key(&self.address, key))
}

fn exists(&self, key: &H256) -> bool {
fn contains(&self, key: &H256) -> bool {
if key == &SHA3_NULL_RLP {
return true;
}
self.db.exists(&combine_key(&self.address, key))
self.db.contains(&combine_key(&self.address, key))
}

fn insert(&mut self, value: &[u8]) -> H256 {
Expand All @@ -114,12 +114,12 @@ impl<'db> HashDB for AccountDBMut<'db>{
self.db.emplace(key, value.to_vec())
}

fn kill(&mut self, key: &H256) {
fn remove(&mut self, key: &H256) {
if key == &SHA3_NULL_RLP {
return;
}
let key = combine_key(&self.address, key);
self.db.kill(&key)
self.db.remove(&key)
}
}

Expand Down
24 changes: 11 additions & 13 deletions util/src/hashdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ use bytes::*;
use std::collections::HashMap;

/// Trait modelling datastore keyed by a 32-byte Keccak hash.
pub trait HashDB : AsHashDB {
pub trait HashDB: AsHashDB {
/// Get the keys in the database together with number of underlying references.
fn keys(&self) -> HashMap<H256, i32>;

/// Deprecated. use `get`.
fn lookup(&self, key: &H256) -> Option<&[u8]>; // TODO: rename to get.
/// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known.
///
Expand All @@ -41,10 +39,8 @@ pub trait HashDB : AsHashDB {
/// assert_eq!(m.get(&hash).unwrap(), hello_bytes);
/// }
/// ```
fn get(&self, key: &H256) -> Option<&[u8]> { self.lookup(key) }
fn get(&self, key: &H256) -> Option<&[u8]>;

/// Deprecated. Use `contains`.
fn exists(&self, key: &H256) -> bool; // TODO: rename to contains.
/// Check for the existance of a hash-key.
///
/// # Examples
Expand All @@ -63,10 +59,10 @@ pub trait HashDB : AsHashDB {
/// assert!(!m.contains(&key));
/// }
/// ```
fn contains(&self, key: &H256) -> bool { self.exists(key) }
fn contains(&self, key: &H256) -> bool;

/// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions
/// are counted and the equivalent number of `kill()`s must be performed before the data
/// are counted and the equivalent number of `remove()`s must be performed before the data
/// is considered dead.
///
/// # Examples
Expand All @@ -86,8 +82,6 @@ pub trait HashDB : AsHashDB {
/// Like `insert()` , except you provide the key and the data is all moved.
fn emplace(&mut self, key: H256, value: Bytes);

/// Deprecated - use `remove`.
fn kill(&mut self, key: &H256); // TODO: rename to remove.
/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may
/// happen without the data being eventually being inserted into the DB.
///
Expand All @@ -109,7 +103,7 @@ pub trait HashDB : AsHashDB {
/// assert_eq!(m.get(key).unwrap(), d);
/// }
/// ```
fn remove(&mut self, key: &H256) { self.kill(key) }
fn remove(&mut self, key: &H256);
}

/// Upcast trait.
Expand All @@ -121,6 +115,10 @@ pub trait AsHashDB {
}

impl<T: HashDB> AsHashDB for T {
fn as_hashdb(&self) -> &HashDB { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB { self }
fn as_hashdb(&self) -> &HashDB {
self
}
fn as_hashdb_mut(&mut self) -> &mut HashDB {
self
}
}
68 changes: 34 additions & 34 deletions util/src/journaldb/archivedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl HashDB for ArchiveDB {
ret
}

fn lookup(&self, key: &H256) -> Option<&[u8]> {
fn get(&self, key: &H256) -> Option<&[u8]> {
let k = self.overlay.raw(key);
match k {
Some(&(ref d, rc)) if rc > 0 => Some(d),
Expand All @@ -113,8 +113,8 @@ impl HashDB for ArchiveDB {
}
}

fn exists(&self, key: &H256) -> bool {
self.lookup(key).is_some()
fn contains(&self, key: &H256) -> bool {
self.get(key).is_some()
}

fn insert(&mut self, value: &[u8]) -> H256 {
Expand All @@ -123,8 +123,8 @@ impl HashDB for ArchiveDB {
fn emplace(&mut self, key: H256, value: Bytes) {
self.overlay.emplace(key, value);
}
fn kill(&mut self, key: &H256) {
self.overlay.kill(key);
fn remove(&mut self, key: &H256) {
self.overlay.remove(key);
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ mod tests {
jdb.commit(5, &b"1004a".sha3(), Some((3, b"1002a".sha3()))).unwrap();
jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap();

assert!(jdb.exists(&x));
assert!(jdb.contains(&x));
}

#[test]
Expand All @@ -216,14 +216,14 @@ mod tests {
let mut jdb = ArchiveDB::new_temp();
let h = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&h));
assert!(jdb.contains(&h));
jdb.remove(&h);
jdb.commit(1, &b"1".sha3(), None).unwrap();
assert!(jdb.exists(&h));
assert!(jdb.contains(&h));
jdb.commit(2, &b"2".sha3(), None).unwrap();
assert!(jdb.exists(&h));
assert!(jdb.contains(&h));
jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&h));
assert!(jdb.contains(&h));
jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap();
}

Expand All @@ -235,26 +235,26 @@ mod tests {
let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.exists(&bar));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&bar));

jdb.remove(&foo);
jdb.remove(&bar);
let baz = jdb.insert(b"baz");
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.exists(&bar));
assert!(jdb.exists(&baz));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&bar));
assert!(jdb.contains(&baz));

let foo = jdb.insert(b"foo");
jdb.remove(&baz);
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.exists(&baz));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&baz));

jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));

jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
}
Expand All @@ -267,8 +267,8 @@ mod tests {
let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.exists(&bar));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&bar));

jdb.remove(&foo);
let baz = jdb.insert(b"baz");
Expand All @@ -277,12 +277,12 @@ mod tests {
jdb.remove(&bar);
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();

assert!(jdb.exists(&foo));
assert!(jdb.exists(&bar));
assert!(jdb.exists(&baz));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&bar));
assert!(jdb.contains(&baz));

jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
}

#[test]
Expand All @@ -292,16 +292,16 @@ mod tests {

let foo = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));

jdb.remove(&foo);
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
jdb.insert(b"foo");
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
}

#[test]
Expand All @@ -315,10 +315,10 @@ mod tests {

jdb.insert(b"foo");
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));

jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
}

#[test]
Expand All @@ -344,8 +344,8 @@ mod tests {

{
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
assert!(jdb.exists(&foo));
assert!(jdb.exists(&bar));
assert!(jdb.contains(&foo));
assert!(jdb.contains(&bar));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ mod tests {
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap();
Expand Down Expand Up @@ -402,7 +402,7 @@ mod tests {
{
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.exists(&foo));
assert!(jdb.contains(&foo));
}
}

Expand Down
Loading