|
| 1 | +import type { LogFilter } from "@apibara/evm"; |
1 | 2 | import type { Bytes } from "@apibara/protocol"; |
2 | 3 | import type { RpcLog } from "viem"; |
3 | 4 | import { hexToNumber, isHex, numberToHex, pad, trim } from "viem"; |
4 | 5 | import type { Log } from "./block"; |
5 | | -import type { Filter, LogFilter } from "./filter"; |
| 6 | +import type { Filter } from "./filter"; |
6 | 7 | import type { ViemRpcClient } from "./stream-config"; |
7 | 8 | import { viemRpcLogToDna } from "./transform"; |
8 | 9 |
|
@@ -94,7 +95,10 @@ export async function fetchLogsForRange({ |
94 | 95 | fromBlock: numberToHex(fromBlock), |
95 | 96 | toBlock: numberToHex(toBlock), |
96 | 97 | address: logFilter.address, |
97 | | - topics: logFilter.topics ? [...logFilter.topics] : undefined, |
| 98 | + topics: |
| 99 | + logFilter.topics !== undefined |
| 100 | + ? [...logFilter.topics] |
| 101 | + : undefined, |
98 | 102 | }, |
99 | 103 | ], |
100 | 104 | }); |
@@ -149,7 +153,11 @@ export async function fetchLogsForRange({ |
149 | 153 | } |
150 | 154 | } |
151 | 155 |
|
152 | | - return { logs: logsByBlock, blockNumbers: Array.from(blockNumbers) }; |
| 156 | + const sortedBlockNumbers = Array.from(blockNumbers).sort((a, b) => |
| 157 | + a < b ? -1 : a > b ? 1 : 0, |
| 158 | + ); |
| 159 | + |
| 160 | + return { logs: logsByBlock, blockNumbers: sortedBlockNumbers }; |
153 | 161 | } |
154 | 162 |
|
155 | 163 | function refineLog(log: RpcLog, filter: LogFilter): Log | null { |
|
0 commit comments