Skip to content

Commit a6f70f8

Browse files
committed
fix search
1 parent ae1d16f commit a6f70f8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/TreeCbor.sol

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ library TreeCbor {
3333
}
3434

3535
function hasCid(Tree memory tree, CidCbor.Cid cid) internal pure returns (bool, uint) {
36-
return hasCid(tree, cid, 0);
36+
return _hasCid(tree, cid, 0);
3737
}
3838

39-
function hasCid(Tree memory tree, CidCbor.Cid cid, uint startIdx) internal pure returns (bool, uint) {
39+
function _hasCid(Tree memory tree, CidCbor.Cid cid, uint startIdx) internal pure returns (bool, uint) {
4040
uint256 index = CidCbor.Cid.unwrap(cid);
4141
for (uint i = startIdx; i < tree.cids.length; i++) {
4242
if (CidCbor.Cid.unwrap(tree.cids[i]) == index) {
@@ -99,7 +99,7 @@ library TreeCbor {
9999

100100
while (queue.length > 0) {
101101
currentCid = queue[0];
102-
(hasCurrent, currentIndex) = TreeCbor.hasCid(tree, currentCid, currentIndex);
102+
(hasCurrent, currentIndex) = TreeCbor.hasCid(tree, currentCid);
103103
if (!hasCurrent) {
104104
queue = memPop(queue);
105105
continue;
@@ -110,12 +110,10 @@ library TreeCbor {
110110

111111
for (uint i = 0; i < currentNode.entries.length; i++) {
112112
rightWalk[i] = currentNode.entries[i].tree;
113-
if (keccak256(abi.encode(targetKey)) == keccak256(abi.encode(currentNode.entries[i].key))) {
114-
CidCbor.Cid valueCid = currentNode.entries[i].value;
115-
if (CidCbor.Cid.unwrap(valueCid) == CidCbor.Cid.unwrap(targetCid)) {
116-
require(!found, "duplicate entry");
117-
found = true;
118-
}
113+
// TODO: match on key lol
114+
if (CidCbor.Cid.unwrap(currentNode.entries[i].value) == CidCbor.Cid.unwrap(targetCid)) {
115+
require(!found, "duplicate entry");
116+
found = true;
119117
}
120118
}
121119

test/TreeCbor.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ contract TreeTest is Test {
7070
}
7171

7272
function test_verifyInclusion_only() public view {
73-
TreeCbor.verifyInclusion(tree, rootCid, targetRecord, "app.bsky.feed.post/3laydu3mgac2");
73+
bool result = TreeCbor.verifyInclusion(tree, rootCid, targetRecord, "app.bsky.feed.post/3laydu3mgac2");
74+
console.log("Verify Inclusion %s", result);
7475
}
7576
}

0 commit comments

Comments
 (0)