Skip to content

Commit

Permalink
fix: incorrect when data search is any
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Jun 20, 2024
1 parent b908020 commit 36d5838
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/ckb-indexer/src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,18 @@ export class CKBCellCollector implements BaseCellCollector {
}

// set data range to narrow the search result if the data is set
// the default data search filter mode is exact search that is the same as ckb-indexer
if (!query.outputDataLenRange) {
if (
query.data &&
query.data !== "any" &&
typeof query.data === "string"
) {
const dataLenRange = getHexStringBytes(unwrapDataWrapper(query.data));
query.outputDataLenRange = [
"0x" + dataLenRange.toString(16),
"0x" + (dataLenRange + 1).toString(16),
];
}
if (
!query.outputDataLenRange &&
query.data &&
query.data !== "any" &&
// the default data search filter mode is exact search that is the same as ckb-indexer
(typeof query.data === "string" || query.data.searchMode === "exact")
) {
const dataLenRange = getHexStringBytes(unwrapDataWrapper(query.data));
query.outputDataLenRange = [
"0x" + dataLenRange.toString(16),
"0x" + (dataLenRange + 1).toString(16),
];
}

if (!query.scriptLenRange && query.type === "empty") {
Expand Down
2 changes: 2 additions & 0 deletions packages/ckb-indexer/tests/resultFormatter.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ test("should toSearchKey works fine", async (t) => {
outputCapacityRange: undefined,
scriptLenRange: undefined,
blockRange: undefined,
outputData: undefined,
outputDataFilterMode: undefined,
outputDataLenRange: ["0x1", "0x2"],
},
};
Expand Down
2 changes: 2 additions & 0 deletions packages/ckb-indexer/tests/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test("should generateSearchKey works fine", async (t) => {
outputCapacityRange: undefined,
blockRange: undefined,
scriptLenRange: undefined,
outputData: undefined,
outputDataFilterMode: undefined,
outputDataLenRange: ["0x1", "0x2"],
},
};
Expand Down

0 comments on commit 36d5838

Please sign in to comment.