mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
docs: udpate usage section
Former-commit-id: 5e9e9c2a00da6cf147c1053a24575c01c101c4e1 [formerly f667c0acb2a352efbddae3b567a1e5d9676c1491] [formerly 72e3449a076a58e7b7a83807a128329d98c6d358 [formerly d206da4e1954eeef403dd13665c5e6e9b61b8a72]] [formerly 33358b42322573698bf152845f6cae81bfa47ac5 [formerly 406a80a04486d432ce90bf0f99865735e9b7b3fe] [formerly 20ef1a77021f41a1b55975a99166c956b6ed1abb [formerly 115574561d]]]
Former-commit-id: 4c72f610614641b4cdc93289e906cfb43d8a53dd [formerly 4c2af522095b22547fd7fb15628d2d92a56bc3af] [formerly fdb6c11f0c72baa685e4cf73a003d0f364e4812b [formerly 5073e1222fecec2d74e63595adc97058e08e7f00]]
Former-commit-id: eca49ae7a42809e35d9d04e49b544bb883eb90b6 [formerly 0baec6a47c7ec8e37f3dc77afedf30455d327622]
Former-commit-id: 897ed8b72595d4e20663f1464a394a69e2f216d8
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