From f42f258beb305a06e563ad16522f095a72da32eb Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 27 Jul 2023 20:53:55 -0400 Subject: [PATCH] Allow overriding pollingInterval in JsonRpcProvider constructor (via discord). --- src.ts/providers/provider-jsonrpc.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src.ts/providers/provider-jsonrpc.ts b/src.ts/providers/provider-jsonrpc.ts index dfb4c7a96..cd88e5c4a 100644 --- a/src.ts/providers/provider-jsonrpc.ts +++ b/src.ts/providers/provider-jsonrpc.ts @@ -34,7 +34,7 @@ import { PollingEventSubscriber } from "./subscriber-polling.js"; import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; import type { TransactionLike } from "../transaction/index.js"; -import type { AbstractProviderOptions, PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js"; +import type { PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js"; import type { Networkish } from "./network.js"; import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js"; import type { Signer } from "./signer.js"; @@ -196,6 +196,7 @@ export type JsonRpcApiProviderOptions = { batchMaxCount?: number; cacheTimeout?: number; + pollingInterval?: number; }; const defaultOptions = { @@ -206,7 +207,8 @@ const defaultOptions = { batchMaxSize: (1 << 20), // 1Mb batchMaxCount: 100, // 100 requests - cacheTimeout: 250 + cacheTimeout: 250, + pollingInterval: 4000 } /** @@ -543,11 +545,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { } constructor(network?: Networkish, options?: JsonRpcApiProviderOptions) { - const superOptions: AbstractProviderOptions = { }; - if (options && options.cacheTimeout != null) { - superOptions.cacheTimeout = options.cacheTimeout; - } - super(network, superOptions); + super(network, options); this.#nextId = 1; this.#options = Object.assign({ }, defaultOptions, options || { }); @@ -1079,6 +1077,12 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { } } +// @TODO: remove this in v7, it is not exported because this functionality +// is exposed in the JsonRpcApiProvider by setting polling to true. It should +// be safe to remove regardless, because it isn't reachable, but just in case. +/** + * @_ignore: + */ export abstract class JsonRpcApiPollingProvider extends JsonRpcApiProvider { #pollingInterval: number; constructor(network?: Networkish, options?: JsonRpcApiProviderOptions) {