Skip to content

Commit 6c099f5

Browse files
committed
fix: sort paginated logs
1 parent 74e6f50 commit 6c099f5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/utils/getLogsPaginated.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export type GetLogsPaginatedParameters<
3030
pageSize: bigint;
3131
};
3232

33+
/**
34+
* Get logs in pages, to avoid rate limiting
35+
* Must be used with client that has batching enabled
36+
* @param client
37+
* @param params
38+
* @returns
39+
*/
3340
export async function getLogsPaginated<
3441
chain extends Chain | undefined,
3542
const abiEvent extends AbiEvent | undefined = undefined,
@@ -79,7 +86,14 @@ export async function getLogsPaginated<
7986
),
8087
),
8188
);
82-
const events = responses.flat();
8389

84-
return events;
90+
return responses.flat().sort((a, b) => {
91+
if (a.blockNumber === b.blockNumber) {
92+
return a.logIndex - b.logIndex;
93+
} else if (a.blockNumber < b.blockNumber) {
94+
return -1;
95+
} else {
96+
return 1;
97+
}
98+
});
8599
}

0 commit comments

Comments
 (0)