Update dist files.

This commit is contained in:
Richard Moore 2020-05-03 17:53:58 -04:00
parent 99ae946476
commit 3f37d15b88
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
56 changed files with 1694 additions and 1067 deletions

View File

@ -7,9 +7,15 @@ 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` `package-lock.json` (and similar files for yarn, etc.) and doing an `npm install`
after upgrading to a newer version of the v5-BETA. after upgrading to a newer version of the v5-BETA.
ethers/v5.0.0-beta.185 (2020-05-01 16:45) ethers/v5.0.0-beta.185 (2020-05-03 17:38)
----------------------------------------- -----------------------------------------
- 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))
- Only error on duplicate signatures in Contract ABI. ([#499](https://github.com/ethers-io/ethers.js/issues/499); [098d7ef](https://github.com/ethers-io/ethers.js/commit/098d7efb21bd648c2660342297d2419904a10925))
- Added getWebSocketProvider static method to InfuraProvider. ([a6c1174](https://github.com/ethers-io/ethers.js/commit/a6c1174dffe6dca1a3a64d1d472cec6e12372117))
- Fix WebSocketProvider responses when message result is null. ([#813](https://github.com/ethers-io/ethers.js/issues/813); [472e5b0](https://github.com/ethers-io/ethers.js/commit/472e5b07eab180baa12185c8f00e5079ce4c671f))
- Allow modifiers on Human-Readable ABI for tuples and arrays. ([83fba3d](https://github.com/ethers-io/ethers.js/commit/83fba3de25b524cc48975b1952f4319d63874205)) - Allow modifiers on Human-Readable ABI for tuples and arrays. ([83fba3d](https://github.com/ethers-io/ethers.js/commit/83fba3de25b524cc48975b1952f4319d63874205))
- Added initial renew support to ENS CLI. ([54dfb75](https://github.com/ethers-io/ethers.js/commit/54dfb757c4c88e4bcada1890c4016fadfb25581a)) - Added initial renew support to ENS CLI. ([54dfb75](https://github.com/ethers-io/ethers.js/commit/54dfb757c4c88e4bcada1890c4016fadfb25581a))
- Allow contract filters to include OR-ed values. ([#437](https://github.com/ethers-io/ethers.js/issues/437); [28800d7](https://github.com/ethers-io/ethers.js/commit/28800d7681f3bab08f6d30a22f0813e04feee18a)) - Allow contract filters to include OR-ed values. ([#437](https://github.com/ethers-io/ethers.js/issues/437); [28800d7](https://github.com/ethers-io/ethers.js/commit/28800d7681f3bab08f6d30a22f0813e04feee18a))

View File

@ -12,7 +12,7 @@ const Words = fs.readFileSync("/usr/share/dict/words").toString().split("\n").re
// Words missing from the dictionary // Words missing from the dictionary
accessing addresses aligned autofill called cancelled censored accessing addresses aligned autofill called cancelled censored
compiled computed configured consumed creating decoded decoding compiled computed configured consumed creating decoded decoding
decrypt decrypted decrypting deployed deploying deprecated decrypt decrypted decrypting deployed deploying deprecated detected
discontinued earliest email enabled encoded encoding encrypt discontinued earliest email enabled encoded encoding encrypt
encrypted encrypting entries euro exceeded existing expected encrypted encrypting entries euro exceeded existing expected
expired failed fetches formatted formatting funding generated expired failed fetches formatted formatting funding generated
@ -44,13 +44,13 @@ ABIEncoder testcase numberish Wordlist
// Common Code Strings // Common Code Strings
abi addr api app arg arrayify asm basex bigint bn byte bytecode abi addr api app arg arrayify asm basex bigint bn byte bytecode
callback calldata checksum ciphertext cli codepoint config callback calldata checksum ciphertext cli codepoint config
contenthash ctr ctrl debug dklen eexist encseed eof ethaddr contenthash ctr ctrl debug dd dklen eexist encseed eof ethaddr
ethseed ethers eval exec filename func gz hid http https hw iv ethseed ethers eval exec filename func gz hid http https hw iv
info init ipc json kdf kdfparams labelhash lang lib multihash nfc info init ipc json kdf kdfparams labelhash lang lib mm multihash nfc
nfkc nfd nfkd nodehash oob opcode pbkdf pc plugin pragma pre prf nfkc nfd nfkd nodehash oob opcode pbkdf pc plugin pragma pre prf
repl rpc sighash topichash solc stdin stdout subclasses subnode repl rpc sighash topichash solc stdin stdout subclasses subnode
timeout todo txt ufixed utc utf util url uuid vm vs websocket timeout todo txt ufixed utc utf util url uuid vm vs websocket
wikipedia wx xe zlib wikipedia wx xe yyyy zlib
// AbiV2 // AbiV2
abiv abiv

View File

@ -31,7 +31,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"tarballHash": "0x7fd77ad0e6f0df98c7f7b5f91552b5c5ce359a2fbd05a9ab852bec00530a7712", "tarballHash": "0x7f866470aabd8bbe47af1ff527fedbd86445cbfcd3bbf340d34c96b38b8e8606",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.153" "version": "5.0.0-beta.153"
} }

View File

@ -1 +1 @@
export declare const version = "contracts/5.0.0-beta.150"; export declare const version = "contracts/5.0.0-beta.151";

View File

@ -1 +1 @@
export const version = "contracts/5.0.0-beta.150"; export const version = "contracts/5.0.0-beta.151";

View File

@ -389,44 +389,66 @@ export class Contract {
logger.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName); logger.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName);
} }
} }
const uniqueFunctions = {}; const uniqueNames = {};
Object.keys(this.interface.functions).forEach((name) => { const uniqueSignatures = {};
const fragment = this.interface.functions[name]; Object.keys(this.interface.functions).forEach((signature) => {
// @TODO: This should take in fragment const fragment = this.interface.functions[signature];
const run = runMethod(this, name, {}); // Check that the signature is unique; if not the ABI generation has
if (this[name] == null) { // not been cleaned or may be incorrectly generated
defineReadOnly(this, name, run); if (uniqueSignatures[signature]) {
} logger.warn(`Duplicate ABI entry for ${JSON.stringify(name)}`);
if (this.functions[name] == null) {
defineReadOnly(this.functions, name, run);
}
if (this.callStatic[name] == null) {
defineReadOnly(this.callStatic, name, runMethod(this, name, { callStatic: true }));
}
if (this.populateTransaction[name] == null) {
defineReadOnly(this.populateTransaction, name, runMethod(this, name, { transaction: true }));
}
if (this.estimateGas[name] == null) {
defineReadOnly(this.estimateGas, name, runMethod(this, name, { estimate: true }));
}
if (!uniqueFunctions[fragment.name]) {
uniqueFunctions[fragment.name] = [];
}
uniqueFunctions[fragment.name].push(name);
});
Object.keys(uniqueFunctions).forEach((name) => {
const signatures = uniqueFunctions[name];
if (signatures.length > 1) {
logger.warn(`Duplicate definition of ${name} (${signatures.join(", ")})`);
return; return;
} }
if (this[name] == null) { uniqueSignatures[signature] = true;
defineReadOnly(this, name, this[signatures[0]]); // Track unique names; we only expose bare named functions if they
// are ambiguous
{
const name = fragment.name;
if (!uniqueNames[name]) {
uniqueNames[name] = [];
}
uniqueNames[name].push(signature);
}
// @TODO: This should take in fragment
const run = runMethod(this, signature, {});
if (this[signature] == null) {
defineReadOnly(this, signature, run);
}
if (this.functions[signature] == null) {
defineReadOnly(this.functions, signature, run);
}
if (this.callStatic[signature] == null) {
defineReadOnly(this.callStatic, signature, runMethod(this, signature, { callStatic: true }));
}
if (this.populateTransaction[signature] == null) {
defineReadOnly(this.populateTransaction, signature, runMethod(this, signature, { transaction: true }));
}
if (this.estimateGas[signature] == null) {
defineReadOnly(this.estimateGas, signature, runMethod(this, signature, { estimate: true }));
}
});
Object.keys(uniqueNames).forEach((name) => {
// Ambiguous names to not get attached as bare names
const signatures = uniqueNames[name];
if (signatures.length > 1) {
return;
}
const signature = signatures[0];
if (this[name] == null) {
defineReadOnly(this, name, this[signature]);
}
if (this.functions[name] == null) {
defineReadOnly(this.functions, name, this.functions[signature]);
}
if (this.callStatic[name] == null) {
defineReadOnly(this.callStatic, name, this.callStatic[signature]);
}
if (this.populateTransaction[name] == null) {
defineReadOnly(this.populateTransaction, name, this.populateTransaction[signature]);
}
if (this.estimateGas[name] == null) {
defineReadOnly(this.estimateGas, name, this.estimateGas[signature]);
} }
defineReadOnly(this.functions, name, this.functions[signatures[0]]);
defineReadOnly(this.callStatic, name, this.callStatic[signatures[0]]);
defineReadOnly(this.populateTransaction, name, this.populateTransaction[signatures[0]]);
defineReadOnly(this.estimateGas, name, this.estimateGas[signatures[0]]);
}); });
} }
static getContractAddress(transaction) { static getContractAddress(transaction) {

View File

@ -1 +1 @@
export declare const version = "contracts/5.0.0-beta.150"; export declare const version = "contracts/5.0.0-beta.151";

View File

@ -1,3 +1,3 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "contracts/5.0.0-beta.150"; exports.version = "contracts/5.0.0-beta.151";

View File

@ -461,44 +461,66 @@ var Contract = /** @class */ (function () {
logger.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName); logger.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName);
} }
} }
var uniqueFunctions = {}; var uniqueNames = {};
Object.keys(this.interface.functions).forEach(function (name) { var uniqueSignatures = {};
var fragment = _this.interface.functions[name]; Object.keys(this.interface.functions).forEach(function (signature) {
// @TODO: This should take in fragment var fragment = _this.interface.functions[signature];
var run = runMethod(_this, name, {}); // Check that the signature is unique; if not the ABI generation has
if (_this[name] == null) { // not been cleaned or may be incorrectly generated
properties_1.defineReadOnly(_this, name, run); if (uniqueSignatures[signature]) {
} logger.warn("Duplicate ABI entry for " + JSON.stringify(name));
if (_this.functions[name] == null) {
properties_1.defineReadOnly(_this.functions, name, run);
}
if (_this.callStatic[name] == null) {
properties_1.defineReadOnly(_this.callStatic, name, runMethod(_this, name, { callStatic: true }));
}
if (_this.populateTransaction[name] == null) {
properties_1.defineReadOnly(_this.populateTransaction, name, runMethod(_this, name, { transaction: true }));
}
if (_this.estimateGas[name] == null) {
properties_1.defineReadOnly(_this.estimateGas, name, runMethod(_this, name, { estimate: true }));
}
if (!uniqueFunctions[fragment.name]) {
uniqueFunctions[fragment.name] = [];
}
uniqueFunctions[fragment.name].push(name);
});
Object.keys(uniqueFunctions).forEach(function (name) {
var signatures = uniqueFunctions[name];
if (signatures.length > 1) {
logger.warn("Duplicate definition of " + name + " (" + signatures.join(", ") + ")");
return; return;
} }
if (_this[name] == null) { uniqueSignatures[signature] = true;
properties_1.defineReadOnly(_this, name, _this[signatures[0]]); // Track unique names; we only expose bare named functions if they
// are ambiguous
{
var name_1 = fragment.name;
if (!uniqueNames[name_1]) {
uniqueNames[name_1] = [];
}
uniqueNames[name_1].push(signature);
}
// @TODO: This should take in fragment
var run = runMethod(_this, signature, {});
if (_this[signature] == null) {
properties_1.defineReadOnly(_this, signature, run);
}
if (_this.functions[signature] == null) {
properties_1.defineReadOnly(_this.functions, signature, run);
}
if (_this.callStatic[signature] == null) {
properties_1.defineReadOnly(_this.callStatic, signature, runMethod(_this, signature, { callStatic: true }));
}
if (_this.populateTransaction[signature] == null) {
properties_1.defineReadOnly(_this.populateTransaction, signature, runMethod(_this, signature, { transaction: true }));
}
if (_this.estimateGas[signature] == null) {
properties_1.defineReadOnly(_this.estimateGas, signature, runMethod(_this, signature, { estimate: true }));
}
});
Object.keys(uniqueNames).forEach(function (name) {
// Ambiguous names to not get attached as bare names
var signatures = uniqueNames[name];
if (signatures.length > 1) {
return;
}
var signature = signatures[0];
if (_this[name] == null) {
properties_1.defineReadOnly(_this, name, _this[signature]);
}
if (_this.functions[name] == null) {
properties_1.defineReadOnly(_this.functions, name, _this.functions[signature]);
}
if (_this.callStatic[name] == null) {
properties_1.defineReadOnly(_this.callStatic, name, _this.callStatic[signature]);
}
if (_this.populateTransaction[name] == null) {
properties_1.defineReadOnly(_this.populateTransaction, name, _this.populateTransaction[signature]);
}
if (_this.estimateGas[name] == null) {
properties_1.defineReadOnly(_this.estimateGas, name, _this.estimateGas[signature]);
} }
properties_1.defineReadOnly(_this.functions, name, _this.functions[signatures[0]]);
properties_1.defineReadOnly(_this.callStatic, name, _this.callStatic[signatures[0]]);
properties_1.defineReadOnly(_this.populateTransaction, name, _this.populateTransaction[signatures[0]]);
properties_1.defineReadOnly(_this.estimateGas, name, _this.estimateGas[signatures[0]]);
}); });
} }
Contract.getContractAddress = function (transaction) { Contract.getContractAddress = function (transaction) {

View File

@ -32,7 +32,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"tarballHash": "0x5030e873ef0ebc78913b3a1344a86cd92873b60418a342048ad165f751c342e5", "tarballHash": "0x918c40fdb8ee8be8cc4d0094b6b936fb8a35203af97b33f227fb80d30b337f5e",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.150" "version": "5.0.0-beta.151"
} }

View File

@ -1 +1 @@
export const version = "contracts/5.0.0-beta.150"; export const version = "contracts/5.0.0-beta.151";

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8162,7 +8162,7 @@ class VoidSigner extends Signer {
} }
} }
const version$b = "contracts/5.0.0-beta.150"; const version$b = "contracts/5.0.0-beta.151";
"use strict"; "use strict";
var __awaiter$2 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$2 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
@ -8545,44 +8545,66 @@ class Contract {
logger$f.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName); logger$f.throwArgumentError("provider is required to use non-address contract address", "addressOrName", addressOrName);
} }
} }
const uniqueFunctions = {}; const uniqueNames = {};
Object.keys(this.interface.functions).forEach((name) => { const uniqueSignatures = {};
const fragment = this.interface.functions[name]; Object.keys(this.interface.functions).forEach((signature) => {
// @TODO: This should take in fragment const fragment = this.interface.functions[signature];
const run = runMethod(this, name, {}); // Check that the signature is unique; if not the ABI generation has
if (this[name] == null) { // not been cleaned or may be incorrectly generated
defineReadOnly(this, name, run); if (uniqueSignatures[signature]) {
} logger$f.warn(`Duplicate ABI entry for ${JSON.stringify(name)}`);
if (this.functions[name] == null) {
defineReadOnly(this.functions, name, run);
}
if (this.callStatic[name] == null) {
defineReadOnly(this.callStatic, name, runMethod(this, name, { callStatic: true }));
}
if (this.populateTransaction[name] == null) {
defineReadOnly(this.populateTransaction, name, runMethod(this, name, { transaction: true }));
}
if (this.estimateGas[name] == null) {
defineReadOnly(this.estimateGas, name, runMethod(this, name, { estimate: true }));
}
if (!uniqueFunctions[fragment.name]) {
uniqueFunctions[fragment.name] = [];
}
uniqueFunctions[fragment.name].push(name);
});
Object.keys(uniqueFunctions).forEach((name) => {
const signatures = uniqueFunctions[name];
if (signatures.length > 1) {
logger$f.warn(`Duplicate definition of ${name} (${signatures.join(", ")})`);
return; return;
} }
if (this[name] == null) { uniqueSignatures[signature] = true;
defineReadOnly(this, name, this[signatures[0]]); // Track unique names; we only expose bare named functions if they
// are ambiguous
{
const name = fragment.name;
if (!uniqueNames[name]) {
uniqueNames[name] = [];
}
uniqueNames[name].push(signature);
}
// @TODO: This should take in fragment
const run = runMethod(this, signature, {});
if (this[signature] == null) {
defineReadOnly(this, signature, run);
}
if (this.functions[signature] == null) {
defineReadOnly(this.functions, signature, run);
}
if (this.callStatic[signature] == null) {
defineReadOnly(this.callStatic, signature, runMethod(this, signature, { callStatic: true }));
}
if (this.populateTransaction[signature] == null) {
defineReadOnly(this.populateTransaction, signature, runMethod(this, signature, { transaction: true }));
}
if (this.estimateGas[signature] == null) {
defineReadOnly(this.estimateGas, signature, runMethod(this, signature, { estimate: true }));
}
});
Object.keys(uniqueNames).forEach((name) => {
// Ambiguous names to not get attached as bare names
const signatures = uniqueNames[name];
if (signatures.length > 1) {
return;
}
const signature = signatures[0];
if (this[name] == null) {
defineReadOnly(this, name, this[signature]);
}
if (this.functions[name] == null) {
defineReadOnly(this.functions, name, this.functions[signature]);
}
if (this.callStatic[name] == null) {
defineReadOnly(this.callStatic, name, this.callStatic[signature]);
}
if (this.populateTransaction[name] == null) {
defineReadOnly(this.populateTransaction, name, this.populateTransaction[signature]);
}
if (this.estimateGas[name] == null) {
defineReadOnly(this.estimateGas, name, this.estimateGas[signature]);
} }
defineReadOnly(this.functions, name, this.functions[signatures[0]]);
defineReadOnly(this.callStatic, name, this.callStatic[signatures[0]]);
defineReadOnly(this.populateTransaction, name, this.populateTransaction[signatures[0]]);
defineReadOnly(this.estimateGas, name, this.estimateGas[signatures[0]]);
}); });
} }
static getContractAddress(transaction) { static getContractAddress(transaction) {
@ -15706,7 +15728,7 @@ var browser$2 = /*#__PURE__*/Object.freeze({
encode: encode$1 encode: encode$1
}); });
const version$l = "web/5.0.0-beta.137"; const version$l = "web/5.0.0-beta.138";
"use strict"; "use strict";
var __awaiter$4 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$4 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
@ -15845,8 +15867,13 @@ function fetchJson(connection, json, processFunc) {
response = yield getUrl(url, options); response = yield getUrl(url, options);
} }
catch (error) { catch (error) {
console.log(error);
response = error.response; response = error.response;
if (response == null) {
logger$p.throwError("missing response", Logger.errors.SERVER_ERROR, {
serverError: error,
url: url
});
}
} }
let body = response.body; let body = response.body;
if (allow304 && response.statusCode === 304) { if (allow304 && response.statusCode === 304) {
@ -16490,23 +16517,28 @@ class Event {
let defaultFormatter = null; let defaultFormatter = null;
let nextPollId = 1; let nextPollId = 1;
class BaseProvider extends Provider { class BaseProvider extends Provider {
/**
* ready
*
* A Promise<Network> that resolves only once the provider is ready.
*
* Sub-classes that call the super with a network without a chainId
* MUST set this. Standard named networks have a known chainId.
*
*/
constructor(network) { constructor(network) {
logger$r.checkNew(new.target, Provider); logger$r.checkNew(new.target, Provider);
super(); super();
this.formatter = new.target.getFormatter(); this.formatter = new.target.getFormatter();
if (network instanceof Promise) { if (network instanceof Promise) {
defineReadOnly(this, "ready", network.then((network) => { this._networkPromise = network;
defineReadOnly(this, "_network", network);
return network;
}));
// Squash any "unhandled promise" errors; that do not need to be handled // Squash any "unhandled promise" errors; that do not need to be handled
this.ready.catch((error) => { }); network.catch((error) => { });
} }
else { else {
const knownNetwork = getStatic((new.target), "getNetwork")(network); const knownNetwork = getStatic((new.target), "getNetwork")(network);
if (knownNetwork) { if (knownNetwork) {
defineReadOnly(this, "_network", knownNetwork); defineReadOnly(this, "_network", knownNetwork);
defineReadOnly(this, "ready", Promise.resolve(this._network));
} }
else { else {
logger$r.throwArgumentError("invalid network", "network", network); logger$r.throwArgumentError("invalid network", "network", network);
@ -16520,6 +16552,40 @@ class BaseProvider extends Provider {
this._emitted = { block: -2 }; this._emitted = { block: -2 };
this._fastQueryDate = 0; this._fastQueryDate = 0;
} }
_ready() {
return __awaiter$6(this, void 0, void 0, function* () {
if (this._network == null) {
let network = null;
if (this._networkPromise) {
try {
network = yield this._networkPromise;
}
catch (error) { }
}
// Try the Provider's network detection (this MUST throw if it cannot)
if (network == null) {
network = yield this.detectNetwork();
}
// This should never happen; every Provider sub-class should have
// suggested a network by here (or thrown).
if (!network) {
logger$r.throwError("no network detected", Logger.errors.UNKNOWN_ERROR, {});
}
defineReadOnly(this, "_network", network);
}
return this._network;
});
}
get ready() {
return this._ready();
}
detectNetwork() {
return __awaiter$6(this, void 0, void 0, function* () {
return logger$r.throwError("provider does not support network detection", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "provider.detectNetwork"
});
});
}
static getFormatter() { static getFormatter() {
if (defaultFormatter == null) { if (defaultFormatter == null) {
defaultFormatter = new Formatter(); defaultFormatter = new Formatter();
@ -17327,9 +17393,7 @@ var __awaiter$7 = (window && window.__awaiter) || function (thisArg, _arguments,
const logger$s = new Logger(version$m); const logger$s = new Logger(version$m);
function timer(timeout) { function timer(timeout) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
setTimeout(function () { setTimeout(resolve, timeout);
resolve();
}, timeout);
}); });
} }
function getResult(payload) { function getResult(payload) {
@ -17514,28 +17578,7 @@ class JsonRpcProvider extends BaseProvider {
} }
else { else {
// The network is unknown, query the JSON-RPC for it // The network is unknown, query the JSON-RPC for it
const ready = new Promise((resolve, reject) => { super(this.detectNetwork());
setTimeout(() => __awaiter$7(this, void 0, void 0, function* () {
let chainId = null;
try {
chainId = yield this.send("eth_chainId", []);
}
catch (error) {
try {
chainId = yield this.send("net_version", []);
}
catch (error) { }
}
if (chainId != null) {
try {
return resolve(getNetwork(BigNumber.from(chainId).toNumber()));
}
catch (error) { }
}
reject(logger$s.makeError("could not detect network", Logger.errors.NETWORK_ERROR));
}), 0);
});
super(ready);
} }
// Default URL // Default URL
if (!url) { if (!url) {
@ -17554,6 +17597,34 @@ class JsonRpcProvider extends BaseProvider {
static defaultUrl() { static defaultUrl() {
return "http:/\/localhost:8545"; return "http:/\/localhost:8545";
} }
detectNetwork() {
return __awaiter$7(this, void 0, void 0, function* () {
yield timer(0);
let chainId = null;
try {
chainId = yield this.send("eth_chainId", []);
}
catch (error) {
try {
chainId = yield this.send("net_version", []);
}
catch (error) { }
}
if (chainId != null) {
const getNetwork = getStatic(this.constructor, "getNetwork");
try {
return getNetwork(BigNumber.from(chainId).toNumber());
}
catch (error) {
return logger$s.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
chainId: chainId,
serverError: error
});
}
}
return logger$s.throwError("could not detect network", Logger.errors.NETWORK_ERROR);
});
}
getSigner(addressOrIndex) { getSigner(addressOrIndex) {
return new JsonRpcSigner(_constructorGuard$4, this, addressOrIndex); return new JsonRpcSigner(_constructorGuard$4, this, addressOrIndex);
} }
@ -17763,6 +17834,15 @@ class JsonRpcProvider extends BaseProvider {
} }
"use strict"; "use strict";
var __awaiter$8 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const logger$t = new Logger(version$m); const logger$t = new Logger(version$m);
class UrlJsonRpcProvider extends JsonRpcProvider { class UrlJsonRpcProvider extends JsonRpcProvider {
constructor(network, apiKey) { constructor(network, apiKey) {
@ -17781,6 +17861,11 @@ class UrlJsonRpcProvider extends JsonRpcProvider {
}); });
} }
} }
detectNetwork() {
return __awaiter$8(this, void 0, void 0, function* () {
return this.network;
});
}
_startPending() { _startPending() {
logger$t.warn("WARNING: API provider does not support pending filters"); logger$t.warn("WARNING: API provider does not support pending filters");
} }
@ -17844,7 +17929,7 @@ class AlchemyProvider extends UrlJsonRpcProvider {
} }
"use strict"; "use strict";
var __awaiter$8 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$9 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@ -17876,7 +17961,7 @@ class CloudflareProvider extends UrlJsonRpcProvider {
const _super = Object.create(null, { const _super = Object.create(null, {
perform: { get: () => super.perform } perform: { get: () => super.perform }
}); });
return __awaiter$8(this, void 0, void 0, function* () { return __awaiter$9(this, void 0, void 0, function* () {
// The Cloudflare provider does not support eth_blockNumber, // The Cloudflare provider does not support eth_blockNumber,
// so we get the latest block and pull it from that // so we get the latest block and pull it from that
if (method === "getBlockNumber") { if (method === "getBlockNumber") {
@ -17889,7 +17974,7 @@ class CloudflareProvider extends UrlJsonRpcProvider {
} }
"use strict"; "use strict";
var __awaiter$9 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$a = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@ -17989,17 +18074,22 @@ class EtherscanProvider extends BaseProvider {
defineReadOnly(this, "baseUrl", baseUrl); defineReadOnly(this, "baseUrl", baseUrl);
defineReadOnly(this, "apiKey", apiKey || defaultApiKey$1); defineReadOnly(this, "apiKey", apiKey || defaultApiKey$1);
} }
detectNetwork() {
return __awaiter$a(this, void 0, void 0, function* () {
return this.network;
});
}
perform(method, params) { perform(method, params) {
const _super = Object.create(null, { const _super = Object.create(null, {
perform: { get: () => super.perform } perform: { get: () => super.perform }
}); });
return __awaiter$9(this, void 0, void 0, function* () { return __awaiter$a(this, void 0, void 0, function* () {
let url = this.baseUrl; let url = this.baseUrl;
let apiKey = ""; let apiKey = "";
if (this.apiKey) { if (this.apiKey) {
apiKey += "&apikey=" + this.apiKey; apiKey += "&apikey=" + this.apiKey;
} }
const get = (url, procFunc) => __awaiter$9(this, void 0, void 0, function* () { const get = (url, procFunc) => __awaiter$a(this, void 0, void 0, function* () {
this.emit("debug", { this.emit("debug", {
action: "request", action: "request",
request: url, request: url,
@ -18212,7 +18302,7 @@ class EtherscanProvider extends BaseProvider {
} }
"use strict"; "use strict";
var __awaiter$a = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$b = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@ -18295,14 +18385,27 @@ function serialize$1(value) {
// Next request ID to use for emitting debug info // Next request ID to use for emitting debug info
let nextRid = 1; let nextRid = 1;
; ;
// Returns a promise that delays for duration
function stall(duration) { function stall(duration) {
return new Promise((resolve) => { let cancel = null;
const timer = setTimeout(resolve, duration); let timer = null;
if (timer.unref) { let promise = (new Promise((resolve) => {
timer.unref(); cancel = function () {
} if (timer) {
}); clearTimeout(timer);
timer = null;
}
resolve();
};
timer = setTimeout(cancel, duration);
}));
const wait = (func) => {
promise = promise.then(func);
return promise;
};
function getPromise() {
return promise;
}
return { cancel, getPromise, wait };
} }
; ;
function exposeDebugConfig(config, now) { function exposeDebugConfig(config, now) {
@ -18515,43 +18618,44 @@ class FallbackProvider extends BaseProvider {
super(network); super(network);
} }
else { else {
// The network won't be known until all child providers know super(this.detectNetwork());
const ready = Promise.all(providerConfigs.map((c) => c.provider.getNetwork())).then((networks) => {
return checkNetworks(networks);
});
super(ready);
} }
// Preserve a copy, so we do not get mutated // Preserve a copy, so we do not get mutated
defineReadOnly(this, "providerConfigs", Object.freeze(providerConfigs)); defineReadOnly(this, "providerConfigs", Object.freeze(providerConfigs));
defineReadOnly(this, "quorum", quorum); defineReadOnly(this, "quorum", quorum);
this._highestBlockNumber = -1; this._highestBlockNumber = -1;
} }
detectNetwork() {
return __awaiter$b(this, void 0, void 0, function* () {
const networks = yield Promise.all(this.providerConfigs.map((c) => c.provider.getNetwork()));
return checkNetworks(networks);
});
}
perform(method, params) { perform(method, params) {
return __awaiter$a(this, void 0, void 0, function* () { return __awaiter$b(this, void 0, void 0, function* () {
// Sending transactions is special; always broadcast it to all backends // Sending transactions is special; always broadcast it to all backends
if (method === "sendTransaction") { if (method === "sendTransaction") {
return Promise.all(this.providerConfigs.map((c) => { const results = yield Promise.all(this.providerConfigs.map((c) => {
return c.provider.sendTransaction(params.signedTransaction).then((result) => { return c.provider.sendTransaction(params.signedTransaction).then((result) => {
return result.hash; return result.hash;
}, (error) => { }, (error) => {
return error; return error;
}); });
})).then((results) => { }));
// Any success is good enough (other errors are likely "already seen" errors // Any success is good enough (other errors are likely "already seen" errors
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
const result = results[i]; const result = results[i];
if (typeof (result) === "string") { if (typeof (result) === "string") {
return result; return result;
}
} }
// They were all an error; pick the first error }
return Promise.reject(results[0]); // They were all an error; pick the first error
}); throw results[0];
} }
const processFunc = getProcessFunc(this, method, params); const processFunc = getProcessFunc(this, method, params);
// Shuffle the providers and then sort them by their priority; we // Shuffle the providers and then sort them by their priority; we
// shallowCopy them since we will store the result in them too // shallowCopy them since we will store the result in them too
const configs = shuffled(this.providerConfigs.map((c) => shallowCopy(c))); const configs = shuffled(this.providerConfigs.map(shallowCopy));
configs.sort((a, b) => (a.priority - b.priority)); configs.sort((a, b) => (a.priority - b.priority));
let i = 0; let i = 0;
let first = true; let first = true;
@ -18567,7 +18671,8 @@ class FallbackProvider extends BaseProvider {
const config = configs[i++]; const config = configs[i++];
const rid = nextRid++; const rid = nextRid++;
config.start = now(); config.start = now();
config.staller = stall(config.stallTimeout).then(() => { config.staller = null; }); 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, method, params).then((result) => {
config.done = true; config.done = true;
config.result = result; config.result = result;
@ -18593,7 +18698,6 @@ class FallbackProvider extends BaseProvider {
}); });
} }
}); });
//running.push(config);
if (this.listenerCount("debug")) { if (this.listenerCount("debug")) {
this.emit("debug", { this.emit("debug", {
action: "request", action: "request",
@ -18613,7 +18717,7 @@ class FallbackProvider extends BaseProvider {
} }
waiting.push(c.runner); waiting.push(c.runner);
if (c.staller) { if (c.staller) {
waiting.push(c.staller); waiting.push(c.staller.getPromise());
} }
}); });
if (waiting.length) { if (waiting.length) {
@ -18625,10 +18729,12 @@ class FallbackProvider extends BaseProvider {
if (results.length >= this.quorum) { if (results.length >= this.quorum) {
const result = processFunc(results); const result = processFunc(results);
if (result !== undefined) { if (result !== undefined) {
// Shut down any stallers
configs.filter(c => c.staller).forEach(c => c.staller.cancel());
return result; return result;
} }
if (!first) { if (!first) {
yield stall(100); yield stall(100).getPromise();
} }
first = false; first = false;
} }
@ -18637,6 +18743,8 @@ class FallbackProvider extends BaseProvider {
break; break;
} }
} }
// Shut down any stallers; shouldn't be any
configs.filter(c => c.staller).forEach(c => c.staller.cancel());
return logger$x.throwError("failed to meet quorum", Logger.errors.SERVER_ERROR, { return logger$x.throwError("failed to meet quorum", Logger.errors.SERVER_ERROR, {
method: method, method: method,
params: params, params: params,
@ -18656,204 +18764,6 @@ var browserIpcProvider = {
IpcProvider: IpcProvider IpcProvider: IpcProvider
}; };
"use strict";
const logger$y = new Logger(version$m);
const defaultProjectId = "84842078b09946638c03157f83405213";
class InfuraProvider extends UrlJsonRpcProvider {
static getApiKey(apiKey) {
const apiKeyObj = {
apiKey: defaultProjectId,
projectId: defaultProjectId,
projectSecret: null
};
if (apiKey == null) {
return apiKeyObj;
}
if (typeof (apiKey) === "string") {
apiKeyObj.projectId = apiKey;
}
else if (apiKey.projectSecret != null) {
if (typeof (apiKey.projectId) !== "string") {
logger$y.throwArgumentError("projectSecret requires a projectId", "projectId", apiKey.projectId);
}
if (typeof (apiKey.projectSecret) !== "string") {
logger$y.throwArgumentError("invalid projectSecret", "projectSecret", "[REDACTED]");
}
apiKeyObj.projectId = apiKey.projectId;
apiKeyObj.projectSecret = apiKey.projectSecret;
}
else if (apiKey.projectId) {
apiKeyObj.projectId = apiKey.projectId;
}
apiKeyObj.apiKey = apiKeyObj.projectId;
return apiKeyObj;
}
static getUrl(network, apiKey) {
let host = null;
switch (network.name) {
case "homestead":
host = "mainnet.infura.io";
break;
case "ropsten":
host = "ropsten.infura.io";
break;
case "rinkeby":
host = "rinkeby.infura.io";
break;
case "kovan":
host = "kovan.infura.io";
break;
case "goerli":
host = "goerli.infura.io";
break;
default:
logger$y.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
argument: "network",
value: network
});
}
const connection = {
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId)
};
if (apiKey.projectSecret != null) {
connection.user = "";
connection.password = apiKey.projectSecret;
}
return connection;
}
}
"use strict";
const logger$z = new Logger(version$m);
// Special API key provided by Nodesmith for ethers.js
const defaultApiKey$2 = "ETHERS_JS_SHARED";
class NodesmithProvider extends UrlJsonRpcProvider {
static getApiKey(apiKey) {
if (apiKey && typeof (apiKey) !== "string") {
logger$z.throwArgumentError("invalid apiKey", "apiKey", apiKey);
}
return apiKey || defaultApiKey$2;
}
static getUrl(network, apiKey) {
logger$z.warn("NodeSmith will be discontinued on 2019-12-20; please migrate to another platform.");
let host = null;
switch (network.name) {
case "homestead":
host = "https://ethereum.api.nodesmith.io/v1/mainnet/jsonrpc";
break;
case "ropsten":
host = "https://ethereum.api.nodesmith.io/v1/ropsten/jsonrpc";
break;
case "rinkeby":
host = "https://ethereum.api.nodesmith.io/v1/rinkeby/jsonrpc";
break;
case "goerli":
host = "https://ethereum.api.nodesmith.io/v1/goerli/jsonrpc";
break;
case "kovan":
host = "https://ethereum.api.nodesmith.io/v1/kovan/jsonrpc";
break;
default:
logger$z.throwArgumentError("unsupported network", "network", arguments[0]);
}
return (host + "?apiKey=" + apiKey);
}
}
"use strict";
const logger$A = new Logger(version$m);
let _nextId = 1;
function buildWeb3LegacyFetcher(provider, sendFunc) {
return function (method, params) {
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [params[1], params[0]];
}
const request = {
method: method,
params: params,
id: (_nextId++),
jsonrpc: "2.0"
};
return new Promise((resolve, reject) => {
sendFunc(request, function (error, result) {
if (error) {
return reject(error);
}
if (result.error) {
const error = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
return reject(error);
}
resolve(result.result);
});
});
};
}
function buildEip1193Fetcher(provider) {
return function (method, params) {
if (params == null) {
params = [];
}
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [params[1], params[0]];
}
return provider.request({ method, params });
};
}
class Web3Provider extends JsonRpcProvider {
constructor(provider, network) {
logger$A.checkNew(new.target, Web3Provider);
if (provider == null) {
logger$A.throwArgumentError("missing provider", "provider", provider);
}
let path = null;
let jsonRpcFetchFunc = null;
let subprovider = null;
if (typeof (provider) === "function") {
path = "unknown:";
jsonRpcFetchFunc = provider;
}
else {
path = provider.host || provider.path || "";
if (!path && provider.isMetaMask) {
path = "metamask";
}
subprovider = provider;
if (provider.request) {
if (path === "") {
path = "eip-1193:";
}
jsonRpcFetchFunc = buildEip1193Fetcher(provider);
}
else if (provider.sendAsync) {
jsonRpcFetchFunc = buildWeb3LegacyFetcher(provider, provider.sendAsync.bind(provider));
}
else if (provider.send) {
jsonRpcFetchFunc = buildWeb3LegacyFetcher(provider, provider.send.bind(provider));
}
else {
logger$A.throwArgumentError("unsupported provider", "provider", provider);
}
if (!path) {
path = "unknown:";
}
}
super(path, network);
defineReadOnly(this, "jsonRpcFetchFunc", jsonRpcFetchFunc);
defineReadOnly(this, "provider", subprovider);
}
send(method, params) {
return this.jsonRpcFetchFunc(method, params);
}
}
var _version$2 = createCommonjsModule(function (module, exports) { var _version$2 = createCommonjsModule(function (module, exports) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
@ -18889,7 +18799,7 @@ module.exports = WS;
var WebSocket$1 = unwrapExports(browserWs); var WebSocket$1 = unwrapExports(browserWs);
"use strict"; "use strict";
var __awaiter$b = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter$c = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@ -18898,7 +18808,7 @@ var __awaiter$b = (window && window.__awaiter) || function (thisArg, _arguments,
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
const logger$B = new Logger(version$m); const logger$y = new Logger(version$m);
/** /**
* Notes: * Notes:
* *
@ -18935,11 +18845,11 @@ class WebSocketProvider extends JsonRpcProvider {
this._websocket.onmessage = (messageEvent) => { this._websocket.onmessage = (messageEvent) => {
const data = messageEvent.data; const data = messageEvent.data;
const result = JSON.parse(data); const result = JSON.parse(data);
if (result.id) { if (result.id != null) {
const id = String(result.id); const id = String(result.id);
const request = this._requests[id]; const request = this._requests[id];
delete this._requests[id]; delete this._requests[id];
if (result.result) { if (result.result !== undefined) {
request.callback(null, result.result); request.callback(null, result.result);
} }
else { else {
@ -18971,17 +18881,17 @@ class WebSocketProvider extends JsonRpcProvider {
return 0; return 0;
} }
resetEventsBlock(blockNumber) { resetEventsBlock(blockNumber) {
logger$B.throwError("cannot reset events block on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, { logger$y.throwError("cannot reset events block on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "resetEventBlock" operation: "resetEventBlock"
}); });
} }
set pollingInterval(value) { set pollingInterval(value) {
logger$B.throwError("cannot set polling interval on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, { logger$y.throwError("cannot set polling interval on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "setPollingInterval" operation: "setPollingInterval"
}); });
} }
poll() { poll() {
return __awaiter$b(this, void 0, void 0, function* () { return __awaiter$c(this, void 0, void 0, function* () {
return null; return null;
}); });
} }
@ -18989,7 +18899,7 @@ class WebSocketProvider extends JsonRpcProvider {
if (!value) { if (!value) {
return; return;
} }
logger$B.throwError("cannot set polling on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, { logger$y.throwError("cannot set polling on WebSocketProvider", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "setPolling" operation: "setPolling"
}); });
} }
@ -19018,7 +18928,7 @@ class WebSocketProvider extends JsonRpcProvider {
return "ws:/\/localhost:8546"; return "ws:/\/localhost:8546";
} }
_subscribe(tag, param, processFunc) { _subscribe(tag, param, processFunc) {
return __awaiter$b(this, void 0, void 0, function* () { return __awaiter$c(this, void 0, void 0, function* () {
let subIdPromise = this._subIds[tag]; let subIdPromise = this._subIds[tag];
if (subIdPromise == null) { if (subIdPromise == null) {
subIdPromise = Promise.all(param).then((param) => { subIdPromise = Promise.all(param).then((param) => {
@ -19108,6 +19018,215 @@ class WebSocketProvider extends JsonRpcProvider {
} }
} }
"use strict";
const logger$z = new Logger(version$m);
const defaultProjectId = "84842078b09946638c03157f83405213";
class InfuraProvider extends UrlJsonRpcProvider {
static getWebSocketProvider(network, apiKey) {
const provider = new InfuraProvider(network, apiKey);
const connection = provider.connection;
if (connection.password) {
logger$z.throwError("INFURA WebSocket project secrets unsupported", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "InfuraProvider.getWebSocketProvider()"
});
}
const url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/");
return new WebSocketProvider(url, network);
}
static getApiKey(apiKey) {
const apiKeyObj = {
apiKey: defaultProjectId,
projectId: defaultProjectId,
projectSecret: null
};
if (apiKey == null) {
return apiKeyObj;
}
if (typeof (apiKey) === "string") {
apiKeyObj.projectId = apiKey;
}
else if (apiKey.projectSecret != null) {
if (typeof (apiKey.projectId) !== "string") {
logger$z.throwArgumentError("projectSecret requires a projectId", "projectId", apiKey.projectId);
}
if (typeof (apiKey.projectSecret) !== "string") {
logger$z.throwArgumentError("invalid projectSecret", "projectSecret", "[REDACTED]");
}
apiKeyObj.projectId = apiKey.projectId;
apiKeyObj.projectSecret = apiKey.projectSecret;
}
else if (apiKey.projectId) {
apiKeyObj.projectId = apiKey.projectId;
}
apiKeyObj.apiKey = apiKeyObj.projectId;
return apiKeyObj;
}
static getUrl(network, apiKey) {
let host = null;
switch (network.name) {
case "homestead":
host = "mainnet.infura.io";
break;
case "ropsten":
host = "ropsten.infura.io";
break;
case "rinkeby":
host = "rinkeby.infura.io";
break;
case "kovan":
host = "kovan.infura.io";
break;
case "goerli":
host = "goerli.infura.io";
break;
default:
logger$z.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
argument: "network",
value: network
});
}
const connection = {
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId)
};
if (apiKey.projectSecret != null) {
connection.user = "";
connection.password = apiKey.projectSecret;
}
return connection;
}
}
"use strict";
const logger$A = new Logger(version$m);
// Special API key provided by Nodesmith for ethers.js
const defaultApiKey$2 = "ETHERS_JS_SHARED";
class NodesmithProvider extends UrlJsonRpcProvider {
static getApiKey(apiKey) {
if (apiKey && typeof (apiKey) !== "string") {
logger$A.throwArgumentError("invalid apiKey", "apiKey", apiKey);
}
return apiKey || defaultApiKey$2;
}
static getUrl(network, apiKey) {
logger$A.warn("NodeSmith will be discontinued on 2019-12-20; please migrate to another platform.");
let host = null;
switch (network.name) {
case "homestead":
host = "https://ethereum.api.nodesmith.io/v1/mainnet/jsonrpc";
break;
case "ropsten":
host = "https://ethereum.api.nodesmith.io/v1/ropsten/jsonrpc";
break;
case "rinkeby":
host = "https://ethereum.api.nodesmith.io/v1/rinkeby/jsonrpc";
break;
case "goerli":
host = "https://ethereum.api.nodesmith.io/v1/goerli/jsonrpc";
break;
case "kovan":
host = "https://ethereum.api.nodesmith.io/v1/kovan/jsonrpc";
break;
default:
logger$A.throwArgumentError("unsupported network", "network", arguments[0]);
}
return (host + "?apiKey=" + apiKey);
}
}
"use strict";
const logger$B = new Logger(version$m);
let _nextId = 1;
function buildWeb3LegacyFetcher(provider, sendFunc) {
return function (method, params) {
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [params[1], params[0]];
}
const request = {
method: method,
params: params,
id: (_nextId++),
jsonrpc: "2.0"
};
return new Promise((resolve, reject) => {
sendFunc(request, function (error, result) {
if (error) {
return reject(error);
}
if (result.error) {
const error = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
return reject(error);
}
resolve(result.result);
});
});
};
}
function buildEip1193Fetcher(provider) {
return function (method, params) {
if (params == null) {
params = [];
}
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [params[1], params[0]];
}
return provider.request({ method, params });
};
}
class Web3Provider extends JsonRpcProvider {
constructor(provider, network) {
logger$B.checkNew(new.target, Web3Provider);
if (provider == null) {
logger$B.throwArgumentError("missing provider", "provider", provider);
}
let path = null;
let jsonRpcFetchFunc = null;
let subprovider = null;
if (typeof (provider) === "function") {
path = "unknown:";
jsonRpcFetchFunc = provider;
}
else {
path = provider.host || provider.path || "";
if (!path && provider.isMetaMask) {
path = "metamask";
}
subprovider = provider;
if (provider.request) {
if (path === "") {
path = "eip-1193:";
}
jsonRpcFetchFunc = buildEip1193Fetcher(provider);
}
else if (provider.sendAsync) {
jsonRpcFetchFunc = buildWeb3LegacyFetcher(provider, provider.sendAsync.bind(provider));
}
else if (provider.send) {
jsonRpcFetchFunc = buildWeb3LegacyFetcher(provider, provider.send.bind(provider));
}
else {
logger$B.throwArgumentError("unsupported provider", "provider", provider);
}
if (!path) {
path = "unknown:";
}
}
super(path, network);
defineReadOnly(this, "jsonRpcFetchFunc", jsonRpcFetchFunc);
defineReadOnly(this, "provider", subprovider);
}
send(method, params) {
return this.jsonRpcFetchFunc(method, params);
}
}
"use strict"; "use strict";
const logger$C = new Logger(version$m); const logger$C = new Logger(version$m);
//////////////////////// ////////////////////////

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -52,7 +52,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"tarballHash": "0xe9daa152b8c9f669a2a20427db554a49d87d64060a3851a5ace3bdcab47e3173", "tarballHash": "0x1c30ae49addbeee1a530704a69d38cd067932db413c4643b38409be32c7c04e1",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.185" "version": "5.0.0-beta.185"
} }

View File

@ -25,6 +25,7 @@ export declare class Event {
pollable(): boolean; pollable(): boolean;
} }
export declare class BaseProvider extends Provider { export declare class BaseProvider extends Provider {
_networkPromise: Promise<Network>;
_network: Network; _network: Network;
_events: Array<Event>; _events: Array<Event>;
formatter: Formatter; formatter: Formatter;
@ -52,8 +53,10 @@ export declare class BaseProvider extends Provider {
* MUST set this. Standard named networks have a known chainId. * MUST set this. Standard named networks have a known chainId.
* *
*/ */
ready: Promise<Network>;
constructor(network: Networkish | Promise<Network>); constructor(network: Networkish | Promise<Network>);
_ready(): Promise<Network>;
get ready(): Promise<Network>;
detectNetwork(): Promise<Network>;
static getFormatter(): Formatter; static getFormatter(): Formatter;
static getNetwork(network: Networkish): Network; static getNetwork(network: Networkish): Network;
_getInternalBlockNumber(maxAge: number): Promise<number>; _getInternalBlockNumber(maxAge: number): Promise<number>;

View File

@ -154,23 +154,28 @@ export class Event {
let defaultFormatter = null; let defaultFormatter = null;
let nextPollId = 1; let nextPollId = 1;
export class BaseProvider extends Provider { export class BaseProvider extends Provider {
/**
* ready
*
* A Promise<Network> that resolves only once the provider is ready.
*
* Sub-classes that call the super with a network without a chainId
* MUST set this. Standard named networks have a known chainId.
*
*/
constructor(network) { constructor(network) {
logger.checkNew(new.target, Provider); logger.checkNew(new.target, Provider);
super(); super();
this.formatter = new.target.getFormatter(); this.formatter = new.target.getFormatter();
if (network instanceof Promise) { if (network instanceof Promise) {
defineReadOnly(this, "ready", network.then((network) => { this._networkPromise = network;
defineReadOnly(this, "_network", network);
return network;
}));
// Squash any "unhandled promise" errors; that do not need to be handled // Squash any "unhandled promise" errors; that do not need to be handled
this.ready.catch((error) => { }); network.catch((error) => { });
} }
else { else {
const knownNetwork = getStatic((new.target), "getNetwork")(network); const knownNetwork = getStatic((new.target), "getNetwork")(network);
if (knownNetwork) { if (knownNetwork) {
defineReadOnly(this, "_network", knownNetwork); defineReadOnly(this, "_network", knownNetwork);
defineReadOnly(this, "ready", Promise.resolve(this._network));
} }
else { else {
logger.throwArgumentError("invalid network", "network", network); logger.throwArgumentError("invalid network", "network", network);
@ -184,6 +189,40 @@ export class BaseProvider extends Provider {
this._emitted = { block: -2 }; this._emitted = { block: -2 };
this._fastQueryDate = 0; this._fastQueryDate = 0;
} }
_ready() {
return __awaiter(this, void 0, void 0, function* () {
if (this._network == null) {
let network = null;
if (this._networkPromise) {
try {
network = yield this._networkPromise;
}
catch (error) { }
}
// Try the Provider's network detection (this MUST throw if it cannot)
if (network == null) {
network = yield this.detectNetwork();
}
// This should never happen; every Provider sub-class should have
// suggested a network by here (or thrown).
if (!network) {
logger.throwError("no network detected", Logger.errors.UNKNOWN_ERROR, {});
}
defineReadOnly(this, "_network", network);
}
return this._network;
});
}
get ready() {
return this._ready();
}
detectNetwork() {
return __awaiter(this, void 0, void 0, function* () {
return logger.throwError("provider does not support network detection", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "provider.detectNetwork"
});
});
}
static getFormatter() { static getFormatter() {
if (defaultFormatter == null) { if (defaultFormatter == null) {
defaultFormatter = new Formatter(); defaultFormatter = new Formatter();

View File

@ -1,10 +1,11 @@
import { BlockTag, TransactionResponse } from "@ethersproject/abstract-provider"; import { BlockTag, TransactionResponse } from "@ethersproject/abstract-provider";
import { Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { BaseProvider } from "./base-provider"; import { BaseProvider } from "./base-provider";
export declare class EtherscanProvider extends BaseProvider { export declare class EtherscanProvider extends BaseProvider {
readonly baseUrl: string; readonly baseUrl: string;
readonly apiKey: string; readonly apiKey: string;
constructor(network?: Networkish, apiKey?: string); constructor(network?: Networkish, apiKey?: string);
detectNetwork(): Promise<Network>;
perform(method: string, params: any): Promise<any>; perform(method: string, params: any): Promise<any>;
getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>>; getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>>;
} }

View File

@ -105,6 +105,11 @@ export class EtherscanProvider extends BaseProvider {
defineReadOnly(this, "baseUrl", baseUrl); defineReadOnly(this, "baseUrl", baseUrl);
defineReadOnly(this, "apiKey", apiKey || defaultApiKey); defineReadOnly(this, "apiKey", apiKey || defaultApiKey);
} }
detectNetwork() {
return __awaiter(this, void 0, void 0, function* () {
return this.network;
});
}
perform(method, params) { perform(method, params) {
const _super = Object.create(null, { const _super = Object.create(null, {
perform: { get: () => super.perform } perform: { get: () => super.perform }

View File

@ -1,3 +1,4 @@
import { Network } from "@ethersproject/networks";
import { Provider } from "@ethersproject/abstract-provider"; import { Provider } from "@ethersproject/abstract-provider";
import { BaseProvider } from "./base-provider"; import { BaseProvider } from "./base-provider";
export interface FallbackProviderConfig { export interface FallbackProviderConfig {
@ -11,6 +12,7 @@ export declare class FallbackProvider extends BaseProvider {
readonly quorum: number; readonly quorum: number;
_highestBlockNumber: number; _highestBlockNumber: number;
constructor(providers: Array<Provider | FallbackProviderConfig>, quorum?: number); constructor(providers: Array<Provider | FallbackProviderConfig>, quorum?: number);
detectNetwork(): Promise<Network>;
perform(method: string, params: { perform(method: string, params: {
[name: string]: any; [name: string]: any;
}): Promise<any>; }): Promise<any>;

View File

@ -89,14 +89,27 @@ function serialize(value) {
// Next request ID to use for emitting debug info // Next request ID to use for emitting debug info
let nextRid = 1; let nextRid = 1;
; ;
// Returns a promise that delays for duration
function stall(duration) { function stall(duration) {
return new Promise((resolve) => { let cancel = null;
const timer = setTimeout(resolve, duration); let timer = null;
if (timer.unref) { let promise = (new Promise((resolve) => {
timer.unref(); cancel = function () {
} if (timer) {
}); clearTimeout(timer);
timer = null;
}
resolve();
};
timer = setTimeout(cancel, duration);
}));
const wait = (func) => {
promise = promise.then(func);
return promise;
};
function getPromise() {
return promise;
}
return { cancel, getPromise, wait };
} }
; ;
function exposeDebugConfig(config, now) { function exposeDebugConfig(config, now) {
@ -309,43 +322,44 @@ export class FallbackProvider extends BaseProvider {
super(network); super(network);
} }
else { else {
// The network won't be known until all child providers know super(this.detectNetwork());
const ready = Promise.all(providerConfigs.map((c) => c.provider.getNetwork())).then((networks) => {
return checkNetworks(networks);
});
super(ready);
} }
// Preserve a copy, so we do not get mutated // Preserve a copy, so we do not get mutated
defineReadOnly(this, "providerConfigs", Object.freeze(providerConfigs)); defineReadOnly(this, "providerConfigs", Object.freeze(providerConfigs));
defineReadOnly(this, "quorum", quorum); defineReadOnly(this, "quorum", quorum);
this._highestBlockNumber = -1; this._highestBlockNumber = -1;
} }
detectNetwork() {
return __awaiter(this, void 0, void 0, function* () {
const networks = yield Promise.all(this.providerConfigs.map((c) => c.provider.getNetwork()));
return checkNetworks(networks);
});
}
perform(method, params) { perform(method, params) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Sending transactions is special; always broadcast it to all backends // Sending transactions is special; always broadcast it to all backends
if (method === "sendTransaction") { if (method === "sendTransaction") {
return Promise.all(this.providerConfigs.map((c) => { const results = yield Promise.all(this.providerConfigs.map((c) => {
return c.provider.sendTransaction(params.signedTransaction).then((result) => { return c.provider.sendTransaction(params.signedTransaction).then((result) => {
return result.hash; return result.hash;
}, (error) => { }, (error) => {
return error; return error;
}); });
})).then((results) => { }));
// Any success is good enough (other errors are likely "already seen" errors // Any success is good enough (other errors are likely "already seen" errors
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
const result = results[i]; const result = results[i];
if (typeof (result) === "string") { if (typeof (result) === "string") {
return result; return result;
}
} }
// They were all an error; pick the first error }
return Promise.reject(results[0]); // They were all an error; pick the first error
}); throw results[0];
} }
const processFunc = getProcessFunc(this, method, params); const processFunc = getProcessFunc(this, method, params);
// Shuffle the providers and then sort them by their priority; we // Shuffle the providers and then sort them by their priority; we
// shallowCopy them since we will store the result in them too // shallowCopy them since we will store the result in them too
const configs = shuffled(this.providerConfigs.map((c) => shallowCopy(c))); const configs = shuffled(this.providerConfigs.map(shallowCopy));
configs.sort((a, b) => (a.priority - b.priority)); configs.sort((a, b) => (a.priority - b.priority));
let i = 0; let i = 0;
let first = true; let first = true;
@ -361,7 +375,8 @@ export class FallbackProvider extends BaseProvider {
const config = configs[i++]; const config = configs[i++];
const rid = nextRid++; const rid = nextRid++;
config.start = now(); config.start = now();
config.staller = stall(config.stallTimeout).then(() => { config.staller = null; }); 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, method, params).then((result) => {
config.done = true; config.done = true;
config.result = result; config.result = result;
@ -387,7 +402,6 @@ export class FallbackProvider extends BaseProvider {
}); });
} }
}); });
//running.push(config);
if (this.listenerCount("debug")) { if (this.listenerCount("debug")) {
this.emit("debug", { this.emit("debug", {
action: "request", action: "request",
@ -407,7 +421,7 @@ export class FallbackProvider extends BaseProvider {
} }
waiting.push(c.runner); waiting.push(c.runner);
if (c.staller) { if (c.staller) {
waiting.push(c.staller); waiting.push(c.staller.getPromise());
} }
}); });
if (waiting.length) { if (waiting.length) {
@ -419,10 +433,12 @@ export class FallbackProvider extends BaseProvider {
if (results.length >= this.quorum) { if (results.length >= this.quorum) {
const result = processFunc(results); const result = processFunc(results);
if (result !== undefined) { if (result !== undefined) {
// Shut down any stallers
configs.filter(c => c.staller).forEach(c => c.staller.cancel());
return result; return result;
} }
if (!first) { if (!first) {
yield stall(100); yield stall(100).getPromise();
} }
first = false; first = false;
} }
@ -431,6 +447,8 @@ export class FallbackProvider extends BaseProvider {
break; break;
} }
} }
// Shut down any stallers; shouldn't be any
configs.filter(c => c.staller).forEach(c => c.staller.cancel());
return logger.throwError("failed to meet quorum", Logger.errors.SERVER_ERROR, { return logger.throwError("failed to meet quorum", Logger.errors.SERVER_ERROR, {
method: method, method: method,
params: params, params: params,

View File

@ -1,9 +1,11 @@
import { Network } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { ConnectionInfo } from "@ethersproject/web"; import { ConnectionInfo } from "@ethersproject/web";
import { WebSocketProvider } from "./websocket-provider";
import { UrlJsonRpcProvider } from "./url-json-rpc-provider"; import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
export declare class InfuraProvider extends UrlJsonRpcProvider { export declare class InfuraProvider extends UrlJsonRpcProvider {
readonly projectId: string; readonly projectId: string;
readonly projectSecret: string; readonly projectSecret: string;
static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider;
static getApiKey(apiKey: any): any; static getApiKey(apiKey: any): any;
static getUrl(network: Network, apiKey: any): string | ConnectionInfo; static getUrl(network: Network, apiKey: any): string | ConnectionInfo;
} }

View File

@ -1,10 +1,22 @@
"use strict"; "use strict";
import { WebSocketProvider } from "./websocket-provider";
import { Logger } from "@ethersproject/logger"; import { Logger } from "@ethersproject/logger";
import { version } from "./_version"; import { version } from "./_version";
const logger = new Logger(version); const logger = new Logger(version);
import { UrlJsonRpcProvider } from "./url-json-rpc-provider"; import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
const defaultProjectId = "84842078b09946638c03157f83405213"; const defaultProjectId = "84842078b09946638c03157f83405213";
export class InfuraProvider extends UrlJsonRpcProvider { export class InfuraProvider extends UrlJsonRpcProvider {
static getWebSocketProvider(network, apiKey) {
const provider = new InfuraProvider(network, apiKey);
const connection = provider.connection;
if (connection.password) {
logger.throwError("INFURA WebSocket project secrets unsupported", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "InfuraProvider.getWebSocketProvider()"
});
}
const url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/");
return new WebSocketProvider(url, network);
}
static getApiKey(apiKey) { static getApiKey(apiKey) {
const apiKeyObj = { const apiKeyObj = {
apiKey: defaultProjectId, apiKey: defaultProjectId,

View File

@ -1,7 +1,7 @@
import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider"; import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { Signer } from "@ethersproject/abstract-signer"; import { Signer } from "@ethersproject/abstract-signer";
import { Bytes } from "@ethersproject/bytes"; import { Bytes } from "@ethersproject/bytes";
import { Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { ConnectionInfo } from "@ethersproject/web"; import { ConnectionInfo } from "@ethersproject/web";
import { BaseProvider, Event } from "./base-provider"; import { BaseProvider, Event } from "./base-provider";
export declare class JsonRpcSigner extends Signer { export declare class JsonRpcSigner extends Signer {
@ -27,6 +27,7 @@ export declare class JsonRpcProvider extends BaseProvider {
_nextId: number; _nextId: number;
constructor(url?: ConnectionInfo | string, network?: Networkish); constructor(url?: ConnectionInfo | string, network?: Networkish);
static defaultUrl(): string; static defaultUrl(): string;
detectNetwork(): Promise<Network>;
getSigner(addressOrIndex?: string | number): JsonRpcSigner; getSigner(addressOrIndex?: string | number): JsonRpcSigner;
getUncheckedSigner(addressOrIndex?: string | number): UncheckedJsonRpcSigner; getUncheckedSigner(addressOrIndex?: string | number): UncheckedJsonRpcSigner;
listAccounts(): Promise<Array<string>>; listAccounts(): Promise<Array<string>>;

View File

@ -20,9 +20,7 @@ const logger = new Logger(version);
import { BaseProvider } from "./base-provider"; import { BaseProvider } from "./base-provider";
function timer(timeout) { function timer(timeout) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
setTimeout(function () { setTimeout(resolve, timeout);
resolve();
}, timeout);
}); });
} }
function getResult(payload) { function getResult(payload) {
@ -207,28 +205,7 @@ export class JsonRpcProvider extends BaseProvider {
} }
else { else {
// The network is unknown, query the JSON-RPC for it // The network is unknown, query the JSON-RPC for it
const ready = new Promise((resolve, reject) => { super(this.detectNetwork());
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
let chainId = null;
try {
chainId = yield this.send("eth_chainId", []);
}
catch (error) {
try {
chainId = yield this.send("net_version", []);
}
catch (error) { }
}
if (chainId != null) {
try {
return resolve(getNetwork(BigNumber.from(chainId).toNumber()));
}
catch (error) { }
}
reject(logger.makeError("could not detect network", Logger.errors.NETWORK_ERROR));
}), 0);
});
super(ready);
} }
// Default URL // Default URL
if (!url) { if (!url) {
@ -247,6 +224,34 @@ export class JsonRpcProvider extends BaseProvider {
static defaultUrl() { static defaultUrl() {
return "http:/\/localhost:8545"; return "http:/\/localhost:8545";
} }
detectNetwork() {
return __awaiter(this, void 0, void 0, function* () {
yield timer(0);
let chainId = null;
try {
chainId = yield this.send("eth_chainId", []);
}
catch (error) {
try {
chainId = yield this.send("net_version", []);
}
catch (error) { }
}
if (chainId != null) {
const getNetwork = getStatic(this.constructor, "getNetwork");
try {
return getNetwork(BigNumber.from(chainId).toNumber());
}
catch (error) {
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
chainId: chainId,
serverError: error
});
}
}
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR);
});
}
getSigner(addressOrIndex) { getSigner(addressOrIndex) {
return new JsonRpcSigner(_constructorGuard, this, addressOrIndex); return new JsonRpcSigner(_constructorGuard, this, addressOrIndex);
} }

View File

@ -4,6 +4,7 @@ import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
export declare abstract class UrlJsonRpcProvider extends JsonRpcProvider { export declare abstract class UrlJsonRpcProvider extends JsonRpcProvider {
readonly apiKey: any; readonly apiKey: any;
constructor(network?: Networkish, apiKey?: any); constructor(network?: Networkish, apiKey?: any);
detectNetwork(): Promise<Network>;
_startPending(): void; _startPending(): void;
getSigner(address?: string): JsonRpcSigner; getSigner(address?: string): JsonRpcSigner;
listAccounts(): Promise<Array<string>>; listAccounts(): Promise<Array<string>>;

View File

@ -1,4 +1,13 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { defineReadOnly, getStatic } from "@ethersproject/properties"; import { defineReadOnly, getStatic } from "@ethersproject/properties";
import { Logger } from "@ethersproject/logger"; import { Logger } from "@ethersproject/logger";
import { version } from "./_version"; import { version } from "./_version";
@ -21,6 +30,11 @@ export class UrlJsonRpcProvider extends JsonRpcProvider {
}); });
} }
} }
detectNetwork() {
return __awaiter(this, void 0, void 0, function* () {
return this.network;
});
}
_startPending() { _startPending() {
logger.warn("WARNING: API provider does not support pending filters"); logger.warn("WARNING: API provider does not support pending filters");
} }

View File

@ -51,11 +51,11 @@ export class WebSocketProvider extends JsonRpcProvider {
this._websocket.onmessage = (messageEvent) => { this._websocket.onmessage = (messageEvent) => {
const data = messageEvent.data; const data = messageEvent.data;
const result = JSON.parse(data); const result = JSON.parse(data);
if (result.id) { if (result.id != null) {
const id = String(result.id); const id = String(result.id);
const request = this._requests[id]; const request = this._requests[id];
delete this._requests[id]; delete this._requests[id];
if (result.result) { if (result.result !== undefined) {
request.callback(null, result.result); request.callback(null, result.result);
} }
else { else {

View File

@ -25,6 +25,7 @@ export declare class Event {
pollable(): boolean; pollable(): boolean;
} }
export declare class BaseProvider extends Provider { export declare class BaseProvider extends Provider {
_networkPromise: Promise<Network>;
_network: Network; _network: Network;
_events: Array<Event>; _events: Array<Event>;
formatter: Formatter; formatter: Formatter;
@ -52,8 +53,10 @@ export declare class BaseProvider extends Provider {
* MUST set this. Standard named networks have a known chainId. * MUST set this. Standard named networks have a known chainId.
* *
*/ */
ready: Promise<Network>;
constructor(network: Networkish | Promise<Network>); constructor(network: Networkish | Promise<Network>);
_ready(): Promise<Network>;
get ready(): Promise<Network>;
detectNetwork(): Promise<Network>;
static getFormatter(): Formatter; static getFormatter(): Formatter;
static getNetwork(network: Networkish): Network; static getNetwork(network: Networkish): Network;
_getInternalBlockNumber(maxAge: number): Promise<number>; _getInternalBlockNumber(maxAge: number): Promise<number>;

View File

@ -214,6 +214,15 @@ var defaultFormatter = null;
var nextPollId = 1; var nextPollId = 1;
var BaseProvider = /** @class */ (function (_super) { var BaseProvider = /** @class */ (function (_super) {
__extends(BaseProvider, _super); __extends(BaseProvider, _super);
/**
* ready
*
* A Promise<Network> that resolves only once the provider is ready.
*
* Sub-classes that call the super with a network without a chainId
* MUST set this. Standard named networks have a known chainId.
*
*/
function BaseProvider(network) { function BaseProvider(network) {
var _newTarget = this.constructor; var _newTarget = this.constructor;
var _this = this; var _this = this;
@ -221,18 +230,14 @@ var BaseProvider = /** @class */ (function (_super) {
_this = _super.call(this) || this; _this = _super.call(this) || this;
_this.formatter = _newTarget.getFormatter(); _this.formatter = _newTarget.getFormatter();
if (network instanceof Promise) { if (network instanceof Promise) {
properties_1.defineReadOnly(_this, "ready", network.then(function (network) { _this._networkPromise = network;
properties_1.defineReadOnly(_this, "_network", network);
return network;
}));
// Squash any "unhandled promise" errors; that do not need to be handled // Squash any "unhandled promise" errors; that do not need to be handled
_this.ready.catch(function (error) { }); network.catch(function (error) { });
} }
else { else {
var knownNetwork = properties_1.getStatic((_newTarget), "getNetwork")(network); var knownNetwork = properties_1.getStatic((_newTarget), "getNetwork")(network);
if (knownNetwork) { if (knownNetwork) {
properties_1.defineReadOnly(_this, "_network", knownNetwork); properties_1.defineReadOnly(_this, "_network", knownNetwork);
properties_1.defineReadOnly(_this, "ready", Promise.resolve(_this._network));
} }
else { else {
logger.throwArgumentError("invalid network", "network", network); logger.throwArgumentError("invalid network", "network", network);
@ -247,6 +252,60 @@ var BaseProvider = /** @class */ (function (_super) {
_this._fastQueryDate = 0; _this._fastQueryDate = 0;
return _this; return _this;
} }
BaseProvider.prototype._ready = function () {
return __awaiter(this, void 0, void 0, function () {
var network, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this._network == null)) return [3 /*break*/, 7];
network = null;
if (!this._networkPromise) return [3 /*break*/, 4];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this._networkPromise];
case 2:
network = _a.sent();
return [3 /*break*/, 4];
case 3:
error_1 = _a.sent();
return [3 /*break*/, 4];
case 4:
if (!(network == null)) return [3 /*break*/, 6];
return [4 /*yield*/, this.detectNetwork()];
case 5:
network = _a.sent();
_a.label = 6;
case 6:
// This should never happen; every Provider sub-class should have
// suggested a network by here (or thrown).
if (!network) {
logger.throwError("no network detected", logger_1.Logger.errors.UNKNOWN_ERROR, {});
}
properties_1.defineReadOnly(this, "_network", network);
_a.label = 7;
case 7: return [2 /*return*/, this._network];
}
});
});
};
Object.defineProperty(BaseProvider.prototype, "ready", {
get: function () {
return this._ready();
},
enumerable: true,
configurable: true
});
BaseProvider.prototype.detectNetwork = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, logger.throwError("provider does not support network detection", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
operation: "provider.detectNetwork"
})];
});
});
};
BaseProvider.getFormatter = function () { BaseProvider.getFormatter = function () {
if (defaultFormatter == null) { if (defaultFormatter == null) {
defaultFormatter = new formatter_1.Formatter(); defaultFormatter = new formatter_1.Formatter();
@ -684,7 +743,7 @@ var BaseProvider = /** @class */ (function (_super) {
}; };
BaseProvider.prototype.sendTransaction = function (signedTransaction) { BaseProvider.prototype.sendTransaction = function (signedTransaction) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var hexTx, tx, hash, error_1; var hexTx, tx, hash, error_2;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: return [4 /*yield*/, this.ready]; case 0: return [4 /*yield*/, this.ready];
@ -702,10 +761,10 @@ var BaseProvider = /** @class */ (function (_super) {
hash = _a.sent(); hash = _a.sent();
return [2 /*return*/, this._wrapTransaction(tx, hash)]; return [2 /*return*/, this._wrapTransaction(tx, hash)];
case 5: case 5:
error_1 = _a.sent(); error_2 = _a.sent();
error_1.transaction = tx; error_2.transaction = tx;
error_1.transactionHash = tx.hash; error_2.transactionHash = tx.hash;
throw error_1; throw error_2;
case 6: return [2 /*return*/]; case 6: return [2 /*return*/];
} }
}); });
@ -843,7 +902,7 @@ var BaseProvider = /** @class */ (function (_super) {
}; };
BaseProvider.prototype._getBlock = function (blockHashOrBlockTag, includeTransactions) { BaseProvider.prototype._getBlock = function (blockHashOrBlockTag, includeTransactions) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var blockNumber, params, _a, _b, _c, error_2; var blockNumber, params, _a, _b, _c, error_3;
var _this = this; var _this = this;
return __generator(this, function (_d) { return __generator(this, function (_d) {
switch (_d.label) { switch (_d.label) {
@ -875,7 +934,7 @@ var BaseProvider = /** @class */ (function (_super) {
} }
return [3 /*break*/, 7]; return [3 /*break*/, 7];
case 6: case 6:
error_2 = _d.sent(); error_3 = _d.sent();
logger.throwArgumentError("invalid block hash or block tag", "blockHashOrBlockTag", blockHashOrBlockTag); logger.throwArgumentError("invalid block hash or block tag", "blockHashOrBlockTag", blockHashOrBlockTag);
return [3 /*break*/, 7]; return [3 /*break*/, 7];
case 7: return [2 /*return*/, web_1.poll(function () { return __awaiter(_this, void 0, void 0, function () { case 7: return [2 /*return*/, web_1.poll(function () { return __awaiter(_this, void 0, void 0, function () {

View File

@ -1,10 +1,11 @@
import { BlockTag, TransactionResponse } from "@ethersproject/abstract-provider"; import { BlockTag, TransactionResponse } from "@ethersproject/abstract-provider";
import { Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { BaseProvider } from "./base-provider"; import { BaseProvider } from "./base-provider";
export declare class EtherscanProvider extends BaseProvider { export declare class EtherscanProvider extends BaseProvider {
readonly baseUrl: string; readonly baseUrl: string;
readonly apiKey: string; readonly apiKey: string;
constructor(network?: Networkish, apiKey?: string); constructor(network?: Networkish, apiKey?: string);
detectNetwork(): Promise<Network>;
perform(method: string, params: any): Promise<any>; perform(method: string, params: any): Promise<any>;
getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>>; getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>>;
} }

View File

@ -150,6 +150,13 @@ var EtherscanProvider = /** @class */ (function (_super) {
properties_1.defineReadOnly(_this, "apiKey", apiKey || defaultApiKey); properties_1.defineReadOnly(_this, "apiKey", apiKey || defaultApiKey);
return _this; return _this;
} }
EtherscanProvider.prototype.detectNetwork = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.network];
});
});
};
EtherscanProvider.prototype.perform = function (method, params) { EtherscanProvider.prototype.perform = function (method, params) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var url, apiKey, get, _a, transaction, transaction, topic0, logs, txs, i, log, tx, _b; var url, apiKey, get, _a, transaction, transaction, topic0, logs, txs, i, log, tx, _b;

View File

@ -1,3 +1,4 @@
import { Network } from "@ethersproject/networks";
import { Provider } from "@ethersproject/abstract-provider"; import { Provider } from "@ethersproject/abstract-provider";
import { BaseProvider } from "./base-provider"; import { BaseProvider } from "./base-provider";
export interface FallbackProviderConfig { export interface FallbackProviderConfig {
@ -11,6 +12,7 @@ export declare class FallbackProvider extends BaseProvider {
readonly quorum: number; readonly quorum: number;
_highestBlockNumber: number; _highestBlockNumber: number;
constructor(providers: Array<Provider | FallbackProviderConfig>, quorum?: number); constructor(providers: Array<Provider | FallbackProviderConfig>, quorum?: number);
detectNetwork(): Promise<Network>;
perform(method: string, params: { perform(method: string, params: {
[name: string]: any; [name: string]: any;
}): Promise<any>; }): Promise<any>;

View File

@ -130,14 +130,27 @@ function serialize(value) {
// Next request ID to use for emitting debug info // Next request ID to use for emitting debug info
var nextRid = 1; var nextRid = 1;
; ;
// Returns a promise that delays for duration
function stall(duration) { function stall(duration) {
return new Promise(function (resolve) { var cancel = null;
var timer = setTimeout(resolve, duration); var timer = null;
if (timer.unref) { var promise = (new Promise(function (resolve) {
timer.unref(); cancel = function () {
} if (timer) {
}); clearTimeout(timer);
timer = null;
}
resolve();
};
timer = setTimeout(cancel, duration);
}));
var wait = function (func) {
promise = promise.then(func);
return promise;
};
function getPromise() {
return promise;
}
return { cancel: cancel, getPromise: getPromise, wait: wait };
} }
; ;
function exposeDebugConfig(config, now) { function exposeDebugConfig(config, now) {
@ -353,11 +366,7 @@ var FallbackProvider = /** @class */ (function (_super) {
_this = _super.call(this, network) || this; _this = _super.call(this, network) || this;
} }
else { else {
// The network won't be known until all child providers know _this = _super.call(this, _this.detectNetwork()) || this;
var ready = Promise.all(providerConfigs.map(function (c) { return c.provider.getNetwork(); })).then(function (networks) {
return checkNetworks(networks);
});
_this = _super.call(this, ready) || this;
} }
// Preserve a copy, so we do not get mutated // Preserve a copy, so we do not get mutated
properties_1.defineReadOnly(_this, "providerConfigs", Object.freeze(providerConfigs)); properties_1.defineReadOnly(_this, "providerConfigs", Object.freeze(providerConfigs));
@ -365,35 +374,48 @@ var FallbackProvider = /** @class */ (function (_super) {
_this._highestBlockNumber = -1; _this._highestBlockNumber = -1;
return _this; return _this;
} }
FallbackProvider.prototype.detectNetwork = function () {
return __awaiter(this, void 0, void 0, function () {
var networks;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(this.providerConfigs.map(function (c) { return c.provider.getNetwork(); }))];
case 1:
networks = _a.sent();
return [2 /*return*/, checkNetworks(networks)];
}
});
});
};
FallbackProvider.prototype.perform = function (method, params) { FallbackProvider.prototype.perform = function (method, params) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var processFunc, configs, i, first, _loop_1, this_1, state_1; var results, i_1, result, processFunc, configs, i, first, _loop_1, this_1, state_1;
var _this = this; var _this = this;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
// Sending transactions is special; always broadcast it to all backends if (!(method === "sendTransaction")) return [3 /*break*/, 2];
if (method === "sendTransaction") { return [4 /*yield*/, Promise.all(this.providerConfigs.map(function (c) {
return [2 /*return*/, Promise.all(this.providerConfigs.map(function (c) { return c.provider.sendTransaction(params.signedTransaction).then(function (result) {
return c.provider.sendTransaction(params.signedTransaction).then(function (result) { return result.hash;
return result.hash; }, function (error) {
}, function (error) { return error;
return error; });
}); }))];
})).then(function (results) { case 1:
// Any success is good enough (other errors are likely "already seen" errors results = _a.sent();
for (var i_1 = 0; i_1 < results.length; i_1++) { // Any success is good enough (other errors are likely "already seen" errors
var result = results[i_1]; for (i_1 = 0; i_1 < results.length; i_1++) {
if (typeof (result) === "string") { result = results[i_1];
return result; if (typeof (result) === "string") {
} return [2 /*return*/, result];
} }
// They were all an error; pick the first error
return Promise.reject(results[0]);
})];
} }
// They were all an error; pick the first error
throw results[0];
case 2:
processFunc = getProcessFunc(this, method, params); processFunc = getProcessFunc(this, method, params);
configs = random_1.shuffled(this.providerConfigs.map(function (c) { return properties_1.shallowCopy(c); })); configs = random_1.shuffled(this.providerConfigs.map(properties_1.shallowCopy));
configs.sort(function (a, b) { return (a.priority - b.priority); }); configs.sort(function (a, b) { return (a.priority - b.priority); });
i = 0; i = 0;
first = true; first = true;
@ -409,7 +431,8 @@ var FallbackProvider = /** @class */ (function (_super) {
var config = configs[i++]; var config = configs[i++];
var rid = nextRid++; var rid = nextRid++;
config.start = now(); config.start = now();
config.staller = stall(config.stallTimeout).then(function () { config.staller = null; }); 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, method, params).then(function (result) {
config.done = true; config.done = true;
config.result = result; config.result = result;
@ -435,7 +458,6 @@ var FallbackProvider = /** @class */ (function (_super) {
}); });
} }
}); });
//running.push(config);
if (this_1.listenerCount("debug")) { if (this_1.listenerCount("debug")) {
this_1.emit("debug", { this_1.emit("debug", {
action: "request", action: "request",
@ -458,7 +480,7 @@ var FallbackProvider = /** @class */ (function (_super) {
} }
waiting.push(c.runner); waiting.push(c.runner);
if (c.staller) { if (c.staller) {
waiting.push(c.staller); waiting.push(c.staller.getPromise());
} }
}); });
if (!waiting.length) return [3 /*break*/, 2]; if (!waiting.length) return [3 /*break*/, 2];
@ -471,10 +493,12 @@ var FallbackProvider = /** @class */ (function (_super) {
if (!(results.length >= this_1.quorum)) return [3 /*break*/, 5]; if (!(results.length >= this_1.quorum)) return [3 /*break*/, 5];
result = processFunc(results); result = processFunc(results);
if (result !== undefined) { if (result !== undefined) {
// Shut down any stallers
configs.filter(function (c) { return c.staller; }).forEach(function (c) { return c.staller.cancel(); });
return [2 /*return*/, { value: result }]; return [2 /*return*/, { value: result }];
} }
if (!!first) return [3 /*break*/, 4]; if (!!first) return [3 /*break*/, 4];
return [4 /*yield*/, stall(100)]; return [4 /*yield*/, stall(100).getPromise()];
case 3: case 3:
_a.sent(); _a.sent();
_a.label = 4; _a.label = 4;
@ -491,25 +515,28 @@ var FallbackProvider = /** @class */ (function (_super) {
}); });
}; };
this_1 = this; this_1 = this;
_a.label = 1; _a.label = 3;
case 1: case 3:
if (!true) return [3 /*break*/, 3]; if (!true) return [3 /*break*/, 5];
return [5 /*yield**/, _loop_1()]; return [5 /*yield**/, _loop_1()];
case 2: case 4:
state_1 = _a.sent(); state_1 = _a.sent();
if (typeof state_1 === "object") if (typeof state_1 === "object")
return [2 /*return*/, state_1.value]; return [2 /*return*/, state_1.value];
if (state_1 === "break") if (state_1 === "break")
return [3 /*break*/, 3]; return [3 /*break*/, 5];
return [3 /*break*/, 1]; return [3 /*break*/, 3];
case 3: return [2 /*return*/, logger.throwError("failed to meet quorum", logger_1.Logger.errors.SERVER_ERROR, { case 5:
method: method, // Shut down any stallers; shouldn't be any
params: params, configs.filter(function (c) { return c.staller; }).forEach(function (c) { return c.staller.cancel(); });
//results: configs.map((c) => c.result), return [2 /*return*/, logger.throwError("failed to meet quorum", logger_1.Logger.errors.SERVER_ERROR, {
//errors: configs.map((c) => c.error), method: method,
results: configs.map(function (c) { return exposeDebugConfig(c); }), params: params,
provider: this //results: configs.map((c) => c.result),
})]; //errors: configs.map((c) => c.error),
results: configs.map(function (c) { return exposeDebugConfig(c); }),
provider: this
})];
} }
}); });
}); });

View File

@ -1,9 +1,11 @@
import { Network } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { ConnectionInfo } from "@ethersproject/web"; import { ConnectionInfo } from "@ethersproject/web";
import { WebSocketProvider } from "./websocket-provider";
import { UrlJsonRpcProvider } from "./url-json-rpc-provider"; import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
export declare class InfuraProvider extends UrlJsonRpcProvider { export declare class InfuraProvider extends UrlJsonRpcProvider {
readonly projectId: string; readonly projectId: string;
readonly projectSecret: string; readonly projectSecret: string;
static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider;
static getApiKey(apiKey: any): any; static getApiKey(apiKey: any): any;
static getUrl(network: Network, apiKey: any): string | ConnectionInfo; static getUrl(network: Network, apiKey: any): string | ConnectionInfo;
} }

View File

@ -13,6 +13,7 @@ var __extends = (this && this.__extends) || (function () {
}; };
})(); })();
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
var websocket_provider_1 = require("./websocket-provider");
var logger_1 = require("@ethersproject/logger"); var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version"); var _version_1 = require("./_version");
var logger = new logger_1.Logger(_version_1.version); var logger = new logger_1.Logger(_version_1.version);
@ -23,6 +24,17 @@ var InfuraProvider = /** @class */ (function (_super) {
function InfuraProvider() { function InfuraProvider() {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
InfuraProvider.getWebSocketProvider = function (network, apiKey) {
var provider = new InfuraProvider(network, apiKey);
var connection = provider.connection;
if (connection.password) {
logger.throwError("INFURA WebSocket project secrets unsupported", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
operation: "InfuraProvider.getWebSocketProvider()"
});
}
var url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/");
return new websocket_provider_1.WebSocketProvider(url, network);
};
InfuraProvider.getApiKey = function (apiKey) { InfuraProvider.getApiKey = function (apiKey) {
var apiKeyObj = { var apiKeyObj = {
apiKey: defaultProjectId, apiKey: defaultProjectId,

View File

@ -1,7 +1,7 @@
import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider"; import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { Signer } from "@ethersproject/abstract-signer"; import { Signer } from "@ethersproject/abstract-signer";
import { Bytes } from "@ethersproject/bytes"; import { Bytes } from "@ethersproject/bytes";
import { Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { ConnectionInfo } from "@ethersproject/web"; import { ConnectionInfo } from "@ethersproject/web";
import { BaseProvider, Event } from "./base-provider"; import { BaseProvider, Event } from "./base-provider";
export declare class JsonRpcSigner extends Signer { export declare class JsonRpcSigner extends Signer {
@ -27,6 +27,7 @@ export declare class JsonRpcProvider extends BaseProvider {
_nextId: number; _nextId: number;
constructor(url?: ConnectionInfo | string, network?: Networkish); constructor(url?: ConnectionInfo | string, network?: Networkish);
static defaultUrl(): string; static defaultUrl(): string;
detectNetwork(): Promise<Network>;
getSigner(addressOrIndex?: string | number): JsonRpcSigner; getSigner(addressOrIndex?: string | number): JsonRpcSigner;
getUncheckedSigner(addressOrIndex?: string | number): UncheckedJsonRpcSigner; getUncheckedSigner(addressOrIndex?: string | number): UncheckedJsonRpcSigner;
listAccounts(): Promise<Array<string>>; listAccounts(): Promise<Array<string>>;

View File

@ -61,9 +61,7 @@ var logger = new logger_1.Logger(_version_1.version);
var base_provider_1 = require("./base-provider"); var base_provider_1 = require("./base-provider");
function timer(timeout) { function timer(timeout) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
setTimeout(function () { setTimeout(resolve, timeout);
resolve();
}, timeout);
}); });
} }
function getResult(payload) { function getResult(payload) {
@ -267,47 +265,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
} }
else { else {
// The network is unknown, query the JSON-RPC for it // The network is unknown, query the JSON-RPC for it
var ready = new Promise(function (resolve, reject) { _this = _super.call(this, _this.detectNetwork()) || this;
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
var chainId, error_1, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
chainId = null;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 8]);
return [4 /*yield*/, this.send("eth_chainId", [])];
case 2:
chainId = _a.sent();
return [3 /*break*/, 8];
case 3:
error_1 = _a.sent();
_a.label = 4;
case 4:
_a.trys.push([4, 6, , 7]);
return [4 /*yield*/, this.send("net_version", [])];
case 5:
chainId = _a.sent();
return [3 /*break*/, 7];
case 6:
error_2 = _a.sent();
return [3 /*break*/, 7];
case 7: return [3 /*break*/, 8];
case 8:
if (chainId != null) {
try {
return [2 /*return*/, resolve(getNetwork(bignumber_1.BigNumber.from(chainId).toNumber()))];
}
catch (error) { }
}
reject(logger.makeError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR));
return [2 /*return*/];
}
});
}); }, 0);
});
_this = _super.call(this, ready) || this;
} }
// Default URL // Default URL
if (!url) { if (!url) {
@ -327,6 +285,53 @@ var JsonRpcProvider = /** @class */ (function (_super) {
JsonRpcProvider.defaultUrl = function () { JsonRpcProvider.defaultUrl = function () {
return "http:/\/localhost:8545"; return "http:/\/localhost:8545";
}; };
JsonRpcProvider.prototype.detectNetwork = function () {
return __awaiter(this, void 0, void 0, function () {
var chainId, error_1, error_2, getNetwork;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, timer(0)];
case 1:
_a.sent();
chainId = null;
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 9]);
return [4 /*yield*/, this.send("eth_chainId", [])];
case 3:
chainId = _a.sent();
return [3 /*break*/, 9];
case 4:
error_1 = _a.sent();
_a.label = 5;
case 5:
_a.trys.push([5, 7, , 8]);
return [4 /*yield*/, this.send("net_version", [])];
case 6:
chainId = _a.sent();
return [3 /*break*/, 8];
case 7:
error_2 = _a.sent();
return [3 /*break*/, 8];
case 8: return [3 /*break*/, 9];
case 9:
if (chainId != null) {
getNetwork = properties_1.getStatic(this.constructor, "getNetwork");
try {
return [2 /*return*/, getNetwork(bignumber_1.BigNumber.from(chainId).toNumber())];
}
catch (error) {
return [2 /*return*/, logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR, {
chainId: chainId,
serverError: error
})];
}
}
return [2 /*return*/, logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR)];
}
});
});
};
JsonRpcProvider.prototype.getSigner = function (addressOrIndex) { JsonRpcProvider.prototype.getSigner = function (addressOrIndex) {
return new JsonRpcSigner(_constructorGuard, this, addressOrIndex); return new JsonRpcSigner(_constructorGuard, this, addressOrIndex);
}; };

View File

@ -4,6 +4,7 @@ import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
export declare abstract class UrlJsonRpcProvider extends JsonRpcProvider { export declare abstract class UrlJsonRpcProvider extends JsonRpcProvider {
readonly apiKey: any; readonly apiKey: any;
constructor(network?: Networkish, apiKey?: any); constructor(network?: Networkish, apiKey?: any);
detectNetwork(): Promise<Network>;
_startPending(): void; _startPending(): void;
getSigner(address?: string): JsonRpcSigner; getSigner(address?: string): JsonRpcSigner;
listAccounts(): Promise<Array<string>>; listAccounts(): Promise<Array<string>>;

View File

@ -12,6 +12,42 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
})(); })();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
var properties_1 = require("@ethersproject/properties"); var properties_1 = require("@ethersproject/properties");
var logger_1 = require("@ethersproject/logger"); var logger_1 = require("@ethersproject/logger");
@ -39,6 +75,13 @@ var UrlJsonRpcProvider = /** @class */ (function (_super) {
} }
return _this; return _this;
} }
UrlJsonRpcProvider.prototype.detectNetwork = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.network];
});
});
};
UrlJsonRpcProvider.prototype._startPending = function () { UrlJsonRpcProvider.prototype._startPending = function () {
logger.warn("WARNING: API provider does not support pending filters"); logger.warn("WARNING: API provider does not support pending filters");
}; };

View File

@ -96,11 +96,11 @@ var WebSocketProvider = /** @class */ (function (_super) {
_this._websocket.onmessage = function (messageEvent) { _this._websocket.onmessage = function (messageEvent) {
var data = messageEvent.data; var data = messageEvent.data;
var result = JSON.parse(data); var result = JSON.parse(data);
if (result.id) { if (result.id != null) {
var id = String(result.id); var id = String(result.id);
var request = _this._requests[id]; var request = _this._requests[id];
delete _this._requests[id]; delete _this._requests[id];
if (result.result) { if (result.result !== undefined) {
request.callback(null, result.result); request.callback(null, result.result);
} }
else { else {

View File

@ -56,7 +56,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"tarballHash": "0x1f418141b6b57ca25d4399fdab8eb941be425422a1ee37cefc764652f64aeb11", "tarballHash": "0xa23d77e6439556382bb60e82fc8ec1a3ba9504d90c381815ec813496cd497daa",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.165" "version": "5.0.0-beta.165"
} }

View File

@ -2,7 +2,8 @@
import assert from "assert"; import assert from "assert";
import { ethers } from "ethers"; import { ethers } from "ethers";
import contractData from "./test-contract.json"; import contractData from "./test-contract.json";
const provider = new ethers.providers.InfuraProvider('rinkeby'); //const provider = new ethers.providers.InfuraProvider('rinkeby');
const provider = ethers.getDefaultProvider("rinkeby");
const TIMEOUT_PERIOD = 120000; const TIMEOUT_PERIOD = 120000;
const contract = (function () { const contract = (function () {
return new ethers.Contract(contractData.contractAddress, contractData.interface, provider); return new ethers.Contract(contractData.contractAddress, contractData.interface, provider);

View File

@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
var assert_1 = __importDefault(require("assert")); var assert_1 = __importDefault(require("assert"));
var ethers_1 = require("ethers"); var ethers_1 = require("ethers");
var test_contract_json_1 = __importDefault(require("./test-contract.json")); var test_contract_json_1 = __importDefault(require("./test-contract.json"));
var provider = new ethers_1.ethers.providers.InfuraProvider('rinkeby'); //const provider = new ethers.providers.InfuraProvider('rinkeby');
var provider = ethers_1.ethers.getDefaultProvider("rinkeby");
var TIMEOUT_PERIOD = 120000; var TIMEOUT_PERIOD = 120000;
var contract = (function () { var contract = (function () {
return new ethers_1.ethers.Contract(test_contract_json_1.default.contractAddress, test_contract_json_1.default.interface, provider); return new ethers_1.ethers.Contract(test_contract_json_1.default.contractAddress, test_contract_json_1.default.interface, provider);

View File

@ -39,7 +39,7 @@
"scripts": { "scripts": {
"test": "exit 1" "test": "exit 1"
}, },
"tarballHash": "0x5dde69881b3dce2e3827d00926af541802a2b3995d55346fbeda99a4cb3b7dc0", "tarballHash": "0xac8cf0ee9074b69de2a45675de01bd995355f887a1daed7fadd95cc43195d1d8",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.158" "version": "5.0.0-beta.158"
} }

View File

@ -1 +1 @@
export declare const version = "web/5.0.0-beta.137"; export declare const version = "web/5.0.0-beta.138";

View File

@ -1 +1 @@
export const version = "web/5.0.0-beta.137"; export const version = "web/5.0.0-beta.138";

View File

@ -94,8 +94,13 @@ export function fetchJson(connection, json, processFunc) {
response = yield getUrl(url, options); response = yield getUrl(url, options);
} }
catch (error) { catch (error) {
console.log(error);
response = error.response; response = error.response;
if (response == null) {
logger.throwError("missing response", Logger.errors.SERVER_ERROR, {
serverError: error,
url: url
});
}
} }
let body = response.body; let body = response.body;
if (allow304 && response.statusCode === 304) { if (allow304 && response.statusCode === 304) {

View File

@ -1 +1 @@
export declare const version = "web/5.0.0-beta.137"; export declare const version = "web/5.0.0-beta.138";

View File

@ -1,3 +1,3 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "web/5.0.0-beta.137"; exports.version = "web/5.0.0-beta.138";

View File

@ -131,8 +131,13 @@ function fetchJson(connection, json, processFunc) {
return [3 /*break*/, 4]; return [3 /*break*/, 4];
case 3: case 3:
error_1 = _a.sent(); error_1 = _a.sent();
console.log(error_1);
response = error_1.response; response = error_1.response;
if (response == null) {
logger.throwError("missing response", logger_1.Logger.errors.SERVER_ERROR, {
serverError: error_1,
url: url
});
}
return [3 /*break*/, 4]; return [3 /*break*/, 4];
case 4: case 4:
body = response.body; body = response.body;

View File

@ -35,7 +35,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"tarballHash": "0x61705e91a9250f3d5b7cbf031c2aff7c41be3557228d156de9b27bed652ac282", "tarballHash": "0xb65d230f34fff51296199d36c8963829b38d278b9a14f0eefe8dd45f544a1b90",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"version": "5.0.0-beta.137" "version": "5.0.0-beta.138"
} }

View File

@ -1 +1 @@
export const version = "web/5.0.0-beta.137"; export const version = "web/5.0.0-beta.138";