diff --git a/lighthouse/db/disk_db.rs b/lighthouse/db/disk_db.rs index e4ebdedec..d0f6eb970 100644 --- a/lighthouse/db/disk_db.rs +++ b/lighthouse/db/disk_db.rs @@ -107,6 +107,21 @@ impl ClientDB for DiskDB { Some(handle) => self.db.put_cf(handle, key, val).map_err(|e| e.into()) } } + + /// Return true if some key exists in some column. + fn exists(&self, col: &str, key: &[u8]) + -> Result + { + /* + * I'm not sure if this is the correct way to read if some + * block exists. Naievely I would expect this to unncessarily + * copy some data, but I could be wrong. + */ + match self.db.cf_handle(col) { + None => Err(DBError{ message: "Unknown column".to_string() }), + Some(handle) => Ok(self.db.get_cf(handle, key)?.is_some()) + } + } } diff --git a/lighthouse/db/traits.rs b/lighthouse/db/traits.rs index 97759d3b7..35feda243 100644 --- a/lighthouse/db/traits.rs +++ b/lighthouse/db/traits.rs @@ -26,5 +26,8 @@ pub trait ClientDB: Sync + Send { fn put(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), DBError>; + + fn exists(&self, col: &str, key: &[u8]) + -> Result; }