Skip to content

Commit c0ec67f

Browse files
committed
update docs
1 parent d05dabe commit c0ec67f

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![GitHub top language](https://img.shields.io/github/languages/top/rust-util-collections/vsdb)
22
[![Rust](https://github.com/rust-util-collections/vsdb/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-util-collections/vsdb/actions/workflows/rust.yml)
3-
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.89+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements)
3+
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.85+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements)
44

55
# vsdb
66

core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add this to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
vsdb_core = "5.0.1"
23+
vsdb_core = "6.0.0"
2424
```
2525

2626
## Features

utils/slot_db/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Add this to your `Cargo.toml`:
1515

1616
```toml
1717
[dependencies]
18-
vsdb_slot_db = "5.0.1"
18+
vsdb_slot_db = "6.0.0"
1919
```
2020

2121
## Usage

utils/trie_db/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Add this to your `Cargo.toml`:
1515

1616
```toml
1717
[dependencies]
18-
vsdb_trie_db = "5.0.1"
18+
vsdb_trie_db = "6.0.1"
1919
```
2020

2121
## Usage
@@ -28,26 +28,33 @@ For more detailed API examples, see [API Examples](docs/api.md).
2828
use vsdb_trie_db::MptStore;
2929

3030
// Create a new MptStore
31-
let mut store = MptStore::new();
31+
let store = MptStore::new();
3232

33-
// Initialize a new trie with a unique backend key
34-
let mut trie = store.trie_init(b"my_app_state").unwrap();
33+
// Initialize a new trie (starts with an empty root)
34+
let mut trie = store.trie_init();
3535

36-
// Insert a key-value pair
36+
// Insert key-value pairs (automatically commits)
3737
trie.insert(b"key1", b"value1").unwrap();
38+
trie.insert(b"key2", b"value2").unwrap();
3839

39-
// Commit the changes to persist them and get a new state root
40-
let mut trie = trie.commit().unwrap();
40+
// Get the current root hash
4141
let root = trie.root();
4242

43-
// Retrieve the value using the latest trie instance
43+
// Retrieve values
4444
let value = trie.get(b"key1").unwrap().unwrap();
4545
assert_eq!(value, b"value1");
4646

47-
// Create a read-only handle to the trie at a specific root
48-
let ro_trie = trie.ro_handle(root).unwrap();
49-
let value = ro_trie.get(b"key1").unwrap().unwrap();
47+
// Load an existing trie from a root hash
48+
let loaded_trie = store.trie_load(&root);
49+
let value = loaded_trie.get(b"key1").unwrap().unwrap();
5050
assert_eq!(value, b"value1");
51+
52+
// Batch update operations
53+
let ops = vec![
54+
(b"key3".as_ref(), Some(b"value3".as_ref())),
55+
(b"key1".as_ref(), None), // Remove key1
56+
];
57+
trie.batch_update(&ops).unwrap();
5158
```
5259

5360
## License

utils/trie_db/docs/api.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,45 @@ This document provides examples for the public APIs in the `vsdb_trie_db` crate.
44

55
## MptStore
66

7-
`MptStore` provides an out-of-the-box wrapper for the `trie-db` crate, backed by `vsdb`.
7+
`MptStore` provides a high-level wrapper for managing Merkle Patricia Tries with persistent storage.
88

99
```rust
1010
use vsdb_trie_db::MptStore;
1111

1212
// Create a new MptStore
13-
let mut store = MptStore::new();
13+
let store = MptStore::new();
1414

15-
// Initialize a new trie with a backend key
16-
let mut trie = store.trie_init(b"my_trie").unwrap();
15+
// Initialize a new trie (starts with an empty root)
16+
let mut trie = store.trie_init();
1717

18-
// Insert a key-value pair
18+
// Insert key-value pairs (automatically commits)
1919
trie.insert(b"key1", b"value1").unwrap();
20+
trie.insert(b"key2", b"value2").unwrap();
2021

21-
// Commit the changes to the trie
22-
let mut trie = trie.commit().unwrap();
22+
// Get the current root hash
2323
let root = trie.root();
2424

25-
// Retrieve the value
25+
// Retrieve values
2626
let value = trie.get(b"key1").unwrap().unwrap();
2727
assert_eq!(value, b"value1");
2828

29-
// Create a read-only handle to the trie at a specific root
30-
let ro_trie = trie.ro_handle(root).unwrap();
31-
let value = ro_trie.get(b"key1").unwrap().unwrap();
29+
// Load an existing trie from a root hash
30+
let loaded_trie = store.trie_load(&root);
31+
let value = loaded_trie.get(b"key1").unwrap().unwrap();
3232
assert_eq!(value, b"value1");
33+
34+
// Remove a key
35+
trie.remove(b"key2").unwrap();
36+
assert!(trie.get(b"key2").unwrap().is_none());
37+
38+
// Batch update operations
39+
let ops = vec![
40+
(b"key3".as_ref(), Some(b"value3".as_ref())), // Insert
41+
(b"key1".as_ref(), None), // Remove
42+
];
43+
trie.batch_update(&ops).unwrap();
44+
45+
// Verify changes
46+
assert!(trie.get(b"key1").unwrap().is_none());
47+
assert_eq!(trie.get(b"key3").unwrap().unwrap(), b"value3");
3348
```

wrappers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Add this to your `Cargo.toml`:
1717

1818
```toml
1919
[dependencies]
20-
vsdb = "5.0.1"
20+
vsdb = "6.0.0"
2121
```
2222

2323
## Highlights

0 commit comments

Comments
 (0)