1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.AnkrProvider = void 0;
|
19 | var formatter_1 = require("./formatter");
|
20 | var url_json_rpc_provider_1 = require("./url-json-rpc-provider");
|
21 | var logger_1 = require("@ethersproject/logger");
|
22 | var _version_1 = require("./_version");
|
23 | var logger = new logger_1.Logger(_version_1.version);
|
24 | var defaultApiKey = "9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972";
|
25 | function getHost(name) {
|
26 | switch (name) {
|
27 | case "homestead":
|
28 | return "rpc.ankr.com/eth/";
|
29 | case "ropsten":
|
30 | return "rpc.ankr.com/eth_ropsten/";
|
31 | case "rinkeby":
|
32 | return "rpc.ankr.com/eth_rinkeby/";
|
33 | case "goerli":
|
34 | return "rpc.ankr.com/eth_goerli/";
|
35 | case "matic":
|
36 | return "rpc.ankr.com/polygon/";
|
37 | case "arbitrum":
|
38 | return "rpc.ankr.com/arbitrum/";
|
39 | }
|
40 | return logger.throwArgumentError("unsupported network", "name", name);
|
41 | }
|
42 | var AnkrProvider = (function (_super) {
|
43 | __extends(AnkrProvider, _super);
|
44 | function AnkrProvider() {
|
45 | return _super !== null && _super.apply(this, arguments) || this;
|
46 | }
|
47 | AnkrProvider.prototype.isCommunityResource = function () {
|
48 | return (this.apiKey === defaultApiKey);
|
49 | };
|
50 | AnkrProvider.getApiKey = function (apiKey) {
|
51 | if (apiKey == null) {
|
52 | return defaultApiKey;
|
53 | }
|
54 | return apiKey;
|
55 | };
|
56 | AnkrProvider.getUrl = function (network, apiKey) {
|
57 | if (apiKey == null) {
|
58 | apiKey = defaultApiKey;
|
59 | }
|
60 | var connection = {
|
61 | allowGzip: true,
|
62 | url: ("https:/\/" + getHost(network.name) + apiKey),
|
63 | throttleCallback: function (attempt, url) {
|
64 | if (apiKey.apiKey === defaultApiKey) {
|
65 | (0, formatter_1.showThrottleMessage)();
|
66 | }
|
67 | return Promise.resolve(true);
|
68 | }
|
69 | };
|
70 | if (apiKey.projectSecret != null) {
|
71 | connection.user = "";
|
72 | connection.password = apiKey.projectSecret;
|
73 | }
|
74 | return connection;
|
75 | };
|
76 | return AnkrProvider;
|
77 | }(url_json_rpc_provider_1.UrlJsonRpcProvider));
|
78 | exports.AnkrProvider = AnkrProvider;
|
79 |
|
\ | No newline at end of file |