Skip to content

Commit

Permalink
More robust support on networks which throw when filters are not supp…
Browse files Browse the repository at this point in the history
…orted (ethers-io#3767).
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 0d872f3 commit 172f2c8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src.ts/providers/subscriber-filterid.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isError } from "../utils/index.js";

import { PollingEventSubscriber } from "./subscriber-polling.js";

import type { AbstractProvider, Subscriber } from "./abstract-provider.js";
import type { Network } from "./network.js";
import type { EventFilter } from "./provider.js";
import type { JsonRpcApiProvider } from "./provider-jsonrpc.js";


function copy(obj: any): any {
return JSON.parse(JSON.stringify(obj));
}
Expand Down Expand Up @@ -59,12 +60,25 @@ export class FilterIdSubscriber implements Subscriber {

async #poll(blockNumber: number): Promise<void> {
try {
// Subscribe if necessary
if (this.#filterIdPromise == null) {
this.#filterIdPromise = this._subscribe(this.#provider);
}

const filterId = await this.#filterIdPromise;
// Get the Filter ID
let filterId: null | string = null;
try {
filterId = await this.#filterIdPromise;
} catch (error) {
if (!isError(error, "UNSUPPORTED_OPERATION") || error.operation !== "eth_newFilter") {
throw error;
}
}

// The backend does not support Filter ID; downgrade to
// polling
if (filterId == null) {
this.#filterIdPromise = null;
this.#provider._recoverSubscriber(this, this._recover(this.#provider));
return;
}
Expand Down

0 comments on commit 172f2c8

Please sign in to comment.