vsdb_hash_db

Crates.iovsdb_hash_db
lib.rsvsdb_hash_db
version5.0.0
created_at2023-03-25 13:18:52.640157+00
updated_at2025-08-11 04:13:06.052431+00
descriptionAn implementation of the `hash_db::HashDB` trait
homepagehttps://github.com/rust-util-collections/vsdb
repositoryhttps://github.com/rust-util-collections/vsdb
max_upload_size
id820241
size42,631
中正 (haxjump)

documentation

README

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.

Commit count: 382

cargo fmt