Crate vsdb_hash_db

Source
Expand description

§vsdb_hash_db

Crates.io Docs.rs License Rust

An implementation of the hash_db::HashDB trait.

This crate provides an implementation of the hash_db::HashDB trait, based on the powerful vsdb crate.

§Installation

Add this to your Cargo.toml:

[dependencies]
vsdb_hash_db = "4.0"

§Usage

vsdb_hash_db provides an implementation of the hash_db::HashDB trait, backed by vsdb.

use vsdb_hash_db::{MmBackend, KeccakHasher, sp_hash_db::{HashDB, Hasher}};
use vsdb::{Orphan, DagMapRaw};

// Define a type alias for the backend
type TrieBackend = MmBackend<KeccakHasher, Vec<u8>>;

// Create a new Orphan instance
let mut orphan = Orphan::new_dag_map_raw();

// Create a new TrieBackend
let mut db = TrieBackend::new(&mut orphan).unwrap();

// Insert a value and get its hash
let value = b"hello world";
let hash = db.insert(Default::default(), value);

// Retrieve the value using its hash
let retrieved_value = db.get(&hash, Default::default()).unwrap();
assert_eq!(retrieved_value, value);

// Check if a hash exists
assert!(db.contains(&hash, Default::default()));

// Remove the value
db.remove(&hash, Default::default());
assert!(!db.contains(&hash, Default::default()));

§License

This project is licensed under the MIT license.

Re-exports§

pub use hash_db as sp_hash_db;
pub use vsdb;

Structs§

KeccakHasher
Concrete Hasher impl for the Keccak-256 hash
MmBackend
A memory-mapped backend for the trie.
Value
A struct representing a value in the trie, with a reference count.

Traits§

TrieVar
A trait for types that can be used as values in the trie.

Type Aliases§

TrieBackend
A type alias for the memory-mapped backend with Keccak hashing.