Updated dist files.
This commit is contained in:
parent
88c7eaed06
commit
6fa853b309
@ -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))
|
||||
|
4
packages/ethers/dist/ethers-all.esm.min.js
vendored
4
packages/ethers/dist/ethers-all.esm.min.js
vendored
File diff suppressed because one or more lines are too long
4
packages/ethers/dist/ethers-all.umd.min.js
vendored
4
packages/ethers/dist/ethers-all.umd.min.js
vendored
File diff suppressed because one or more lines are too long
217
packages/ethers/dist/ethers.esm.js
vendored
217
packages/ethers/dist/ethers.esm.js
vendored
@ -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
|
||||
@ -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) {
|
||||
for (let attempt = 0; attempt < attemptLimit; attempt++) {
|
||||
let response = null;
|
||||
try {
|
||||
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) {
|
||||
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("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) {
|
||||
try {
|
||||
json = JSON.parse(body);
|
||||
}
|
||||
catch (error) {
|
||||
logger$p.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
|
||||
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]);
|
||||
@ -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) {
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
@ -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,
|
||||
@ -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;
|
||||
@ -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,
|
||||
@ -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 = "";
|
||||
@ -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
|
||||
|
4
packages/ethers/dist/ethers.esm.min.js
vendored
4
packages/ethers/dist/ethers.esm.min.js
vendored
File diff suppressed because one or more lines are too long
179
packages/ethers/dist/ethers.umd.js
vendored
179
packages/ethers/dist/ethers.umd.js
vendored
@ -21306,7 +21306,16 @@
|
||||
|
||||
var logger = new lib.Logger(_version$G.version);
|
||||
|
||||
function staller(duration) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(resolve, duration);
|
||||
});
|
||||
}
|
||||
function fetchJson(connection, json, processFunc) {
|
||||
// How many times to retry in the event of a throttle
|
||||
var attemptLimit = (typeof (connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit : 12;
|
||||
logger.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), "invalid connection throttle limit", "connection.throttleLimit", attemptLimit);
|
||||
var throttleCallback = ((typeof (connection) === "object") ? connection.throttleCallback : null);
|
||||
var headers = {};
|
||||
var url = null;
|
||||
// @TODO: Allow ConnectionInfo to override some of these values
|
||||
@ -21385,19 +21394,37 @@
|
||||
})();
|
||||
var runningFetch = (function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var response, error_1, body, json, error_2;
|
||||
var attempt, response, tryAgain, timeout_1, error_1, body, json_1, error_2, tryAgain, timeout_2;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
response = null;
|
||||
attempt = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, browserGeturl.getUrl(url, options)];
|
||||
if (!(attempt < attemptLimit)) return [3 /*break*/, 19];
|
||||
response = null;
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
response = _a.sent();
|
||||
return [3 /*break*/, 4];
|
||||
_a.trys.push([2, 8, , 9]);
|
||||
return [4 /*yield*/, browserGeturl.getUrl(url, options)];
|
||||
case 3:
|
||||
response = _a.sent();
|
||||
if (!(response.statusCode === 429 && attempt < attemptLimit)) return [3 /*break*/, 7];
|
||||
tryAgain = true;
|
||||
if (!throttleCallback) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, throttleCallback(attempt, url)];
|
||||
case 4:
|
||||
tryAgain = _a.sent();
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
if (!tryAgain) return [3 /*break*/, 7];
|
||||
timeout_1 = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
||||
return [4 /*yield*/, staller(timeout_1)];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 18];
|
||||
case 7: return [3 /*break*/, 9];
|
||||
case 8:
|
||||
error_1 = _a.sent();
|
||||
response = error_1.response;
|
||||
if (response == null) {
|
||||
@ -21409,8 +21436,8 @@
|
||||
url: url
|
||||
});
|
||||
}
|
||||
return [3 /*break*/, 4];
|
||||
case 4:
|
||||
return [3 /*break*/, 9];
|
||||
case 9:
|
||||
body = response.body;
|
||||
if (allow304 && response.statusCode === 304) {
|
||||
body = null;
|
||||
@ -21426,13 +21453,13 @@
|
||||
url: url
|
||||
});
|
||||
}
|
||||
runningTimeout.cancel();
|
||||
json = null;
|
||||
json_1 = null;
|
||||
if (body != null) {
|
||||
try {
|
||||
json = JSON.parse(body);
|
||||
json_1 = JSON.parse(body);
|
||||
}
|
||||
catch (error) {
|
||||
runningTimeout.cancel();
|
||||
logger.throwError("invalid JSON", lib.Logger.errors.SERVER_ERROR, {
|
||||
body: body,
|
||||
error: error,
|
||||
@ -21442,25 +21469,47 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!processFunc) return [3 /*break*/, 8];
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
_a.trys.push([5, 7, , 8]);
|
||||
return [4 /*yield*/, processFunc(json, response)];
|
||||
case 6:
|
||||
json = _a.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7:
|
||||
if (!processFunc) return [3 /*break*/, 17];
|
||||
_a.label = 10;
|
||||
case 10:
|
||||
_a.trys.push([10, 12, , 17]);
|
||||
return [4 /*yield*/, processFunc(json_1, response)];
|
||||
case 11:
|
||||
json_1 = _a.sent();
|
||||
return [3 /*break*/, 17];
|
||||
case 12:
|
||||
error_2 = _a.sent();
|
||||
if (!(error_2.throttleRetry && attempt < attemptLimit)) return [3 /*break*/, 16];
|
||||
tryAgain = true;
|
||||
if (!throttleCallback) return [3 /*break*/, 14];
|
||||
return [4 /*yield*/, throttleCallback(attempt, url)];
|
||||
case 13:
|
||||
tryAgain = _a.sent();
|
||||
_a.label = 14;
|
||||
case 14:
|
||||
if (!tryAgain) return [3 /*break*/, 16];
|
||||
timeout_2 = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
||||
return [4 /*yield*/, staller(timeout_2)];
|
||||
case 15:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 18];
|
||||
case 16:
|
||||
runningTimeout.cancel();
|
||||
logger.throwError("processing response error", lib.Logger.errors.SERVER_ERROR, {
|
||||
body: json,
|
||||
body: json_1,
|
||||
error: error_2,
|
||||
requestBody: (options.body || null),
|
||||
requestMethod: options.method,
|
||||
url: url
|
||||
});
|
||||
return [3 /*break*/, 8];
|
||||
case 8: return [2 /*return*/, json];
|
||||
return [3 /*break*/, 17];
|
||||
case 17:
|
||||
runningTimeout.cancel();
|
||||
return [2 /*return*/, json_1];
|
||||
case 18:
|
||||
attempt++;
|
||||
return [3 /*break*/, 1];
|
||||
case 19: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -21954,11 +22003,33 @@
|
||||
return Formatter;
|
||||
}());
|
||||
exports.Formatter = Formatter;
|
||||
// Show the throttle message only once
|
||||
var 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("==========================");
|
||||
}
|
||||
exports.showThrottleMessage = showThrottleMessage;
|
||||
|
||||
});
|
||||
|
||||
var formatter$1 = unwrapExports(formatter);
|
||||
var formatter_1 = formatter.Formatter;
|
||||
var formatter_2 = formatter.showThrottleMessage;
|
||||
|
||||
var baseProvider = createCommonjsModule(function (module, exports) {
|
||||
"use strict";
|
||||
@ -24596,6 +24667,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
var logger = new lib.Logger(_version$I.version);
|
||||
|
||||
// This key was provided to ethers.js by Alchemy to be used by the
|
||||
@ -24644,7 +24716,15 @@
|
||||
default:
|
||||
logger.throwArgumentError("unsupported network", "network", arguments[0]);
|
||||
}
|
||||
return ("https:/" + "/" + host + apiKey);
|
||||
return {
|
||||
url: ("https:/" + "/" + host + apiKey),
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (apiKey === defaultApiKey) {
|
||||
formatter.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
};
|
||||
return AlchemyProvider;
|
||||
}(urlJsonRpcProvider.UrlJsonRpcProvider));
|
||||
@ -24815,6 +24895,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
var logger = new lib.Logger(_version$I.version);
|
||||
|
||||
// The transaction has already been sanitized by the calls in Provider
|
||||
@ -24838,14 +24919,23 @@
|
||||
return result.result;
|
||||
}
|
||||
if (result.status != 1 || result.message != "OK") {
|
||||
// @TODO: not any
|
||||
var 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) {
|
||||
var error = new Error("throttled response");
|
||||
error.result = JSON.stringify(result);
|
||||
error.throttleRetry = true;
|
||||
throw error;
|
||||
}
|
||||
if (result.jsonrpc != "2.0") {
|
||||
// @TODO: not any
|
||||
var error = new Error("invalid response");
|
||||
@ -24931,7 +25021,8 @@
|
||||
apiKey += "&apikey=" + this.apiKey;
|
||||
}
|
||||
get = function (url, procFunc) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var result;
|
||||
var connection, result;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
@ -24940,7 +25031,16 @@
|
||||
request: url,
|
||||
provider: this
|
||||
});
|
||||
return [4 /*yield*/, lib$l.fetchJson(url, null, procFunc || getJsonResult)];
|
||||
connection = {
|
||||
url: url,
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (_this.apiKey === defaultApiKey) {
|
||||
formatter.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
return [4 /*yield*/, lib$l.fetchJson(connection, null, procFunc || getJsonResult)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
this.emit("debug", {
|
||||
@ -24989,12 +25089,12 @@
|
||||
case 5:
|
||||
url += "/api?module=proxy&action=eth_getCode&address=" + params.address;
|
||||
url += "&tag=" + params.blockTag + apiKey;
|
||||
return [2 /*return*/, get(url, getJsonResult)];
|
||||
return [2 /*return*/, get(url)];
|
||||
case 6:
|
||||
url += "/api?module=proxy&action=eth_getStorageAt&address=" + params.address;
|
||||
url += "&position=" + params.position;
|
||||
url += "&tag=" + params.blockTag + apiKey;
|
||||
return [2 /*return*/, get(url, getJsonResult)];
|
||||
return [2 /*return*/, get(url)];
|
||||
case 7:
|
||||
url += "/api?module=proxy&action=eth_sendRawTransaction&hex=" + params.signedTransaction;
|
||||
url += apiKey;
|
||||
@ -25153,7 +25253,16 @@
|
||||
request: url,
|
||||
provider: _this
|
||||
});
|
||||
return lib$l.fetchJson(url, null, getResult).then(function (result) {
|
||||
var connection = {
|
||||
url: url,
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (_this.apiKey === defaultApiKey) {
|
||||
formatter.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
return lib$l.fetchJson(connection, null, getResult).then(function (result) {
|
||||
_this.emit("debug", {
|
||||
action: "response",
|
||||
request: url,
|
||||
@ -25863,6 +25972,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
var logger = new lib.Logger(_version$I.version);
|
||||
|
||||
var defaultProjectId = "84842078b09946638c03157f83405213";
|
||||
@ -25931,7 +26041,13 @@
|
||||
});
|
||||
}
|
||||
var connection = {
|
||||
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId)
|
||||
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId),
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (apiKey.projectId === defaultProjectId) {
|
||||
formatter.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
if (apiKey.projectSecret != null) {
|
||||
connection.user = "";
|
||||
@ -25949,6 +26065,7 @@
|
||||
var infuraProvider_1 = infuraProvider.InfuraProvider;
|
||||
|
||||
var nodesmithProvider = createCommonjsModule(function (module, exports) {
|
||||
/* istanbul ignore file */
|
||||
"use strict";
|
||||
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
|
4
packages/ethers/dist/ethers.umd.min.js
vendored
4
packages/ethers/dist/ethers.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -49,7 +49,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0xdc21b1ae12f84040ec07d56076f705cf5d89cc50fd555e70dd20c58c18f7aeed",
|
||||
"tarballHash": "0x930c9c8ccf1f6fcda0433634b0642e46949ddd18ea54063c3285047ed9945856",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.6"
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Network, Networkish } from "@ethersproject/networks";
|
||||
import { ConnectionInfo } from "@ethersproject/web";
|
||||
import { WebSocketProvider } from "./websocket-provider";
|
||||
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
||||
export declare class AlchemyProvider extends UrlJsonRpcProvider {
|
||||
readonly apiKey: string;
|
||||
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider;
|
||||
static getApiKey(apiKey: any): any;
|
||||
static getUrl(network: Network, apiKey: string): string;
|
||||
static getUrl(network: Network, apiKey: string): ConnectionInfo;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
import { showThrottleMessage } from "./formatter";
|
||||
import { WebSocketProvider } from "./websocket-provider";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
@ -46,7 +47,15 @@ export class AlchemyProvider extends UrlJsonRpcProvider {
|
||||
default:
|
||||
logger.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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=alchemy-provider.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"alchemy-provider.js","sourceRoot":"","sources":["../src.ts/alchemy-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAIb,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,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AAa,CAAC;SAAE;QAC7C,IAAI,MAAM,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;YACvC,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SACjE;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,OAAgB,EAAE,MAAc;QAC1C,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,QAAQ,OAAO,CAAC,IAAI,EAAE;YAClB,KAAK,WAAW;gBACZ,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,QAAQ;gBACT,IAAI,GAAG,8BAA8B,CAAC;gBACtC,MAAM;YACV,KAAK,OAAO;gBACR,IAAI,GAAG,6BAA6B,CAAC;gBACrC,MAAM;YACV;gBACG,MAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SAChF;QAED,OAAO;YACH,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,GAAG,MAAM,CAAC;YACtC,gBAAgB,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,MAAM,KAAK,aAAa,EAAE;oBAC1B,mBAAmB,EAAE,CAAC;iBACzB;gBACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;SACJ,CAAC;IACN,CAAC;CACJ"}
|
@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
import { hexlify, hexValue } from "@ethersproject/bytes";
|
||||
import { deepCopy, defineReadOnly } from "@ethersproject/properties";
|
||||
import { fetchJson } from "@ethersproject/web";
|
||||
import { showThrottleMessage } from "./formatter";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
@ -36,14 +37,23 @@ function getResult(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");
|
||||
@ -126,7 +136,16 @@ export 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) {
|
||||
showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
const result = yield fetchJson(connection, null, procFunc || getJsonResult);
|
||||
this.emit("debug", {
|
||||
action: "response",
|
||||
request: url,
|
||||
@ -154,12 +173,12 @@ export 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;
|
||||
@ -303,7 +322,16 @@ export class EtherscanProvider extends BaseProvider {
|
||||
request: url,
|
||||
provider: this
|
||||
});
|
||||
return fetchJson(url, null, getResult).then((result) => {
|
||||
const connection = {
|
||||
url: url,
|
||||
throttleCallback: (attempt, url) => {
|
||||
if (this.apiKey === defaultApiKey) {
|
||||
showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
return fetchJson(connection, null, getResult).then((result) => {
|
||||
this.emit("debug", {
|
||||
action: "response",
|
||||
request: url,
|
||||
|
File diff suppressed because one or more lines are too long
1
packages/providers/lib.esm/formatter.d.ts
vendored
1
packages/providers/lib.esm/formatter.d.ts
vendored
@ -48,3 +48,4 @@ export declare class Formatter {
|
||||
static allowFalsish(format: FormatFunc, replaceValue: any): FormatFunc;
|
||||
static arrayOf(format: FormatFunc): FormatFunc;
|
||||
}
|
||||
export declare function showThrottleMessage(): void;
|
||||
|
@ -380,4 +380,24 @@ export class Formatter {
|
||||
});
|
||||
}
|
||||
}
|
||||
// Show the throttle message only once
|
||||
let throttleMessage = false;
|
||||
export 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("==========================");
|
||||
}
|
||||
//# sourceMappingURL=formatter.js.map
|
File diff suppressed because one or more lines are too long
@ -7,5 +7,5 @@ export declare class InfuraProvider extends UrlJsonRpcProvider {
|
||||
readonly projectSecret: string;
|
||||
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider;
|
||||
static getApiKey(apiKey: any): any;
|
||||
static getUrl(network: Network, apiKey: any): string | ConnectionInfo;
|
||||
static getUrl(network: Network, apiKey: any): ConnectionInfo;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
import { WebSocketProvider } from "./websocket-provider";
|
||||
import { showThrottleMessage } from "./formatter";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
@ -66,7 +67,13 @@ export 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 = "";
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"infura-provider.js","sourceRoot":"","sources":["../src.ts/infura-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAKb,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,MAAM,gBAAgB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I,GAAG,mBAAmB,CAAC;gBAC3B,MAAM;YACV,KAAK,OAAO;gBACR,IAAI,GAAG,iBAAiB,CAAC;gBACzB,MAAM;YACV,KAAK,QAAQ;gBACT,IAAI,GAAG,kBAAkB,CAAC;gBAC1B,MAAM;YACV;gBACI,MAAM,CAAC,UAAU,CAAC,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE;oBACrE,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,OAAO;iBACjB,CAAC,CAAC;SACV;QAED,MAAM,UAAU,GAAmB;YAC9B,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;YACzD,gBAAgB,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE;gBAC/C,IAAI,MAAM,CAAC,SAAS,KAAK,gBAAgB,EAAE;oBACvC,mBAAmB,EAAE,CAAC;iBACzB;gBACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;SACL,CAAC;QAEF,IAAI,MAAM,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,UAAU,CAAC,IAAI,GAAG,EAAE,CAAC;YACrB,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAA;SAC7C;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ"}
|
@ -1,3 +1,4 @@
|
||||
/* istanbul ignore file */
|
||||
"use strict";
|
||||
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"nodesmith-provider.js","sourceRoot":"","sources":["../src.ts/nodesmith-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAA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providers/lib/alchemy-provider.d.ts
vendored
4
packages/providers/lib/alchemy-provider.d.ts
vendored
@ -1,9 +1,9 @@
|
||||
import { Network, Networkish } from "@ethersproject/networks";
|
||||
import { ConnectionInfo } from "@ethersproject/web";
|
||||
import { WebSocketProvider } from "./websocket-provider";
|
||||
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
||||
export declare class AlchemyProvider extends UrlJsonRpcProvider {
|
||||
readonly apiKey: string;
|
||||
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider;
|
||||
static getApiKey(apiKey: any): any;
|
||||
static getUrl(network: Network, apiKey: string): string;
|
||||
static getUrl(network: Network, apiKey: string): ConnectionInfo;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ var __extends = (this && this.__extends) || (function () {
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var formatter_1 = require("./formatter");
|
||||
var websocket_provider_1 = require("./websocket-provider");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
@ -64,7 +65,15 @@ var AlchemyProvider = /** @class */ (function (_super) {
|
||||
default:
|
||||
logger.throwArgumentError("unsupported network", "network", arguments[0]);
|
||||
}
|
||||
return ("https:/" + "/" + host + apiKey);
|
||||
return {
|
||||
url: ("https:/" + "/" + host + apiKey),
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (apiKey === defaultApiKey) {
|
||||
formatter_1.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
};
|
||||
return AlchemyProvider;
|
||||
}(url_json_rpc_provider_1.UrlJsonRpcProvider));
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"alchemy-provider.js","sourceRoot":"","sources":["../src.ts/alchemy-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAIb,2DAAyD;AAEzD,gDAA+C;AAC/C,uCAAqC;AACrC,IAAM,MAAM,GAAG,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,EAAE;YACvC,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SACjE;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAEM,sBAAM,GAAb,UAAc,OAAgB,EAAE,MAAc;QAC1C,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,QAAQ,OAAO,CAAC,IAAI,EAAE;YAClB,KAAK,WAAW;gBACZ,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,+BAA+B,CAAC;gBACvC,MAAM;YACV,KAAK,QAAQ;gBACT,IAAI,GAAG,8BAA8B,CAAC;gBACtC,MAAM;YACV,KAAK,OAAO;gBACR,IAAI,GAAG,6BAA6B,CAAC;gBACrC,MAAM;YACV;gBACG,MAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SAChF;QAED,OAAO;YACH,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,GAAG,MAAM,CAAC;YACtC,gBAAgB,EAAE,UAAC,OAAe,EAAE,GAAW;gBAC3C,IAAI,MAAM,KAAK,aAAa,EAAE;oBAC1B,+BAAmB,EAAE,CAAC;iBACzB;gBACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;SACJ,CAAC;IACN,CAAC;IACL,sBAAC;AAAD,CAAC,AAnDD,CAAqC,0CAAkB,GAmDtD;AAnDY,0CAAe"}
|
@ -52,6 +52,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var web_1 = require("@ethersproject/web");
|
||||
var formatter_1 = require("./formatter");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
@ -77,14 +78,23 @@ function getResult(result) {
|
||||
return result.result;
|
||||
}
|
||||
if (result.status != 1 || result.message != "OK") {
|
||||
// @TODO: not any
|
||||
var 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) {
|
||||
var error = new Error("throttled response");
|
||||
error.result = JSON.stringify(result);
|
||||
error.throttleRetry = true;
|
||||
throw error;
|
||||
}
|
||||
if (result.jsonrpc != "2.0") {
|
||||
// @TODO: not any
|
||||
var error = new Error("invalid response");
|
||||
@ -170,7 +180,8 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
apiKey += "&apikey=" + this.apiKey;
|
||||
}
|
||||
get = function (url, procFunc) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var result;
|
||||
var connection, result;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
@ -179,7 +190,16 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
request: url,
|
||||
provider: this
|
||||
});
|
||||
return [4 /*yield*/, web_1.fetchJson(url, null, procFunc || getJsonResult)];
|
||||
connection = {
|
||||
url: url,
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (_this.apiKey === defaultApiKey) {
|
||||
formatter_1.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
return [4 /*yield*/, web_1.fetchJson(connection, null, procFunc || getJsonResult)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
this.emit("debug", {
|
||||
@ -228,12 +248,12 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
case 5:
|
||||
url += "/api?module=proxy&action=eth_getCode&address=" + params.address;
|
||||
url += "&tag=" + params.blockTag + apiKey;
|
||||
return [2 /*return*/, get(url, getJsonResult)];
|
||||
return [2 /*return*/, get(url)];
|
||||
case 6:
|
||||
url += "/api?module=proxy&action=eth_getStorageAt&address=" + params.address;
|
||||
url += "&position=" + params.position;
|
||||
url += "&tag=" + params.blockTag + apiKey;
|
||||
return [2 /*return*/, get(url, getJsonResult)];
|
||||
return [2 /*return*/, get(url)];
|
||||
case 7:
|
||||
url += "/api?module=proxy&action=eth_sendRawTransaction&hex=" + params.signedTransaction;
|
||||
url += apiKey;
|
||||
@ -392,7 +412,16 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
request: url,
|
||||
provider: _this
|
||||
});
|
||||
return web_1.fetchJson(url, null, getResult).then(function (result) {
|
||||
var connection = {
|
||||
url: url,
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (_this.apiKey === defaultApiKey) {
|
||||
formatter_1.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
return web_1.fetchJson(connection, null, getResult).then(function (result) {
|
||||
_this.emit("debug", {
|
||||
action: "response",
|
||||
request: url,
|
||||
|
File diff suppressed because one or more lines are too long
1
packages/providers/lib/formatter.d.ts
vendored
1
packages/providers/lib/formatter.d.ts
vendored
@ -48,3 +48,4 @@ export declare class Formatter {
|
||||
static allowFalsish(format: FormatFunc, replaceValue: any): FormatFunc;
|
||||
static arrayOf(format: FormatFunc): FormatFunc;
|
||||
}
|
||||
export declare function showThrottleMessage(): void;
|
||||
|
@ -386,4 +386,25 @@ var Formatter = /** @class */ (function () {
|
||||
return Formatter;
|
||||
}());
|
||||
exports.Formatter = Formatter;
|
||||
// Show the throttle message only once
|
||||
var 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("==========================");
|
||||
}
|
||||
exports.showThrottleMessage = showThrottleMessage;
|
||||
//# sourceMappingURL=formatter.js.map
|
File diff suppressed because one or more lines are too long
2
packages/providers/lib/infura-provider.d.ts
vendored
2
packages/providers/lib/infura-provider.d.ts
vendored
@ -7,5 +7,5 @@ export declare class InfuraProvider extends UrlJsonRpcProvider {
|
||||
readonly projectSecret: string;
|
||||
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider;
|
||||
static getApiKey(apiKey: any): any;
|
||||
static getUrl(network: Network, apiKey: any): string | ConnectionInfo;
|
||||
static getUrl(network: Network, apiKey: any): ConnectionInfo;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ var __extends = (this && this.__extends) || (function () {
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var websocket_provider_1 = require("./websocket-provider");
|
||||
var formatter_1 = require("./formatter");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
@ -84,7 +85,13 @@ var InfuraProvider = /** @class */ (function (_super) {
|
||||
});
|
||||
}
|
||||
var connection = {
|
||||
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId)
|
||||
url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId),
|
||||
throttleCallback: function (attempt, url) {
|
||||
if (apiKey.projectId === defaultProjectId) {
|
||||
formatter_1.showThrottleMessage();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
if (apiKey.projectSecret != null) {
|
||||
connection.user = "";
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"infura-provider.js","sourceRoot":"","sources":["../src.ts/infura-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAKb,2DAAyD;AAEzD,gDAA+C;AAC/C,uCAAqC;AACrC,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CAAC;AAEnC,iEAA6D;AAG7D,IAAM,gBAAgB,GAAG,kCAAkC,CAAA;AAE3D;IAAoC,kCAAkB;IAAtD;;IAmFA,CAAC;IA/EU,mCAAoB,GAA3B,UAA4B,OAAoB,EAAE,MAAY;QAC1D,IAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,IAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,IAAI,UAAU,CAAC,QAAQ,EAAE;YACrB,MAAM,CAAC,UAAU,CAAC,8CAA8C,EAAE,eAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE;gBACnG,SAAS,EAAE,uCAAuC;aACrD,CAAC,CAAC;SACN;QAED,IAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC9E,OAAO,IAAI,sCAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAEM,wBAAS,GAAhB,UAAiB,MAAW;QACxB,IAAM,SAAS,GAAiE;YAC5E,MAAM,EAAE,gBAAgB;YACxB,SAAS,EAAE,gBAAgB;YAC3B,aAAa,EAAE,IAAI;SACtB,CAAC;QAEF,IAAI,MAAM,IAAI,IAAI,EAAE;YAAE,OAAO,SAAS,CAAC;SAAE;QAEzC,IAAI,OAAM,CAAC,MAAM,CAAC,KA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this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"nodesmith-provider.js","sourceRoot":"","sources":["../src.ts/nodesmith-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAGb,iEAA6D;AAE7D,gDAA+C;AAC/C,uCAAqC;AACrC,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CAAC;AAEnC,sDAAsD;AACtD,IAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC;IAAuC,qCAAkB;IAAzD;;IAmCA,CAAC;IAjCU,2BAAS,GAAhB,UAAiB,MAAW;QACxB,IAAI,MAAM,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;YACvC,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SACjE;QACD,OAAO,MAAM,IAAI,aAAa,CAAC;IACnC,CAAC;IAEM,wBAAM,GAAb,UAAc,OAAgB,EAAE,MAAY;QACxC,MAAM,CAAC,IAAI,CAAC,mFAAmF,CAAC,CAAC;QAEjG,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,QAAQ,OAAO,CAAC,IAAI,EAAE;YAClB,KAAK,WAAW;gBACZ,IAAI,GAAG,sDAAsD,CAAC;gBAC9D,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,sDAAsD,CAAC;gBAC9D,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,GAAG,sDAAsD,CAAC;gBAC9D,MAAM;YACV,KAAK,QAAQ;gBACT,IAAI,GAAG,qDAAqD,CAAC;gBAC7D,MAAM;YACV,KAAK,OAAO;gBACR,IAAI,GAAG,oDAAoD,CAAC;gBAC5D,MAAM;YACV;gBACG,MAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SAChF;QAED,OAAO,CAA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qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SAChF;QAED,OAAO,CAAC,IAAI,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;IACxC,CAAC;IACL,wBAAC;AAAD,CAAC,AAnCD,CAAuC,0CAAkB,GAmCxD;AAnCY,8CAAiB"}
|
@ -56,7 +56,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0x01ddbe7f91459e5c067071a0b87f2ff49951b11c8fb4144e5b83c760084a6879",
|
||||
"tarballHash": "0xb990b748245872f8bd26e2e711161e0896217bb2f5b8ea8c810481c0a5624c48",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.5"
|
||||
}
|
||||
|
7
packages/web/lib.esm/index.d.ts
vendored
7
packages/web/lib.esm/index.d.ts
vendored
@ -1,13 +1,14 @@
|
||||
export declare type ConnectionInfo = {
|
||||
url: string;
|
||||
headers?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
user?: string;
|
||||
password?: string;
|
||||
allowInsecureAuthentication?: boolean;
|
||||
throttleLimit?: number;
|
||||
throttleCallback?: (attempt: number, url: string) => Promise<boolean>;
|
||||
timeout?: number;
|
||||
headers?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
};
|
||||
export interface OnceBlockable {
|
||||
once(eventName: "block", handler: () => void): void;
|
||||
|
@ -15,7 +15,16 @@ import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
import { getUrl } from "./geturl";
|
||||
function staller(duration) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, duration);
|
||||
});
|
||||
}
|
||||
export 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.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
|
||||
@ -94,68 +103,96 @@ export function fetchJson(connection, json, processFunc) {
|
||||
})();
|
||||
const runningFetch = (function () {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let response = null;
|
||||
try {
|
||||
response = yield getUrl(url, options);
|
||||
}
|
||||
catch (error) {
|
||||
response = error.response;
|
||||
if (response == null) {
|
||||
for (let attempt = 0; attempt < attemptLimit; attempt++) {
|
||||
let response = null;
|
||||
try {
|
||||
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) {
|
||||
response = error.response;
|
||||
if (response == null) {
|
||||
runningTimeout.cancel();
|
||||
logger.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.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.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) {
|
||||
try {
|
||||
json = JSON.parse(body);
|
||||
}
|
||||
catch (error) {
|
||||
logger.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
|
||||
logger.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.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
|
||||
body: body,
|
||||
error: error,
|
||||
requestBody: (options.body || null),
|
||||
requestMethod: options.method,
|
||||
url: url
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
logger.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.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]);
|
||||
|
File diff suppressed because one or more lines are too long
7
packages/web/lib/index.d.ts
vendored
7
packages/web/lib/index.d.ts
vendored
@ -1,13 +1,14 @@
|
||||
export declare type ConnectionInfo = {
|
||||
url: string;
|
||||
headers?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
user?: string;
|
||||
password?: string;
|
||||
allowInsecureAuthentication?: boolean;
|
||||
throttleLimit?: number;
|
||||
throttleCallback?: (attempt: number, url: string) => Promise<boolean>;
|
||||
timeout?: number;
|
||||
headers?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
};
|
||||
export interface OnceBlockable {
|
||||
once(eventName: "block", handler: () => void): void;
|
||||
|
@ -43,7 +43,16 @@ var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var geturl_1 = require("./geturl");
|
||||
function staller(duration) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(resolve, duration);
|
||||
});
|
||||
}
|
||||
function fetchJson(connection, json, processFunc) {
|
||||
// How many times to retry in the event of a throttle
|
||||
var attemptLimit = (typeof (connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit : 12;
|
||||
logger.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), "invalid connection throttle limit", "connection.throttleLimit", attemptLimit);
|
||||
var throttleCallback = ((typeof (connection) === "object") ? connection.throttleCallback : null);
|
||||
var headers = {};
|
||||
var url = null;
|
||||
// @TODO: Allow ConnectionInfo to override some of these values
|
||||
@ -122,19 +131,37 @@ function fetchJson(connection, json, processFunc) {
|
||||
})();
|
||||
var runningFetch = (function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var response, error_1, body, json, error_2;
|
||||
var attempt, response, tryAgain, timeout_1, error_1, body, json_1, error_2, tryAgain, timeout_2;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
response = null;
|
||||
attempt = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, geturl_1.getUrl(url, options)];
|
||||
if (!(attempt < attemptLimit)) return [3 /*break*/, 19];
|
||||
response = null;
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
response = _a.sent();
|
||||
return [3 /*break*/, 4];
|
||||
_a.trys.push([2, 8, , 9]);
|
||||
return [4 /*yield*/, geturl_1.getUrl(url, options)];
|
||||
case 3:
|
||||
response = _a.sent();
|
||||
if (!(response.statusCode === 429 && attempt < attemptLimit)) return [3 /*break*/, 7];
|
||||
tryAgain = true;
|
||||
if (!throttleCallback) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, throttleCallback(attempt, url)];
|
||||
case 4:
|
||||
tryAgain = _a.sent();
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
if (!tryAgain) return [3 /*break*/, 7];
|
||||
timeout_1 = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
||||
return [4 /*yield*/, staller(timeout_1)];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 18];
|
||||
case 7: return [3 /*break*/, 9];
|
||||
case 8:
|
||||
error_1 = _a.sent();
|
||||
response = error_1.response;
|
||||
if (response == null) {
|
||||
@ -146,8 +173,8 @@ function fetchJson(connection, json, processFunc) {
|
||||
url: url
|
||||
});
|
||||
}
|
||||
return [3 /*break*/, 4];
|
||||
case 4:
|
||||
return [3 /*break*/, 9];
|
||||
case 9:
|
||||
body = response.body;
|
||||
if (allow304 && response.statusCode === 304) {
|
||||
body = null;
|
||||
@ -163,13 +190,13 @@ function fetchJson(connection, json, processFunc) {
|
||||
url: url
|
||||
});
|
||||
}
|
||||
runningTimeout.cancel();
|
||||
json = null;
|
||||
json_1 = null;
|
||||
if (body != null) {
|
||||
try {
|
||||
json = JSON.parse(body);
|
||||
json_1 = JSON.parse(body);
|
||||
}
|
||||
catch (error) {
|
||||
runningTimeout.cancel();
|
||||
logger.throwError("invalid JSON", logger_1.Logger.errors.SERVER_ERROR, {
|
||||
body: body,
|
||||
error: error,
|
||||
@ -179,25 +206,47 @@ function fetchJson(connection, json, processFunc) {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!processFunc) return [3 /*break*/, 8];
|
||||
_a.label = 5;
|
||||
case 5:
|
||||
_a.trys.push([5, 7, , 8]);
|
||||
return [4 /*yield*/, processFunc(json, response)];
|
||||
case 6:
|
||||
json = _a.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7:
|
||||
if (!processFunc) return [3 /*break*/, 17];
|
||||
_a.label = 10;
|
||||
case 10:
|
||||
_a.trys.push([10, 12, , 17]);
|
||||
return [4 /*yield*/, processFunc(json_1, response)];
|
||||
case 11:
|
||||
json_1 = _a.sent();
|
||||
return [3 /*break*/, 17];
|
||||
case 12:
|
||||
error_2 = _a.sent();
|
||||
if (!(error_2.throttleRetry && attempt < attemptLimit)) return [3 /*break*/, 16];
|
||||
tryAgain = true;
|
||||
if (!throttleCallback) return [3 /*break*/, 14];
|
||||
return [4 /*yield*/, throttleCallback(attempt, url)];
|
||||
case 13:
|
||||
tryAgain = _a.sent();
|
||||
_a.label = 14;
|
||||
case 14:
|
||||
if (!tryAgain) return [3 /*break*/, 16];
|
||||
timeout_2 = 100 * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
||||
return [4 /*yield*/, staller(timeout_2)];
|
||||
case 15:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 18];
|
||||
case 16:
|
||||
runningTimeout.cancel();
|
||||
logger.throwError("processing response error", logger_1.Logger.errors.SERVER_ERROR, {
|
||||
body: json,
|
||||
body: json_1,
|
||||
error: error_2,
|
||||
requestBody: (options.body || null),
|
||||
requestMethod: options.method,
|
||||
url: url
|
||||
});
|
||||
return [3 /*break*/, 8];
|
||||
case 8: return [2 /*return*/, json];
|
||||
return [3 /*break*/, 17];
|
||||
case 17:
|
||||
runningTimeout.cancel();
|
||||
return [2 /*return*/, json_1];
|
||||
case 18:
|
||||
attempt++;
|
||||
return [3 /*break*/, 1];
|
||||
case 19: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
@ -35,7 +35,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0x374c4de15f58beb22df5089f1172ecec515d62de34eae1cdd5917359c4ca74b0",
|
||||
"tarballHash": "0xc22676625b8063465d9d8d59169c0beb6eaeb70af3743d98fc8f2b4d826a70c8",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.2"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user