ethers.js/packages/providers/lib.esm/pocket-provider.js

75 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-10-19 06:19:16 +03:00
"use strict";
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
2022-08-18 21:48:39 +03:00
const defaultApplicationId = "62e1ad51b37b8e00394bda3b";
2020-10-19 06:19:16 +03:00
export class PocketProvider extends UrlJsonRpcProvider {
static getApiKey(apiKey) {
const apiKeyObj = {
2021-02-03 01:32:11 +03:00
applicationId: null,
2022-08-18 21:48:39 +03:00
loadBalancer: true,
2020-10-19 06:19:16 +03:00
applicationSecretKey: null
};
// Parse applicationId and applicationSecretKey
2022-08-18 21:48:39 +03:00
if (apiKey == null) {
apiKeyObj.applicationId = defaultApplicationId;
}
else if (typeof (apiKey) === "string") {
2020-10-19 06:19:16 +03: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-03 01:32:11 +03:00
}
else {
logger.throwArgumentError("unsupported PocketProvider apiKey", "apiKey", apiKey);
2020-10-19 06:19:16 +03:00
}
return apiKeyObj;
}
static getUrl(network, apiKey) {
let host = null;
switch (network ? network.name : "unknown") {
2022-08-18 21:48:39 +03:00
case "goerli":
host = "eth-goerli.gateway.pokt.network";
break;
2020-10-19 06:19:16 +03:00
case "homestead":
host = "eth-mainnet.gateway.pokt.network";
break;
2022-08-18 21:48:39 +03: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-03 01:32:11 +03:00
break;
case "rinkeby":
host = "eth-rinkeby.gateway.pokt.network";
break;
2022-08-18 21:48:39 +03:00
case "ropsten":
host = "eth-ropsten.gateway.pokt.network";
2021-02-03 01:32:11 +03:00
break;
2020-10-19 06:19:16 +03:00
default:
logger.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
argument: "network",
value: network
});
}
2022-08-18 21:48:39 +03:00
const url = `https:/\/${host}/v1/lb/${apiKey.applicationId}`;
const connection = { headers: {}, url };
2020-10-19 06:19:16 +03:00
if (apiKey.applicationSecretKey != null) {
connection.user = "";
connection.password = apiKey.applicationSecretKey;
}
return connection;
}
isCommunityResource() {
2022-08-18 21:48:39 +03:00
return (this.applicationId === defaultApplicationId);
2020-10-19 06:19:16 +03:00
}
}
//# sourceMappingURL=pocket-provider.js.map