Skip to content

Commit

Permalink
Updated dist files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 14, 2020
1 parent 88c7eae commit 6fa853b
Show file tree
Hide file tree
Showing 42 changed files with 651 additions and 212 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ Changelog

This change log is managed by `scripts/cmds/update-versions` but may be manually updated.

ethers/v5.0.6 (2020-07-13 09:34)
ethers/v5.0.6 (2020-07-14 02:32)
--------------------------------

- Added initial throttling support. ([#139](https://github.com/ethers-io/ethers.js/issues/139), [#904](https://github.com/ethers-io/ethers.js/issues/904), [#926](https://github.com/ethers-io/ethers.js/issues/926); [88c7eae](https://github.com/ethers-io/ethers.js/commit/88c7eaed061ae9a6798733a97e4e87011d36b8e7))
- Use status code 1000 on WebSocket hangup for compatibility. ([588f64c](https://github.com/ethers-io/ethers.js/commit/588f64c760ee49bfb5109bfbaafb4beafe41c52a))
- Updated WebSocketProvider to use web-style event listener API. ([57fd6f0](https://github.com/ethers-io/ethers.js/commit/57fd6f06047a1a2a3a46fe8b23ff585293a40062))
- Normalize formatUnits to simplified decimals. ([79b1da1](https://github.com/ethers-io/ethers.js/commit/79b1da130be50df80c7e5aeb221edc5669fc211e))
Expand Down
4 changes: 2 additions & 2 deletions packages/ethers/dist/ethers-all.esm.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ethers/dist/ethers-all.umd.min.js

Large diffs are not rendered by default.

213 changes: 156 additions & 57 deletions packages/ethers/dist/ethers.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19448,7 +19448,16 @@ var __awaiter$5 = (window && window.__awaiter) || function (thisArg, _arguments,
});
};
const logger$p = new Logger(version$l);
function staller(duration) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
});
}
function fetchJson(connection, json, processFunc) {
// How many times to retry in the event of a throttle
const attemptLimit = (typeof (connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit : 12;
logger$p.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), "invalid connection throttle limit", "connection.throttleLimit", attemptLimit);
const throttleCallback = ((typeof (connection) === "object") ? connection.throttleCallback : null);
const headers = {};
let url = null;
// @TODO: Allow ConnectionInfo to override some of these values
Expand Down Expand Up @@ -19527,68 +19536,96 @@ function fetchJson(connection, json, processFunc) {
})();
const runningFetch = (function () {
return __awaiter$5(this, void 0, void 0, function* () {
let response = null;
try {
response = yield getUrl(url, options);
}
catch (error) {
response = error.response;
if (response == null) {
runningTimeout.cancel();
logger$p.throwError("missing response", Logger.errors.SERVER_ERROR, {
requestBody: (options.body || null),
requestMethod: options.method,
serverError: error,
url: url
});
}
}
let body = response.body;
if (allow304 && response.statusCode === 304) {
body = null;
}
else if (response.statusCode < 200 || response.statusCode >= 300) {
runningTimeout.cancel();
logger$p.throwError("bad response", Logger.errors.SERVER_ERROR, {
status: response.statusCode,
headers: response.headers,
body: body,
requestBody: (options.body || null),
requestMethod: options.method,
url: url
});
}
runningTimeout.cancel();
let json = null;
if (body != null) {
for (let attempt = 0; attempt < attemptLimit; attempt++) {
let response = null;
try {
json = JSON.parse(body);
response = yield getUrl(url, options);
// Exponential back-off throttling (interval = 100ms)
if (response.statusCode === 429 && attempt < attemptLimit) {
let tryAgain = true;
if (throttleCallback) {
tryAgain = yield throttleCallback(attempt, url);
}
if (tryAgain) {
const timeout = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
yield staller(timeout);
continue;
}
}
}
catch (error) {
logger$p.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
response = error.response;
if (response == null) {
runningTimeout.cancel();
logger$p.throwError("missing response", Logger.errors.SERVER_ERROR, {
requestBody: (options.body || null),
requestMethod: options.method,
serverError: error,
url: url
});
}
}
let body = response.body;
if (allow304 && response.statusCode === 304) {
body = null;
}
else if (response.statusCode < 200 || response.statusCode >= 300) {
runningTimeout.cancel();
logger$p.throwError("bad response", Logger.errors.SERVER_ERROR, {
status: response.statusCode,
headers: response.headers,
body: body,
error: error,
requestBody: (options.body || null),
requestMethod: options.method,
url: url
});
}
}
if (processFunc) {
try {
json = yield processFunc(json, response);
let json = null;
if (body != null) {
try {
json = JSON.parse(body);
}
catch (error) {
runningTimeout.cancel();
logger$p.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
body: body,
error: error,
requestBody: (options.body || null),
requestMethod: options.method,
url: url
});
}
}
catch (error) {
logger$p.throwError("processing response error", Logger.errors.SERVER_ERROR, {
body: json,
error: error,
requestBody: (options.body || null),
requestMethod: options.method,
url: url
});
if (processFunc) {
try {
json = yield processFunc(json, response);
}
catch (error) {
// Allow the processFunc to trigger a throttle
if (error.throttleRetry && attempt < attemptLimit) {
let tryAgain = true;
if (throttleCallback) {
tryAgain = yield throttleCallback(attempt, url);
}
if (tryAgain) {
const timeout = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
yield staller(timeout);
continue;
}
}
runningTimeout.cancel();
logger$p.throwError("processing response error", Logger.errors.SERVER_ERROR, {
body: json,
error: error,
requestBody: (options.body || null),
requestMethod: options.method,
url: url
});
}
}
runningTimeout.cancel();
return json;
}
return json;
});
})();
return Promise.race([runningTimeout.promise, runningFetch]);
Expand Down Expand Up @@ -20049,6 +20086,26 @@ class Formatter {
});
}
}
// Show the throttle message only once
let throttleMessage = false;
function showThrottleMessage() {
if (throttleMessage) {
return;
}
throttleMessage = true;
console.log("========= NOTICE =========");
console.log("Request-Rate Exceeded (this message will not be repeated)");
console.log("");
console.log("The default API keys for each service are provided as a highly-throttled,");
console.log("community resource for low-traffic projects and early prototyping.");
console.log("");
console.log("While your application will continue to function, we highly recommended");
console.log("signing up for your own API keys to improve performance, increase your");
console.log("request rate/limit and enable other perks, such as metrics and advanced APIs.");
console.log("");
console.log("For more details: https:/\/docs.ethers.io/api-keys/");
console.log("==========================");
}

"use strict";
var __awaiter$6 = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -22050,7 +22107,15 @@ class AlchemyProvider extends UrlJsonRpcProvider {
default:
logger$v.throwArgumentError("unsupported network", "network", arguments[0]);
}
return ("https:/" + "/" + host + apiKey);
return {
url: ("https:/" + "/" + host + apiKey),
throttleCallback: (attempt, url) => {
if (apiKey === defaultApiKey) {
showThrottleMessage();
}
return Promise.resolve(true);
}
};
}
}

Expand Down Expand Up @@ -22131,14 +22196,23 @@ function getResult$1(result) {
return result.result;
}
if (result.status != 1 || result.message != "OK") {
// @TODO: not any
const error = new Error("invalid response");
error.result = JSON.stringify(result);
if ((result.result || "").toLowerCase().indexOf("rate limit") >= 0) {
error.throttleRetry = true;
}
throw error;
}
return result.result;
}
function getJsonResult(result) {
// This response indicates we are being throttled
if (result && result.status == 0 && result.message == "NOTOK" && (result.result || "").toLowerCase().indexOf("rate limit") >= 0) {
const error = new Error("throttled response");
error.result = JSON.stringify(result);
error.throttleRetry = true;
throw error;
}
if (result.jsonrpc != "2.0") {
// @TODO: not any
const error = new Error("invalid response");
Expand Down Expand Up @@ -22221,7 +22295,16 @@ class EtherscanProvider extends BaseProvider {
request: url,
provider: this
});
const result = yield fetchJson(url, null, procFunc || getJsonResult);
const connection = {
url: url,
throttleCallback: (attempt, url) => {
if (this.apiKey === defaultApiKey$1) {
showThrottleMessage();
}
return Promise.resolve(true);
}
};
const result = yield fetchJson(connection, null, procFunc || getJsonResult);
this.emit("debug", {
action: "response",
request: url,
Expand Down Expand Up @@ -22249,12 +22332,12 @@ class EtherscanProvider extends BaseProvider {
case "getCode":
url += "/api?module=proxy&action=eth_getCode&address=" + params.address;
url += "&tag=" + params.blockTag + apiKey;
return get(url, getJsonResult);
return get(url);
case "getStorageAt":
url += "/api?module=proxy&action=eth_getStorageAt&address=" + params.address;
url += "&position=" + params.position;
url += "&tag=" + params.blockTag + apiKey;
return get(url, getJsonResult);
return get(url);
case "sendTransaction":
url += "/api?module=proxy&action=eth_sendRawTransaction&hex=" + params.signedTransaction;
url += apiKey;
Expand Down Expand Up @@ -22398,7 +22481,16 @@ class EtherscanProvider extends BaseProvider {
request: url,
provider: this
});
return fetchJson(url, null, getResult$1).then((result) => {
const connection = {
url: url,
throttleCallback: (attempt, url) => {
if (this.apiKey === defaultApiKey$1) {
showThrottleMessage();
}
return Promise.resolve(true);
}
};
return fetchJson(connection, null, getResult$1).then((result) => {
this.emit("debug", {
action: "response",
request: url,
Expand Down Expand Up @@ -23018,7 +23110,13 @@ class InfuraProvider extends UrlJsonRpcProvider {
});
}
const connection = {
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId)
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId),
throttleCallback: (attempt, url) => {
if (apiKey.projectId === defaultProjectId) {
showThrottleMessage();
}
return Promise.resolve(true);
}
};
if (apiKey.projectSecret != null) {
connection.user = "";
Expand All @@ -23028,6 +23126,7 @@ class InfuraProvider extends UrlJsonRpcProvider {
}
}

/* istanbul ignore file */
"use strict";
const logger$A = new Logger(version$m);
// Special API key provided by Nodesmith for ethers.js
Expand Down
4 changes: 2 additions & 2 deletions packages/ethers/dist/ethers.esm.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6fa853b

Please sign in to comment.