Merge pull request #683 from ethcore/jdb-state-queries

state query for archive jdb
This commit is contained in:
Arkadiy Paronyan 2016-03-12 16:19:00 +01:00
commit 8ce073ed9a
2 changed files with 28 additions and 1 deletions

View File

@ -159,6 +159,10 @@ impl JournalDB for ArchiveDB {
try!(self.backing.write(batch)); try!(self.backing.write(batch));
Ok((inserts + deletes) as u32) Ok((inserts + deletes) as u32)
} }
fn state(&self, id: &H256) -> Option<Bytes> {
self.backing.get_by_prefix(&id.bytes()[0..12]).and_then(|b| Some(b.to_vec()))
}
} }
#[cfg(test)] #[cfg(test)]
@ -301,7 +305,6 @@ mod tests {
assert!(jdb.exists(&foo)); assert!(jdb.exists(&foo));
} }
#[test] #[test]
fn reopen() { fn reopen() {
let mut dir = ::std::env::temp_dir(); let mut dir = ::std::env::temp_dir();
@ -360,6 +363,7 @@ mod tests {
jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap();
} }
} }
#[test] #[test]
fn reopen_fork() { fn reopen_fork() {
let mut dir = ::std::env::temp_dir(); let mut dir = ::std::env::temp_dir();
@ -385,4 +389,22 @@ mod tests {
assert!(jdb.exists(&foo)); assert!(jdb.exists(&foo));
} }
} }
#[test]
fn returns_state() {
let temp = ::devtools::RandomTempPath::new();
let key = {
let mut jdb = ArchiveDB::new(temp.as_str());
let key = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap();
key
};
{
let jdb = ArchiveDB::new(temp.as_str());
let state = jdb.state(&key);
assert!(state.is_some());
}
}
} }

View File

@ -34,4 +34,9 @@ pub trait JournalDB : HashDB + Send + Sync {
/// Commit all recent insert operations and canonical historical commits' removals from the /// Commit all recent insert operations and canonical historical commits' removals from the
/// old era to the backing database, reverting any non-canonical historical commit's inserts. /// old era to the backing database, reverting any non-canonical historical commit's inserts.
fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result<u32, UtilError>; fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result<u32, UtilError>;
/// State data query
fn state(&self, _id: &H256) -> Option<Bytes> {
None
}
} }