Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get logs #1034

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions web3/packages/api-server/src/methods/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ export class Eth {
} else {
const lastPollLogId = await this.filterManager.getLastPoll(filter_id);
const logs = await this.query.getLogsByFilter(
await this._rpcFilterRequestToGetLogsParams(filter),
await this._rpcFilterRequestToGetLogsParams(filter, false),
lastPollLogId
);

Expand All @@ -1035,9 +1035,8 @@ export class Eth {
}

async getLogs(args: [RpcFilterRequest]): Promise<EthLog[]> {
return await this._getLogs(
await this._rpcFilterRequestToGetLogsParams(args[0])
);
const params = await this._rpcFilterRequestToGetLogsParams(args[0], true);
return await this._getLogs(params);
}

async _getLogs(filter: FilterParams): Promise<EthLog[]> {
Expand Down Expand Up @@ -1175,7 +1174,8 @@ export class Eth {
}

private async _rpcFilterRequestToGetLogsParams(
filter: RpcFilterRequest
filter: RpcFilterRequest,
isGetLogs: boolean
): Promise<FilterParams> {
if (filter.blockHash != null) {
if (filter.fromBlock !== undefined || filter.toBlock !== undefined) {
Expand All @@ -1196,7 +1196,8 @@ export class Eth {
const [fromBlock, toBlock] =
await this._normalizeBlockParameterForFilterRequest(
filter.fromBlock,
filter.toBlock
filter.toBlock,
isGetLogs
);
return {
fromBlock,
Expand All @@ -1209,16 +1210,22 @@ export class Eth {

private async _normalizeBlockParameterForFilterRequest(
fromBlock: undefined | BlockParameter,
toBlock: undefined | BlockParameter
toBlock: undefined | BlockParameter,
isGetLogs: boolean
): Promise<[bigint, bigint]> {
let normalizedFromBlock: bigint;
let normalizedToBlock: bigint;
const latestBlockNumber = await this._getTipNumber();
// See also:
// - https://github.com/nervosnetwork/godwoken-web3/pull/427#discussion_r918904239
// - https://github.com/nervosnetwork/godwoken-web3/pull/300/files/131542bd5cc272279d27760e258fb5fa5de6fc9a#r861541728
let fromBlockParam = fromBlock ?? "earliest";
if (isGetLogs) {
// https://github.com/ethereum/go-ethereum/blob/20f8eb756bdbfa6dbd94374bbad15883e23ab150/eth/filters/api.go#L388
fromBlockParam = fromBlock ?? "latest";
}
const _fromBlock: bigint | undefined = await this._parseBlockParameter(
fromBlock ?? "earliest"
fromBlockParam
);
normalizedFromBlock = _fromBlock ?? latestBlockNumber;

Expand Down