Skip to content

Commit

Permalink
Allow providers to prepare their Network object.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 2, 2019
1 parent 04bdf45 commit 6484908
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6484908

Please sign in to comment.