@ -7,32 +7,53 @@ Compatible with the Go version: https://github.com/arnaucube/go-merkletree
## Usage
## Usage
Import lib:
```rust
extern crate merkletree_rs;
use merkletree_rs::{db, MerkleTree, TestValue, Value};
```
Create new tree:
Create new tree:
```rust
```rust
// to build the storage, the first parameter is the path and the second parameter specifies if wants to use a in_memory database or a directory of the filesystem
// to build the storage, the first parameter is the path and the second parameter specifies if wants to use a in_memory database or a directory of the filesystem
let mut sto = db::Db::new("test".to_string(), true);
let mut sto = db::Db::new("test".to_string(), true);
let mut mt: MerkleTree::new(&mut sto, 140);
let mut mt = MerkleTree::new(&mut sto, 140 as u32);
```
```
Add value to leaf:
Add value to leaf:
```rust
```rust
let val = TestValue {
bytes: "this is a test leaf".as_bytes().to_vec(),
index_length: 15,
let val: TestValue = TestValue {
bytes: "this is a test leaf".as_bytes().to_vec(),
index_length: 15,
};
};
mt.add(&val);
mt.add(&val).unwrap();
```
```
Get proof:
Get proof:
```rust
```rust
let mp = mt.generate_proof(val.hi());
let mp = mt.generate_proof(val.hi());
println!("{:?}", mp);
```
```
Verify proof:
Verify proof:
```rust
```rust
// check if the value exist
// check if the value exist
let v = verify_proof(mt.root, mp, val.hi(), val.ht(), mt.num_levels);