From 6484908cb25dd35e5d98b2672dca72ed3f30cbe1 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 2 Jul 2019 16:06:47 -0400 Subject: [PATCH] Allow providers to prepare their Network object. --- packages/providers/src.ts/base-provider.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/providers/src.ts/base-provider.ts b/packages/providers/src.ts/base-provider.ts index 70f600a6cc..73f165f2f9 100644 --- a/packages/providers/src.ts/base-provider.ts +++ b/packages/providers/src.ts/base-provider.ts @@ -9,7 +9,7 @@ import { arrayify, hexDataLength, hexlify, hexValue, isHexString } from "@ethers import * as errors from "@ethersproject/errors"; import { namehash } from "@ethersproject/hash"; import { getNetwork, Network, Networkish } from "@ethersproject/networks"; -import { defineReadOnly, resolveProperties } from "@ethersproject/properties"; +import { defineReadOnly, getStatic, resolveProperties } from "@ethersproject/properties"; import { Transaction } from "@ethersproject/transactions"; import { toUtf8String } from "@ethersproject/strings"; import { poll } from "@ethersproject/web"; @@ -187,7 +187,7 @@ export class BaseProvider extends Provider { this.ready.catch((error) => { }); } else { - let knownNetwork = getNetwork((network == null) ? "homestead": network); + let knownNetwork = getStatic<(network: Networkish) => Network>(new.target, "getNetwork")(network); if (knownNetwork) { defineReadOnly(this, "_network", knownNetwork); defineReadOnly(this, "ready", Promise.resolve(this._network)); @@ -216,6 +216,10 @@ export class BaseProvider extends Provider { return defaultFormatter; } + static getNetwork(network: Networkish): Network { + return getNetwork((network == null) ? "homestead": network); + } + poll(): void { let pollId = nextPollId++; this.emit("willPoll", pollId);