Skip to content

Commit b275d2a

Browse files
committed
evm-rpc: sort block numbers
1 parent d89396e commit b275d2a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"packages/beaconchain",
3434
"packages/cli",
3535
"packages/evm",
36+
"packages/evm-rpc",
3637
"packages/indexer",
3738
"packages/protocol",
3839
"packages/starknet",

packages/evm-rpc/src/log-fetcher.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { LogFilter } from "@apibara/evm";
12
import type { Bytes } from "@apibara/protocol";
23
import type { RpcLog } from "viem";
34
import { hexToNumber, isHex, numberToHex, pad, trim } from "viem";
45
import type { Log } from "./block";
5-
import type { Filter, LogFilter } from "./filter";
6+
import type { Filter } from "./filter";
67
import type { ViemRpcClient } from "./stream-config";
78
import { viemRpcLogToDna } from "./transform";
89

@@ -85,6 +86,21 @@ export async function fetchLogsForRange({
8586
return { logs: logsByBlock, blockNumbers: [] };
8687
}
8788

89+
console.log("Fetching in range", fromBlock, toBlock);
90+
// console.log("filter: ", filter.logs);
91+
// console.log(
92+
// "req: ",
93+
// filter.logs.map((logFilter) => [
94+
// {
95+
// fromBlock: numberToHex(fromBlock),
96+
// toBlock: numberToHex(toBlock),
97+
// address: logFilter.address,
98+
// topics:
99+
// logFilter.topics !== undefined ? [...logFilter.topics] : undefined,
100+
// },
101+
// ]),
102+
// );
103+
88104
const responses = await Promise.all(
89105
filter.logs.map(async (logFilter) => {
90106
const logs = await client.request({
@@ -94,7 +110,10 @@ export async function fetchLogsForRange({
94110
fromBlock: numberToHex(fromBlock),
95111
toBlock: numberToHex(toBlock),
96112
address: logFilter.address,
97-
topics: logFilter.topics ? [...logFilter.topics] : undefined,
113+
topics:
114+
logFilter.topics !== undefined
115+
? [...logFilter.topics]
116+
: undefined,
98117
},
99118
],
100119
});
@@ -149,7 +168,7 @@ export async function fetchLogsForRange({
149168
}
150169
}
151170

152-
return { logs: logsByBlock, blockNumbers: Array.from(blockNumbers) };
171+
return { logs: logsByBlock, blockNumbers: Array.from(blockNumbers).sort() };
153172
}
154173

155174
function refineLog(log: RpcLog, filter: LogFilter): Log | null {

0 commit comments

Comments
 (0)