@@ -10,16 +10,16 @@ library TreeCbor {
1010
1111 struct Tree {
1212 TreeNodeCbor.TreeNode[] nodes;
13- CidCbor. Cid[] cids;
13+ Cid[] cids;
1414 }
1515
1616 function _readTree (bytes [] memory cborData ) internal pure returns (Tree memory ) {
1717 require (cborData.length > 0 , "Tree must contain nodes " );
1818 TreeNodeCbor.TreeNode[] memory nodes = new TreeNodeCbor.TreeNode [](cborData.length );
19- CidCbor. Cid[] memory cids = new CidCbor. Cid [](cborData.length );
19+ Cid[] memory cids = new Cid [](cborData.length );
2020
2121 for (uint i = 0 ; i < cborData.length ; i++ ) {
22- cids[i] = CidCbor. Cid.wrap (uint256 (sha256 (cborData[i])));
22+ cids[i] = Cid.wrap (uint256 (sha256 (cborData[i])));
2323 uint byteIdx;
2424 (nodes[i], byteIdx) = TreeNodeCbor.readTreeNode (cborData[i], 0 );
2525 require (byteIdx == cborData[i].length , "expected to read all bytes " );
@@ -32,14 +32,13 @@ library TreeCbor {
3232 return validTree (_readTree (cborData));
3333 }
3434
35- function hasCid (Tree memory tree , CidCbor. Cid cid ) internal pure returns (bool , uint ) {
35+ function hasCid (Tree memory tree , Cid cid ) internal pure returns (bool , uint ) {
3636 return _hasCid (tree, cid, 0 );
3737 }
3838
39- function _hasCid (Tree memory tree , CidCbor.Cid cid , uint startIdx ) internal pure returns (bool , uint ) {
40- uint256 index = CidCbor.Cid.unwrap (cid);
39+ function _hasCid (Tree memory tree , Cid cid , uint startIdx ) internal pure returns (bool , uint ) {
4140 for (uint i = startIdx; i < tree.cids.length ; i++ ) {
42- if (CidCbor.Cid. unwrap ( tree.cids[i]) == index ) {
41+ if (tree.cids[i] == cid ) {
4342 return (true , i);
4443 }
4544 }
@@ -48,29 +47,23 @@ library TreeCbor {
4847
4948 function validTree (Tree memory tree ) internal pure returns (Tree memory ) {
5049 for (uint i = 0 ; i < tree.cids.length ; i++ ) {
51- uint256 thisCid = CidCbor.Cid.unwrap (tree.cids[i]);
5250 for (uint j = i + 1 ; j < tree.nodes.length ; j++ ) {
53- uint256 otherCid = CidCbor.Cid.unwrap (tree.cids[j]);
54- require (thisCid != otherCid, "node cids must be unique " );
51+ require (tree.cids[i] != tree.cids[j], "node cids must be unique " );
5552 }
5653 }
5754 return tree;
5855 }
5956
60- function memPop (CidCbor. Cid[] memory arr ) internal pure returns (CidCbor. Cid[] memory ) {
61- CidCbor. Cid[] memory newArr = new CidCbor. Cid [](arr.length - 1 );
57+ function memPop (Cid[] memory arr ) internal pure returns (Cid[] memory ) {
58+ Cid[] memory newArr = new Cid [](arr.length - 1 );
6259 for (uint i = 1 ; i < arr.length ; i++ ) {
6360 newArr[i - 1 ] = arr[i];
6461 }
6562 return newArr;
6663 }
6764
68- function memCat (CidCbor.Cid[] memory arr1 , CidCbor.Cid[] memory arr2 )
69- internal
70- pure
71- returns (CidCbor.Cid[] memory )
72- {
73- CidCbor.Cid[] memory newArr = new CidCbor.Cid [](arr1.length + arr2.length );
65+ function memCat (Cid[] memory arr1 , Cid[] memory arr2 ) internal pure returns (Cid[] memory ) {
66+ Cid[] memory newArr = new Cid [](arr1.length + arr2.length );
7467 for (uint i = 0 ; i < arr1.length ; i++ ) {
7568 newArr[i] = arr1[i];
7669 }
@@ -82,19 +75,19 @@ library TreeCbor {
8275
8376 function verifyInclusion (
8477 TreeCbor.Tree memory tree ,
85- CidCbor. Cid entryCid ,
78+ Cid entryCid ,
8679 bytes memory targetRecord ,
8780 string memory targetKey
8881 ) internal pure returns (bool ) {
89- CidCbor. Cid[] memory rightWalk;
90- CidCbor. Cid currentCid;
82+ Cid[] memory rightWalk;
83+ Cid currentCid;
9184 TreeNodeCbor.TreeNode memory currentNode;
9285 uint currentIndex;
9386 bool found = false ;
9487 bool hasCurrent = false ;
9588
96- CidCbor. Cid targetCid = CidCbor. Cid.wrap (uint256 (sha256 (targetRecord)));
97- CidCbor. Cid[] memory queue = new CidCbor. Cid [](1 );
89+ Cid targetCid = Cid.wrap (uint256 (sha256 (targetRecord)));
90+ Cid[] memory queue = new Cid [](1 );
9891 queue[0 ] = entryCid;
9992
10093 while (queue.length > 0 ) {
@@ -106,15 +99,12 @@ library TreeCbor {
10699 }
107100 currentNode = tree.nodes[currentIndex];
108101
109- rightWalk = new CidCbor. Cid [](currentNode.entries.length );
102+ rightWalk = new Cid [](currentNode.entries.length );
110103
111104 for (uint i = 0 ; i < currentNode.entries.length ; i++ ) {
112105 rightWalk[i] = currentNode.entries[i].tree;
113106 if (keccak256 (abi.encode (currentNode.entries[i].key)) == keccak256 (abi.encode (targetKey))) {
114- require (
115- CidCbor.Cid.unwrap (currentNode.entries[i].value) == CidCbor.Cid.unwrap (targetCid),
116- "cid mismatch "
117- );
107+ require (currentNode.entries[i].value == targetCid, "cid mismatch " );
118108 require (! found, "duplicate entry " );
119109 found = true ;
120110 }
0 commit comments