mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Storage chains: indexing, renewals and reference counting (#8265)
* Transaction indexing * Tests and fixes * Fixed a comment * Style * Build * Style * Apply suggestions from code review Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Code review suggestions * Add missing impl * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * impl JoinInput * Don't store empty slices * JoinInput operates on slices Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,7 @@ fn handle_err<T>(result: parity_db::Result<T>) -> T {
|
||||
}
|
||||
|
||||
/// Wrap parity-db database into a trait object that implements `sp_database::Database`
|
||||
pub fn open<H: Clone>(path: &std::path::Path, db_type: DatabaseType)
|
||||
pub fn open<H: Clone + AsRef<[u8]>>(path: &std::path::Path, db_type: DatabaseType)
|
||||
-> parity_db::Result<std::sync::Arc<dyn Database<H>>>
|
||||
{
|
||||
let mut config = parity_db::Options::with_columns(path, NUM_COLUMNS as u8);
|
||||
@@ -48,7 +48,7 @@ pub fn open<H: Clone>(path: &std::path::Path, db_type: DatabaseType)
|
||||
Ok(std::sync::Arc::new(DbAdapter(db)))
|
||||
}
|
||||
|
||||
impl<H: Clone> Database<H> for DbAdapter {
|
||||
impl<H: Clone + AsRef<[u8]>> Database<H> for DbAdapter {
|
||||
fn commit(&self, transaction: Transaction<H>) -> Result<(), DatabaseError> {
|
||||
handle_err(self.0.commit(transaction.0.into_iter().map(|change|
|
||||
match change {
|
||||
@@ -65,7 +65,11 @@ impl<H: Clone> Database<H> for DbAdapter {
|
||||
handle_err(self.0.get(col as u8, key))
|
||||
}
|
||||
|
||||
fn lookup(&self, _hash: &H) -> Option<Vec<u8>> {
|
||||
unimplemented!();
|
||||
fn contains(&self, col: ColumnId, key: &[u8]) -> bool {
|
||||
handle_err(self.0.get_size(col as u8, key)).is_some()
|
||||
}
|
||||
|
||||
fn value_size(&self, col: ColumnId, key: &[u8]) -> Option<usize> {
|
||||
handle_err(self.0.get_size(col as u8, key)).map(|s| s as usize)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user