| Crates.io | vsdb_hash_db |
| lib.rs | vsdb_hash_db |
| version | 5.0.0 |
| created_at | 2023-03-25 13:18:52.640157+00 |
| updated_at | 2025-08-11 04:13:06.052431+00 |
| description | An implementation of the `hash_db::HashDB` trait |
| homepage | https://github.com/rust-util-collections/vsdb |
| repository | https://github.com/rust-util-collections/vsdb |
| max_upload_size | |
| id | 820241 |
| size | 42,631 |
An implementation of the
hash_db::HashDBtrait.
This crate provides an implementation of the hash_db::HashDB trait, based on the powerful vsdb crate.
Add this to your Cargo.toml:
[dependencies]
vsdb_hash_db = "4.0"
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()));
This project is licensed under the MIT license.