Fix JsonRpcProvider out-of-order super call (#822).
This commit is contained in:
parent
84d37fda83
commit
963197d70c
@ -219,34 +219,32 @@ export class JsonRpcProvider extends BaseProvider {
|
|||||||
constructor(url?: ConnectionInfo | string, network?: Networkish) {
|
constructor(url?: ConnectionInfo | string, network?: Networkish) {
|
||||||
logger.checkNew(new.target, JsonRpcProvider);
|
logger.checkNew(new.target, JsonRpcProvider);
|
||||||
|
|
||||||
const getNetwork = getStatic<(network: Networkish) => Network>(new.target, "getNetwork");
|
let networkOrReady: Networkish | Promise<Network> = network;
|
||||||
|
|
||||||
// One parameter, but it is a network name, so swap it with the URL
|
// The network is unknown, query the JSON-RPC for it
|
||||||
if (typeof(url) === "string") {
|
if (networkOrReady == null) {
|
||||||
if (network === null) {
|
networkOrReady = new Promise((resolve, reject) => {
|
||||||
const checkNetwork = getNetwork(url);
|
setTimeout(() => {
|
||||||
network = checkNetwork;
|
this.detectNetwork().then((network) => {
|
||||||
url = null;
|
resolve(network);
|
||||||
}
|
}, (error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network) {
|
super(networkOrReady);
|
||||||
// The network has been specified explicitly, we can use it
|
|
||||||
super(network);
|
|
||||||
} else {
|
|
||||||
// The network is unknown, query the JSON-RPC for it
|
|
||||||
super(this.detectNetwork());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default URL
|
// Default URL
|
||||||
if (!url) { url = getStatic<() => string>(this.constructor, "defaultUrl")(); }
|
if (!url) { url = getStatic<() => string>(this.constructor, "defaultUrl")(); }
|
||||||
|
|
||||||
if (typeof(url) === "string") {
|
if (typeof(url) === "string") {
|
||||||
this.connection = Object.freeze({
|
defineReadOnly(this, "connection",Object.freeze({
|
||||||
url: url
|
url: url
|
||||||
});
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.connection = Object.freeze(shallowCopy(url));
|
defineReadOnly(this, "connection", Object.freeze(shallowCopy(url)));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._nextId = 42;
|
this._nextId = 42;
|
||||||
|
Loading…
Reference in New Issue
Block a user