From 400d57621b3e9a33679a528b5072449699f0a068 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sun, 12 Feb 2023 22:03:37 -0500 Subject: [PATCH] Fixed ignored polling override for JsonRpcApiProvider. --- src.ts/providers/provider-jsonrpc.ts | 76 +++------------------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/src.ts/providers/provider-jsonrpc.ts b/src.ts/providers/provider-jsonrpc.ts index e73c572330..19d244d48b 100644 --- a/src.ts/providers/provider-jsonrpc.ts +++ b/src.ts/providers/provider-jsonrpc.ts @@ -23,6 +23,7 @@ import { AbstractProvider, UnmanagedSubscriber } from "./abstract-provider.js"; import { AbstractSigner } from "./abstract-signer.js"; import { Network } from "./network.js"; import { FilterIdEventSubscriber, FilterIdPendingSubscriber } from "./subscriber-filterid.js"; +import { PollingEventSubscriber } from "./subscriber-polling.js"; import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; import type { TransactionLike } from "../transaction/index.js"; @@ -628,6 +629,9 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { if (sub.type === "pending") { return new FilterIdPendingSubscriber(this); } if (sub.type === "event") { + if (this._getOption("polling")) { + return new PollingEventSubscriber(this, sub.filter); + } return new FilterIdEventSubscriber(this, sub.filter); } @@ -806,74 +810,6 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { ); e.info = { error, payload }; return e; -/* - let message = "missing revert data during JSON-RPC call"; - - const action = <"call" | "estimateGas" | "unknown">(({ eth_call: "call", eth_estimateGas: "estimateGas" })[method] || "unknown"); - let data: null | string = null; - let reason: null | string = null; - const transaction = <{ from: string, to: string, data: string }>((payload).params[0]); - const invocation = null; - let revert: null | { signature: string, name: string, args: Array } = null; - - if (result) { - // @TODO: Extract errorSignature, errorName, errorArgs, reason if - // it is Error(string) or Panic(uint25) - message = "execution reverted during JSON-RPC call"; - data = result.data; - - let bytes = getBytes(data); - if (bytes.length % 32 !== 4) { - message += " (could not parse reason; invalid data length)"; - - } else if (data.substring(0, 10) === "0x08c379a0") { - // Error(string) - try { - if (bytes.length < 68) { throw new Error("bad length"); } - bytes = bytes.slice(4); - const pointer = getNumber(hexlify(bytes.slice(0, 32))); - bytes = bytes.slice(pointer); - if (bytes.length < 32) { throw new Error("overrun"); } - const length = getNumber(hexlify(bytes.slice(0, 32))); - bytes = bytes.slice(32); - if (bytes.length < length) { throw new Error("overrun"); } - reason = toUtf8String(bytes.slice(0, length)); - revert = { - signature: "Error(string)", - name: "Error", - args: [ reason ] - }; - message += `: ${ JSON.stringify(reason) }`; - - } catch (error) { - console.log(error); - message += " (could not parse reason; invalid data length)"; - } - - } else if (data.substring(0, 10) === "0x4e487b71") { - // Panic(uint256) - try { - if (bytes.length !== 36) { throw new Error("bad length"); } - const arg = getNumber(hexlify(bytes.slice(4))); - revert = { - signature: "Panic(uint256)", - name: "Panic", - args: [ arg ] - }; - reason = `Panic due to ${ PanicReasons.get(Number(arg)) || "UNKNOWN" }(${ arg })`; - message += `: ${ reason }`; - } catch (error) { - console.log(error); - message += " (could not parse panic reason)"; - } - } - } - - return makeError(message, "CALL_EXCEPTION", { - action, data, reason, transaction, invocation, revert, - info: { payload, error } - }); - */ } // Only estimateGas and call can return arbitrary contract-defined text, so now we @@ -904,7 +840,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { if (message.match(/insufficient funds|base fee exceeds gas limit/i)) { return makeError("insufficient funds for intrinsic transaction cost", "INSUFFICIENT_FUNDS", { - transaction + transaction, info: { error } }); } @@ -926,7 +862,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { if (message.match(/the method .* does not exist/i)) { return makeError("unsupported operation", "UNSUPPORTED_OPERATION", { - operation: payload.method + operation: payload.method, info: { error } }); }