Updated dist files.
This commit is contained in:
parent
fa6904fef3
commit
e96b43e84d
@ -2,14 +2,16 @@ Changelog
|
||||
=========
|
||||
|
||||
This change log is managed by `scripts/cmds/update-versions` but may be manually updated.
|
||||
|
||||
During the v5-BETA, although attempts are made to minimize it, some of the APIs
|
||||
may change. It is generally recommended that you remove your `node_modules/`,
|
||||
`package-lock.json` (and similar files for yarn, etc.) and doing an `npm install`
|
||||
after upgrading to a newer version of the v5-BETA.
|
||||
|
||||
ethers/v5.0.0-beta.185 (2020-05-03 17:38)
|
||||
ethers/v5.0.0-beta.185 (2020-05-03 21:09)
|
||||
-----------------------------------------
|
||||
|
||||
- Stall FallbackProvider backends from requests if not in-sync. ([fa6904f](https://github.com/ethers-io/ethers.js/commit/fa6904fef35e7ab888221f3a0613bfe7e6df3594))
|
||||
- Allow providers to detect their network after instantiation. ([#814](https://github.com/ethers-io/ethers.js/issues/814); [99ae946](https://github.com/ethers-io/ethers.js/commit/99ae946476a317a9d89e5d8f57cf37f8680bfa2b))
|
||||
- Better messaging on low-level network errors. ([#814](https://github.com/ethers-io/ethers.js/issues/814); [0e3a66c](https://github.com/ethers-io/ethers.js/commit/0e3a66c82959a08f3f4e4ffbca3ae3792ff2548f))
|
||||
- Manage FallbackProvider stalling without unref. ([#815](https://github.com/ethers-io/ethers.js/issues/815); [7b1a7c7](https://github.com/ethers-io/ethers.js/commit/7b1a7c7f31a3631e12c2a341b562983360e670e9))
|
||||
|
4
packages/ethers/dist/ethers-all.esm.min.js
vendored
4
packages/ethers/dist/ethers-all.esm.min.js
vendored
File diff suppressed because one or more lines are too long
4
packages/ethers/dist/ethers-all.umd.min.js
vendored
4
packages/ethers/dist/ethers-all.umd.min.js
vendored
File diff suppressed because one or more lines are too long
104
packages/ethers/dist/ethers.esm.js
vendored
104
packages/ethers/dist/ethers.esm.js
vendored
@ -18547,36 +18547,72 @@ function getProcessFunc(provider, method, params) {
|
||||
// satisfied and agreed upon for the final result.
|
||||
return normalizedTally(normalize, provider.quorum);
|
||||
}
|
||||
function getRunner(provider, method, params) {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
// If we are doing a blockTag query, we need to make sure the backend is
|
||||
// caught up to the FallbackProvider, before sending a request to it.
|
||||
function waitForSync(provider, blockNumber) {
|
||||
return __awaiter$b(this, void 0, void 0, function* () {
|
||||
if ((provider.blockNumber != null && provider.blockNumber >= blockNumber) || blockNumber === -1) {
|
||||
return provider;
|
||||
}
|
||||
return poll(() => {
|
||||
return provider.getBlockNumber().then((b) => {
|
||||
if (b >= blockNumber) {
|
||||
return Provider;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}, { onceBlock: provider });
|
||||
});
|
||||
}
|
||||
function getRunner(provider, currentBlockNumber, method, params) {
|
||||
return __awaiter$b(this, void 0, void 0, function* () {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs": {
|
||||
let filter = params.filter;
|
||||
if ((filter.fromBlock && isHexString(filter.fromBlock)) || (filter.toBlock && isHexString(filter.toBlock))) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider.getLogs(filter);
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs":
|
||||
return provider.getLogs(params.filter);
|
||||
}
|
||||
return logger$x.throwError("unknown method error", Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
}
|
||||
return logger$x.throwError("unknown method error", Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
});
|
||||
});
|
||||
}
|
||||
class FallbackProvider extends BaseProvider {
|
||||
@ -18652,17 +18688,21 @@ class FallbackProvider extends BaseProvider {
|
||||
// They were all an error; pick the first error
|
||||
throw results[0];
|
||||
}
|
||||
// We need to make sure we are in sync with our backends, so we need
|
||||
// to know this before we can make a lot of calls
|
||||
if (this._highestBlockNumber === -1 && method !== "getBlockNumber") {
|
||||
yield this.getBlockNumber();
|
||||
}
|
||||
const processFunc = getProcessFunc(this, method, params);
|
||||
// Shuffle the providers and then sort them by their priority; we
|
||||
// shallowCopy them since we will store the result in them too
|
||||
const configs = shuffled(this.providerConfigs.map(shallowCopy));
|
||||
configs.sort((a, b) => (a.priority - b.priority));
|
||||
const currentBlockNumber = this._highestBlockNumber;
|
||||
let i = 0;
|
||||
let first = true;
|
||||
while (true) {
|
||||
const t0 = now();
|
||||
// Get a list of running
|
||||
//const running = configs.filter((c) => (c.runner && !c.done));
|
||||
// Compute the inflight weight (exclude anything past)
|
||||
let inflightWeight = configs.filter((c) => (c.runner && ((t0 - c.start) < c.stallTimeout)))
|
||||
.reduce((accum, c) => (accum + c.weight), 0);
|
||||
@ -18673,7 +18713,7 @@ class FallbackProvider extends BaseProvider {
|
||||
config.start = now();
|
||||
config.staller = stall(config.stallTimeout);
|
||||
config.staller.wait(() => { config.staller = null; });
|
||||
config.runner = getRunner(config.provider, method, params).then((result) => {
|
||||
config.runner = getRunner((config.provider), currentBlockNumber, method, params).then((result) => {
|
||||
config.done = true;
|
||||
config.result = result;
|
||||
if (this.listenerCount("debug")) {
|
||||
|
4
packages/ethers/dist/ethers.esm.min.js
vendored
4
packages/ethers/dist/ethers.esm.min.js
vendored
File diff suppressed because one or more lines are too long
148
packages/ethers/dist/ethers.umd.js
vendored
148
packages/ethers/dist/ethers.umd.js
vendored
@ -20885,8 +20885,10 @@
|
||||
|
||||
|
||||
|
||||
var logger = new lib.Logger(_version$I.version);
|
||||
|
||||
|
||||
|
||||
var logger = new lib.Logger(_version$I.version);
|
||||
function now() { return (new Date()).getTime(); }
|
||||
// Returns to network as long as all agree, or null if any is null.
|
||||
// Throws an error if any two networks do not match.
|
||||
@ -21122,36 +21124,97 @@
|
||||
// satisfied and agreed upon for the final result.
|
||||
return normalizedTally(normalize, provider.quorum);
|
||||
}
|
||||
function getRunner(provider, method, params) {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
// If we are doing a blockTag query, we need to make sure the backend is
|
||||
// caught up to the FallbackProvider, before sending a request to it.
|
||||
function waitForSync(provider, blockNumber) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
if ((provider.blockNumber != null && provider.blockNumber >= blockNumber) || blockNumber === -1) {
|
||||
return [2 /*return*/, provider];
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs":
|
||||
return provider.getLogs(params.filter);
|
||||
}
|
||||
return logger.throwError("unknown method error", lib.Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
return [2 /*return*/, lib$l.poll(function () {
|
||||
return provider.getBlockNumber().then(function (b) {
|
||||
if (b >= blockNumber) {
|
||||
return lib$b.Provider;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}, { onceBlock: provider })];
|
||||
});
|
||||
});
|
||||
}
|
||||
function getRunner(provider, currentBlockNumber, method, params) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _a, filter;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_a = method;
|
||||
switch (_a) {
|
||||
case "getBlockNumber": return [3 /*break*/, 1];
|
||||
case "getGasPrice": return [3 /*break*/, 1];
|
||||
case "getEtherPrice": return [3 /*break*/, 2];
|
||||
case "getBalance": return [3 /*break*/, 3];
|
||||
case "getTransactionCount": return [3 /*break*/, 3];
|
||||
case "getCode": return [3 /*break*/, 3];
|
||||
case "getStorageAt": return [3 /*break*/, 6];
|
||||
case "getBlock": return [3 /*break*/, 9];
|
||||
case "call": return [3 /*break*/, 12];
|
||||
case "estimateGas": return [3 /*break*/, 12];
|
||||
case "getTransaction": return [3 /*break*/, 15];
|
||||
case "getTransactionReceipt": return [3 /*break*/, 15];
|
||||
case "getLogs": return [3 /*break*/, 16];
|
||||
}
|
||||
return [3 /*break*/, 19];
|
||||
case 1: return [2 /*return*/, provider[method]()];
|
||||
case 2:
|
||||
if (provider.getEtherPrice) {
|
||||
return [2 /*return*/, provider.getEtherPrice()];
|
||||
}
|
||||
return [3 /*break*/, 19];
|
||||
case 3:
|
||||
if (!(params.blockTag && lib$1.isHexString(params.blockTag))) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 4:
|
||||
provider = _b.sent();
|
||||
_b.label = 5;
|
||||
case 5: return [2 /*return*/, provider[method](params.address, params.blockTag || "latest")];
|
||||
case 6:
|
||||
if (!(params.blockTag && lib$1.isHexString(params.blockTag))) return [3 /*break*/, 8];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 7:
|
||||
provider = _b.sent();
|
||||
_b.label = 8;
|
||||
case 8: return [2 /*return*/, provider.getStorageAt(params.address, params.position, params.blockTag || "latest")];
|
||||
case 9:
|
||||
if (!(params.blockTag && lib$1.isHexString(params.blockTag))) return [3 /*break*/, 11];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 10:
|
||||
provider = _b.sent();
|
||||
_b.label = 11;
|
||||
case 11: return [2 /*return*/, provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash)];
|
||||
case 12:
|
||||
if (!(params.blockTag && lib$1.isHexString(params.blockTag))) return [3 /*break*/, 14];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 13:
|
||||
provider = _b.sent();
|
||||
_b.label = 14;
|
||||
case 14: return [2 /*return*/, provider[method](params.transaction)];
|
||||
case 15: return [2 /*return*/, provider[method](params.transactionHash)];
|
||||
case 16:
|
||||
filter = params.filter;
|
||||
if (!((filter.fromBlock && lib$1.isHexString(filter.fromBlock)) || (filter.toBlock && lib$1.isHexString(filter.toBlock)))) return [3 /*break*/, 18];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 17:
|
||||
provider = _b.sent();
|
||||
_b.label = 18;
|
||||
case 18: return [2 /*return*/, provider.getLogs(filter)];
|
||||
case 19: return [2 /*return*/, logger.throwError("unknown method error", lib.Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
})];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
var FallbackProvider = /** @class */ (function (_super) {
|
||||
@ -21219,7 +21282,7 @@
|
||||
};
|
||||
FallbackProvider.prototype.perform = function (method, params) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var results, i_1, result, processFunc, configs, i, first, _loop_1, this_1, state_1;
|
||||
var results, i_1, result, processFunc, configs, currentBlockNumber, i, first, _loop_1, this_1, state_1;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
@ -21244,9 +21307,16 @@
|
||||
// They were all an error; pick the first error
|
||||
throw results[0];
|
||||
case 2:
|
||||
if (!(this._highestBlockNumber === -1 && method !== "getBlockNumber")) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, this.getBlockNumber()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
_a.label = 4;
|
||||
case 4:
|
||||
processFunc = getProcessFunc(this, method, params);
|
||||
configs = browser$6.shuffled(this.providerConfigs.map(lib$3.shallowCopy));
|
||||
configs.sort(function (a, b) { return (a.priority - b.priority); });
|
||||
currentBlockNumber = this._highestBlockNumber;
|
||||
i = 0;
|
||||
first = true;
|
||||
_loop_1 = function () {
|
||||
@ -21263,7 +21333,7 @@
|
||||
config.start = now();
|
||||
config.staller = stall(config.stallTimeout);
|
||||
config.staller.wait(function () { config.staller = null; });
|
||||
config.runner = getRunner(config.provider, method, params).then(function (result) {
|
||||
config.runner = getRunner((config.provider), currentBlockNumber, method, params).then(function (result) {
|
||||
config.done = true;
|
||||
config.result = result;
|
||||
if (_this.listenerCount("debug")) {
|
||||
@ -21345,18 +21415,18 @@
|
||||
});
|
||||
};
|
||||
this_1 = this;
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
if (!true) return [3 /*break*/, 5];
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
if (!true) return [3 /*break*/, 7];
|
||||
return [5 /*yield**/, _loop_1()];
|
||||
case 4:
|
||||
case 6:
|
||||
state_1 = _a.sent();
|
||||
if (typeof state_1 === "object")
|
||||
return [2 /*return*/, state_1.value];
|
||||
if (state_1 === "break")
|
||||
return [3 /*break*/, 5];
|
||||
return [3 /*break*/, 3];
|
||||
case 5:
|
||||
return [3 /*break*/, 7];
|
||||
return [3 /*break*/, 5];
|
||||
case 7:
|
||||
// Shut down any stallers; shouldn't be any
|
||||
configs.filter(function (c) { return c.staller; }).forEach(function (c) { return c.staller.cancel(); });
|
||||
return [2 /*return*/, logger.throwError("failed to meet quorum", lib.Logger.errors.SERVER_ERROR, {
|
||||
|
4
packages/ethers/dist/ethers.umd.min.js
vendored
4
packages/ethers/dist/ethers.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -52,7 +52,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0x1c30ae49addbeee1a530704a69d38cd067932db413c4643b38409be32c7c04e1",
|
||||
"tarballHash": "0xee6633babeaf42a27299a2d3d14780efecf6fbe4cee7681493f807d71055d759",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.0-beta.185"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Network } from "@ethersproject/networks";
|
||||
import { Provider } from "@ethersproject/abstract-provider";
|
||||
import { Network } from "@ethersproject/networks";
|
||||
import { BaseProvider } from "./base-provider";
|
||||
export interface FallbackProviderConfig {
|
||||
provider: Provider;
|
||||
|
@ -9,13 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
import { Provider } from "@ethersproject/abstract-provider";
|
||||
import { shuffled } from "@ethersproject/random";
|
||||
import { deepCopy, defineReadOnly, shallowCopy } from "@ethersproject/properties";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { isHexString } from "@ethersproject/bytes";
|
||||
import { deepCopy, defineReadOnly, shallowCopy } from "@ethersproject/properties";
|
||||
import { shuffled } from "@ethersproject/random";
|
||||
import { poll } from "@ethersproject/web";
|
||||
import { BaseProvider } from "./base-provider";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
import { BaseProvider } from "./base-provider";
|
||||
function now() { return (new Date()).getTime(); }
|
||||
// Returns to network as long as all agree, or null if any is null.
|
||||
// Throws an error if any two networks do not match.
|
||||
@ -251,36 +253,72 @@ function getProcessFunc(provider, method, params) {
|
||||
// satisfied and agreed upon for the final result.
|
||||
return normalizedTally(normalize, provider.quorum);
|
||||
}
|
||||
function getRunner(provider, method, params) {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
// If we are doing a blockTag query, we need to make sure the backend is
|
||||
// caught up to the FallbackProvider, before sending a request to it.
|
||||
function waitForSync(provider, blockNumber) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if ((provider.blockNumber != null && provider.blockNumber >= blockNumber) || blockNumber === -1) {
|
||||
return provider;
|
||||
}
|
||||
return poll(() => {
|
||||
return provider.getBlockNumber().then((b) => {
|
||||
if (b >= blockNumber) {
|
||||
return Provider;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}, { onceBlock: provider });
|
||||
});
|
||||
}
|
||||
function getRunner(provider, currentBlockNumber, method, params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
if (params.blockTag && isHexString(params.blockTag)) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs": {
|
||||
let filter = params.filter;
|
||||
if ((filter.fromBlock && isHexString(filter.fromBlock)) || (filter.toBlock && isHexString(filter.toBlock))) {
|
||||
provider = yield waitForSync(provider, currentBlockNumber);
|
||||
}
|
||||
return provider.getLogs(filter);
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs":
|
||||
return provider.getLogs(params.filter);
|
||||
}
|
||||
return logger.throwError("unknown method error", Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
}
|
||||
return logger.throwError("unknown method error", Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
});
|
||||
});
|
||||
}
|
||||
export class FallbackProvider extends BaseProvider {
|
||||
@ -356,17 +394,21 @@ export class FallbackProvider extends BaseProvider {
|
||||
// They were all an error; pick the first error
|
||||
throw results[0];
|
||||
}
|
||||
// We need to make sure we are in sync with our backends, so we need
|
||||
// to know this before we can make a lot of calls
|
||||
if (this._highestBlockNumber === -1 && method !== "getBlockNumber") {
|
||||
yield this.getBlockNumber();
|
||||
}
|
||||
const processFunc = getProcessFunc(this, method, params);
|
||||
// Shuffle the providers and then sort them by their priority; we
|
||||
// shallowCopy them since we will store the result in them too
|
||||
const configs = shuffled(this.providerConfigs.map(shallowCopy));
|
||||
configs.sort((a, b) => (a.priority - b.priority));
|
||||
const currentBlockNumber = this._highestBlockNumber;
|
||||
let i = 0;
|
||||
let first = true;
|
||||
while (true) {
|
||||
const t0 = now();
|
||||
// Get a list of running
|
||||
//const running = configs.filter((c) => (c.runner && !c.done));
|
||||
// Compute the inflight weight (exclude anything past)
|
||||
let inflightWeight = configs.filter((c) => (c.runner && ((t0 - c.start) < c.stallTimeout)))
|
||||
.reduce((accum, c) => (accum + c.weight), 0);
|
||||
@ -377,7 +419,7 @@ export class FallbackProvider extends BaseProvider {
|
||||
config.start = now();
|
||||
config.staller = stall(config.stallTimeout);
|
||||
config.staller.wait(() => { config.staller = null; });
|
||||
config.runner = getRunner(config.provider, method, params).then((result) => {
|
||||
config.runner = getRunner((config.provider), currentBlockNumber, method, params).then((result) => {
|
||||
config.done = true;
|
||||
config.result = result;
|
||||
if (this.listenerCount("debug")) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Network } from "@ethersproject/networks";
|
||||
import { Provider } from "@ethersproject/abstract-provider";
|
||||
import { Network } from "@ethersproject/networks";
|
||||
import { BaseProvider } from "./base-provider";
|
||||
export interface FallbackProviderConfig {
|
||||
provider: Provider;
|
||||
|
@ -50,13 +50,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var abstract_provider_1 = require("@ethersproject/abstract-provider");
|
||||
var random_1 = require("@ethersproject/random");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var random_1 = require("@ethersproject/random");
|
||||
var web_1 = require("@ethersproject/web");
|
||||
var base_provider_1 = require("./base-provider");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var base_provider_1 = require("./base-provider");
|
||||
function now() { return (new Date()).getTime(); }
|
||||
// Returns to network as long as all agree, or null if any is null.
|
||||
// Throws an error if any two networks do not match.
|
||||
@ -292,36 +294,97 @@ function getProcessFunc(provider, method, params) {
|
||||
// satisfied and agreed upon for the final result.
|
||||
return normalizedTally(normalize, provider.quorum);
|
||||
}
|
||||
function getRunner(provider, method, params) {
|
||||
switch (method) {
|
||||
case "getBlockNumber":
|
||||
case "getGasPrice":
|
||||
return provider[method]();
|
||||
case "getEtherPrice":
|
||||
if (provider.getEtherPrice) {
|
||||
return provider.getEtherPrice();
|
||||
// If we are doing a blockTag query, we need to make sure the backend is
|
||||
// caught up to the FallbackProvider, before sending a request to it.
|
||||
function waitForSync(provider, blockNumber) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
if ((provider.blockNumber != null && provider.blockNumber >= blockNumber) || blockNumber === -1) {
|
||||
return [2 /*return*/, provider];
|
||||
}
|
||||
break;
|
||||
case "getBalance":
|
||||
case "getTransactionCount":
|
||||
case "getCode":
|
||||
return provider[method](params.address, params.blockTag || "latest");
|
||||
case "getStorageAt":
|
||||
return provider.getStorageAt(params.address, params.position, params.blockTag || "latest");
|
||||
case "getBlock":
|
||||
return provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash);
|
||||
case "call":
|
||||
case "estimateGas":
|
||||
return provider[method](params.transaction);
|
||||
case "getTransaction":
|
||||
case "getTransactionReceipt":
|
||||
return provider[method](params.transactionHash);
|
||||
case "getLogs":
|
||||
return provider.getLogs(params.filter);
|
||||
}
|
||||
return logger.throwError("unknown method error", logger_1.Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
return [2 /*return*/, web_1.poll(function () {
|
||||
return provider.getBlockNumber().then(function (b) {
|
||||
if (b >= blockNumber) {
|
||||
return abstract_provider_1.Provider;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}, { onceBlock: provider })];
|
||||
});
|
||||
});
|
||||
}
|
||||
function getRunner(provider, currentBlockNumber, method, params) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _a, filter;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_a = method;
|
||||
switch (_a) {
|
||||
case "getBlockNumber": return [3 /*break*/, 1];
|
||||
case "getGasPrice": return [3 /*break*/, 1];
|
||||
case "getEtherPrice": return [3 /*break*/, 2];
|
||||
case "getBalance": return [3 /*break*/, 3];
|
||||
case "getTransactionCount": return [3 /*break*/, 3];
|
||||
case "getCode": return [3 /*break*/, 3];
|
||||
case "getStorageAt": return [3 /*break*/, 6];
|
||||
case "getBlock": return [3 /*break*/, 9];
|
||||
case "call": return [3 /*break*/, 12];
|
||||
case "estimateGas": return [3 /*break*/, 12];
|
||||
case "getTransaction": return [3 /*break*/, 15];
|
||||
case "getTransactionReceipt": return [3 /*break*/, 15];
|
||||
case "getLogs": return [3 /*break*/, 16];
|
||||
}
|
||||
return [3 /*break*/, 19];
|
||||
case 1: return [2 /*return*/, provider[method]()];
|
||||
case 2:
|
||||
if (provider.getEtherPrice) {
|
||||
return [2 /*return*/, provider.getEtherPrice()];
|
||||
}
|
||||
return [3 /*break*/, 19];
|
||||
case 3:
|
||||
if (!(params.blockTag && bytes_1.isHexString(params.blockTag))) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 4:
|
||||
provider = _b.sent();
|
||||
_b.label = 5;
|
||||
case 5: return [2 /*return*/, provider[method](params.address, params.blockTag || "latest")];
|
||||
case 6:
|
||||
if (!(params.blockTag && bytes_1.isHexString(params.blockTag))) return [3 /*break*/, 8];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 7:
|
||||
provider = _b.sent();
|
||||
_b.label = 8;
|
||||
case 8: return [2 /*return*/, provider.getStorageAt(params.address, params.position, params.blockTag || "latest")];
|
||||
case 9:
|
||||
if (!(params.blockTag && bytes_1.isHexString(params.blockTag))) return [3 /*break*/, 11];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 10:
|
||||
provider = _b.sent();
|
||||
_b.label = 11;
|
||||
case 11: return [2 /*return*/, provider[(params.includeTransactions ? "getBlockWithTransactions" : "getBlock")](params.blockTag || params.blockHash)];
|
||||
case 12:
|
||||
if (!(params.blockTag && bytes_1.isHexString(params.blockTag))) return [3 /*break*/, 14];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 13:
|
||||
provider = _b.sent();
|
||||
_b.label = 14;
|
||||
case 14: return [2 /*return*/, provider[method](params.transaction)];
|
||||
case 15: return [2 /*return*/, provider[method](params.transactionHash)];
|
||||
case 16:
|
||||
filter = params.filter;
|
||||
if (!((filter.fromBlock && bytes_1.isHexString(filter.fromBlock)) || (filter.toBlock && bytes_1.isHexString(filter.toBlock)))) return [3 /*break*/, 18];
|
||||
return [4 /*yield*/, waitForSync(provider, currentBlockNumber)];
|
||||
case 17:
|
||||
provider = _b.sent();
|
||||
_b.label = 18;
|
||||
case 18: return [2 /*return*/, provider.getLogs(filter)];
|
||||
case 19: return [2 /*return*/, logger.throwError("unknown method error", logger_1.Logger.errors.UNKNOWN_ERROR, {
|
||||
method: method,
|
||||
params: params
|
||||
})];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
var FallbackProvider = /** @class */ (function (_super) {
|
||||
@ -389,7 +452,7 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
};
|
||||
FallbackProvider.prototype.perform = function (method, params) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var results, i_1, result, processFunc, configs, i, first, _loop_1, this_1, state_1;
|
||||
var results, i_1, result, processFunc, configs, currentBlockNumber, i, first, _loop_1, this_1, state_1;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
@ -414,9 +477,16 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
// They were all an error; pick the first error
|
||||
throw results[0];
|
||||
case 2:
|
||||
if (!(this._highestBlockNumber === -1 && method !== "getBlockNumber")) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, this.getBlockNumber()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
_a.label = 4;
|
||||
case 4:
|
||||
processFunc = getProcessFunc(this, method, params);
|
||||
configs = random_1.shuffled(this.providerConfigs.map(properties_1.shallowCopy));
|
||||
configs.sort(function (a, b) { return (a.priority - b.priority); });
|
||||
currentBlockNumber = this._highestBlockNumber;
|
||||
i = 0;
|
||||
first = true;
|
||||
_loop_1 = function () {
|
||||
@ -433,7 +503,7 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
config.start = now();
|
||||
config.staller = stall(config.stallTimeout);
|
||||
config.staller.wait(function () { config.staller = null; });
|
||||
config.runner = getRunner(config.provider, method, params).then(function (result) {
|
||||
config.runner = getRunner((config.provider), currentBlockNumber, method, params).then(function (result) {
|
||||
config.done = true;
|
||||
config.result = result;
|
||||
if (_this.listenerCount("debug")) {
|
||||
@ -515,18 +585,18 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
});
|
||||
};
|
||||
this_1 = this;
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
if (!true) return [3 /*break*/, 5];
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
if (!true) return [3 /*break*/, 7];
|
||||
return [5 /*yield**/, _loop_1()];
|
||||
case 4:
|
||||
case 6:
|
||||
state_1 = _a.sent();
|
||||
if (typeof state_1 === "object")
|
||||
return [2 /*return*/, state_1.value];
|
||||
if (state_1 === "break")
|
||||
return [3 /*break*/, 5];
|
||||
return [3 /*break*/, 3];
|
||||
case 5:
|
||||
return [3 /*break*/, 7];
|
||||
return [3 /*break*/, 5];
|
||||
case 7:
|
||||
// Shut down any stallers; shouldn't be any
|
||||
configs.filter(function (c) { return c.staller; }).forEach(function (c) { return c.staller.cancel(); });
|
||||
return [2 /*return*/, logger.throwError("failed to meet quorum", logger_1.Logger.errors.SERVER_ERROR, {
|
||||
|
@ -56,7 +56,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0xa23d77e6439556382bb60e82fc8ec1a3ba9504d90c381815ec813496cd497daa",
|
||||
"tarballHash": "0x8af51f5043e8b3d30f54fbe3b0b010949bb211324d6eaef0f89354cacf9de4b5",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.0-beta.165"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user