,
}
impl Database {
/// Creates new database handle.
///
/// # Arguments
///
/// * `path` - database directory
pub fn open(path: P) -> io::Result where P: AsRef {
let result = Database {
database: Mutex::new(db::Database::open(path)?),
};
Ok(result)
}
/// Closes the inner database
pub fn close(&self) -> io::Result<()> {
self.database.lock().close()
}
/// Reopens database at the same location.
pub fn reopen(&self) -> io::Result<()> {
self.database.lock().reopen()
}
/// Inserts one or more blooms into database.
///
/// # Arguments
///
/// * `from` - index of the first bloom that needs to be inserted
/// * `blooms` - iterator over blooms
pub fn insert_blooms<'a, I, B>(&self, from: u64, blooms: I) -> io::Result<()>
where ethbloom::BloomRef<'a>: From, I: Iterator- {
self.database.lock().insert_blooms(from, blooms)
}
/// Returns indexes of all headers matching given bloom in a specified range.
///
/// # Arguments
///
/// * `from` - index of the first bloom that needs to be checked
/// * `to` - index of the last bloom that needs to be checked (inclusive range)
/// * `blooms` - searched pattern
pub fn filter<'a, B, I, II>(&self, from: u64, to: u64, blooms: II) -> io::Result>
where ethbloom::BloomRef<'a>: From, II: IntoIterator
- + Copy, I: Iterator
- {
self.database.lock()
.iterate_matching(from, to, blooms)?
.collect::, _>>()
}
}