MerkleTreeMock.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import {MerkleTree} from "../utils/structs/MerkleTree.sol";
  4. contract MerkleTreeMock {
  5. using MerkleTree for MerkleTree.Bytes32PushTree;
  6. MerkleTree.Bytes32PushTree private _tree;
  7. event LeafInserted(bytes32 leaf, uint256 index, bytes32 root);
  8. function setup(uint8 _depth, bytes32 _zero) public {
  9. _tree.setup(_depth, _zero);
  10. }
  11. function push(bytes32 leaf) public {
  12. (uint256 leafIndex, bytes32 currentRoot) = _tree.push(leaf);
  13. emit LeafInserted(leaf, leafIndex, currentRoot);
  14. }
  15. function root() public view returns (bytes32) {
  16. return _tree.root();
  17. }
  18. function depth() public view returns (uint256) {
  19. return _tree.depth();
  20. }
  21. // internal state
  22. function nextLeafIndex() public view returns (uint256) {
  23. return _tree._nextLeafIndex;
  24. }
  25. function sides(uint256 i) public view returns (bytes32) {
  26. return _tree._sides[i];
  27. }
  28. function zeros(uint256 i) public view returns (bytes32) {
  29. return _tree._zeros[i];
  30. }
  31. }