2020-10-18 23:19:16 -04:00
|
|
|
"use strict";
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
2021-03-07 18:24:04 -05:00
|
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
2020-10-18 23:19:16 -04:00
|
|
|
return extendStatics(d, b);
|
|
|
|
};
|
|
|
|
return function (d, b) {
|
2021-03-07 18:24:04 -05:00
|
|
|
if (typeof b !== "function" && b !== null)
|
|
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
2020-10-18 23:19:16 -04:00
|
|
|
extendStatics(d, b);
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2021-03-07 18:24:04 -05:00
|
|
|
exports.PocketProvider = void 0;
|
2020-10-18 23:19:16 -04:00
|
|
|
var logger_1 = require("@ethersproject/logger");
|
|
|
|
var _version_1 = require("./_version");
|
|
|
|
var logger = new logger_1.Logger(_version_1.version);
|
|
|
|
var url_json_rpc_provider_1 = require("./url-json-rpc-provider");
|
2022-08-18 14:48:39 -04:00
|
|
|
var defaultApplicationId = "62e1ad51b37b8e00394bda3b";
|
2020-10-18 23:19:16 -04:00
|
|
|
var PocketProvider = /** @class */ (function (_super) {
|
|
|
|
__extends(PocketProvider, _super);
|
2022-08-18 14:48:39 -04:00
|
|
|
function PocketProvider() {
|
|
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
2020-10-18 23:19:16 -04:00
|
|
|
}
|
|
|
|
PocketProvider.getApiKey = function (apiKey) {
|
|
|
|
var apiKeyObj = {
|
2021-02-02 17:32:11 -05:00
|
|
|
applicationId: null,
|
2022-08-18 14:48:39 -04:00
|
|
|
loadBalancer: true,
|
2020-10-18 23:19:16 -04:00
|
|
|
applicationSecretKey: null
|
|
|
|
};
|
|
|
|
// Parse applicationId and applicationSecretKey
|
2022-08-18 14:48:39 -04:00
|
|
|
if (apiKey == null) {
|
|
|
|
apiKeyObj.applicationId = defaultApplicationId;
|
|
|
|
}
|
|
|
|
else if (typeof (apiKey) === "string") {
|
2020-10-18 23:19:16 -04:00
|
|
|
apiKeyObj.applicationId = apiKey;
|
|
|
|
}
|
|
|
|
else if (apiKey.applicationSecretKey != null) {
|
|
|
|
apiKeyObj.applicationId = apiKey.applicationId;
|
|
|
|
apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
|
|
|
|
}
|
|
|
|
else if (apiKey.applicationId) {
|
|
|
|
apiKeyObj.applicationId = apiKey.applicationId;
|
2021-02-02 17:32:11 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
logger.throwArgumentError("unsupported PocketProvider apiKey", "apiKey", apiKey);
|
2020-10-18 23:19:16 -04:00
|
|
|
}
|
|
|
|
return apiKeyObj;
|
|
|
|
};
|
|
|
|
PocketProvider.getUrl = function (network, apiKey) {
|
|
|
|
var host = null;
|
|
|
|
switch (network ? network.name : "unknown") {
|
2022-08-18 14:48:39 -04:00
|
|
|
case "goerli":
|
|
|
|
host = "eth-goerli.gateway.pokt.network";
|
|
|
|
break;
|
2020-10-18 23:19:16 -04:00
|
|
|
case "homestead":
|
|
|
|
host = "eth-mainnet.gateway.pokt.network";
|
|
|
|
break;
|
2022-08-18 14:48:39 -04:00
|
|
|
case "kovan":
|
|
|
|
host = "poa-kovan.gateway.pokt.network";
|
|
|
|
break;
|
|
|
|
case "matic":
|
|
|
|
host = "poly-mainnet.gateway.pokt.network";
|
|
|
|
break;
|
|
|
|
case "maticmum":
|
|
|
|
host = "polygon-mumbai-rpc.gateway.pokt.network";
|
2021-02-02 17:32:11 -05:00
|
|
|
break;
|
|
|
|
case "rinkeby":
|
|
|
|
host = "eth-rinkeby.gateway.pokt.network";
|
|
|
|
break;
|
2022-08-18 14:48:39 -04:00
|
|
|
case "ropsten":
|
|
|
|
host = "eth-ropsten.gateway.pokt.network";
|
2021-02-02 17:32:11 -05:00
|
|
|
break;
|
2020-10-18 23:19:16 -04:00
|
|
|
default:
|
|
|
|
logger.throwError("unsupported network", logger_1.Logger.errors.INVALID_ARGUMENT, {
|
|
|
|
argument: "network",
|
|
|
|
value: network
|
|
|
|
});
|
|
|
|
}
|
2022-08-18 14:48:39 -04:00
|
|
|
var url = "https://" + host + "/v1/lb/" + apiKey.applicationId;
|
|
|
|
var connection = { headers: {}, url: url };
|
2020-10-18 23:19:16 -04:00
|
|
|
if (apiKey.applicationSecretKey != null) {
|
|
|
|
connection.user = "";
|
|
|
|
connection.password = apiKey.applicationSecretKey;
|
|
|
|
}
|
|
|
|
return connection;
|
|
|
|
};
|
|
|
|
PocketProvider.prototype.isCommunityResource = function () {
|
2022-08-18 14:48:39 -04:00
|
|
|
return (this.applicationId === defaultApplicationId);
|
2020-10-18 23:19:16 -04:00
|
|
|
};
|
|
|
|
return PocketProvider;
|
|
|
|
}(url_json_rpc_provider_1.UrlJsonRpcProvider));
|
|
|
|
exports.PocketProvider = PocketProvider;
|
|
|
|
//# sourceMappingURL=pocket-provider.js.map
|