mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
docs: udpate usage section
This commit is contained in:
@@ -57,7 +57,51 @@ yarn add @zk-kit/incremental-merkle-tree.sol
|
||||
|
||||
## 📜 Usage
|
||||
|
||||
```solidity
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "@zk-kit/incremental-merkle-tree.sol/contracts/IncrementalBinaryTree.sol";
|
||||
|
||||
contract Test {
|
||||
using IncrementalBinaryTree for IncrementalTreeData;
|
||||
|
||||
event TreeCreated(bytes32 id, uint8 depth);
|
||||
event LeafInserted(bytes32 indexed treeId, uint256 leaf, uint256 root);
|
||||
event LeafRemoved(bytes32 indexed treeId, uint256 leaf, uint256 root);
|
||||
|
||||
mapping(bytes32 => IncrementalTreeData) public trees;
|
||||
|
||||
function createTree(bytes32 _id, uint8 _depth) external {
|
||||
require(trees[_id].depth == 0, "Test: tree already exists");
|
||||
|
||||
trees[_id].init(_depth, 0);
|
||||
|
||||
emit TreeCreated(_id, _depth);
|
||||
}
|
||||
|
||||
function insertLeaf(bytes32 _treeId, uint256 _leaf) external {
|
||||
require(trees[_treeId].depth != 0, "Test: tree does not exist");
|
||||
|
||||
trees[_treeId].insert(_leaf);
|
||||
|
||||
emit LeafInserted(_treeId, _leaf, trees[_treeId].root);
|
||||
}
|
||||
|
||||
function removeLeaf(
|
||||
bytes32 _treeId,
|
||||
uint256 _leaf,
|
||||
uint256[] memory _proofSiblings,
|
||||
uint8[] memory _proofPathIndices
|
||||
) external {
|
||||
require(trees[_treeId].depth != 0, "Test: tree does not exist");
|
||||
|
||||
trees[_treeId].remove(_leaf, _proofSiblings, _proofPathIndices);
|
||||
|
||||
emit LeafRemoved(_treeId, _leaf, trees[_treeId].root);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Contacts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user