ethers.js/packages/providers/lib/index.js

100 lines
7.7 KiB
JavaScript
Raw Permalink Normal View History

2019-05-14 18:48:48 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2024-02-23 22:30:55 -05:00
exports.Formatter = exports.showThrottleMessage = exports.isCommunityResourcable = exports.isCommunityResource = exports.getNetwork = exports.getDefaultProvider = exports.JsonRpcSigner = exports.IpcProvider = exports.WebSocketProvider = exports.Web3Provider = exports.StaticJsonRpcProvider = exports.QuickNodeProvider = exports.PocketProvider = exports.NodesmithProvider = exports.JsonRpcBatchProvider = exports.JsonRpcProvider = exports.InfuraWebSocketProvider = exports.InfuraProvider = exports.EtherscanProvider = exports.CloudflareProvider = exports.AnkrProvider = exports.AlchemyWebSocketProvider = exports.AlchemyProvider = exports.FallbackProvider = exports.UrlJsonRpcProvider = exports.Resolver = exports.BaseProvider = exports.Provider = void 0;
2019-05-14 18:48:48 -04:00
var abstract_provider_1 = require("@ethersproject/abstract-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return abstract_provider_1.Provider; } });
2019-05-14 18:48:48 -04:00
var networks_1 = require("@ethersproject/networks");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "getNetwork", { enumerable: true, get: function () { return networks_1.getNetwork; } });
2019-05-14 18:48:48 -04:00
var base_provider_1 = require("./base-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "BaseProvider", { enumerable: true, get: function () { return base_provider_1.BaseProvider; } });
Object.defineProperty(exports, "Resolver", { enumerable: true, get: function () { return base_provider_1.Resolver; } });
2019-05-14 18:48:48 -04:00
var alchemy_provider_1 = require("./alchemy-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "AlchemyProvider", { enumerable: true, get: function () { return alchemy_provider_1.AlchemyProvider; } });
Object.defineProperty(exports, "AlchemyWebSocketProvider", { enumerable: true, get: function () { return alchemy_provider_1.AlchemyWebSocketProvider; } });
2022-03-19 02:59:38 -04:00
var ankr_provider_1 = require("./ankr-provider");
Object.defineProperty(exports, "AnkrProvider", { enumerable: true, get: function () { return ankr_provider_1.AnkrProvider; } });
2019-08-21 01:52:13 -04:00
var cloudflare_provider_1 = require("./cloudflare-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "CloudflareProvider", { enumerable: true, get: function () { return cloudflare_provider_1.CloudflareProvider; } });
2019-05-14 18:48:48 -04:00
var etherscan_provider_1 = require("./etherscan-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "EtherscanProvider", { enumerable: true, get: function () { return etherscan_provider_1.EtherscanProvider; } });
2019-05-14 18:48:48 -04:00
var fallback_provider_1 = require("./fallback-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "FallbackProvider", { enumerable: true, get: function () { return fallback_provider_1.FallbackProvider; } });
2019-05-14 18:48:48 -04:00
var ipc_provider_1 = require("./ipc-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "IpcProvider", { enumerable: true, get: function () { return ipc_provider_1.IpcProvider; } });
2019-05-14 18:48:48 -04:00
var infura_provider_1 = require("./infura-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "InfuraProvider", { enumerable: true, get: function () { return infura_provider_1.InfuraProvider; } });
Object.defineProperty(exports, "InfuraWebSocketProvider", { enumerable: true, get: function () { return infura_provider_1.InfuraWebSocketProvider; } });
2019-05-14 18:48:48 -04:00
var json_rpc_provider_1 = require("./json-rpc-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "JsonRpcProvider", { enumerable: true, get: function () { return json_rpc_provider_1.JsonRpcProvider; } });
Object.defineProperty(exports, "JsonRpcSigner", { enumerable: true, get: function () { return json_rpc_provider_1.JsonRpcSigner; } });
2021-04-17 22:41:09 -04:00
var json_rpc_batch_provider_1 = require("./json-rpc-batch-provider");
Object.defineProperty(exports, "JsonRpcBatchProvider", { enumerable: true, get: function () { return json_rpc_batch_provider_1.JsonRpcBatchProvider; } });
2019-05-14 18:48:48 -04:00
var nodesmith_provider_1 = require("./nodesmith-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "NodesmithProvider", { enumerable: true, get: function () { return nodesmith_provider_1.NodesmithProvider; } });
2020-10-18 23:19:16 -04:00
var pocket_provider_1 = require("./pocket-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "PocketProvider", { enumerable: true, get: function () { return pocket_provider_1.PocketProvider; } });
2024-02-23 22:30:55 -05:00
var quicknode_provider_1 = require("./quicknode-provider");
Object.defineProperty(exports, "QuickNodeProvider", { enumerable: true, get: function () { return quicknode_provider_1.QuickNodeProvider; } });
2020-06-29 00:54:30 -04:00
var url_json_rpc_provider_1 = require("./url-json-rpc-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "StaticJsonRpcProvider", { enumerable: true, get: function () { return url_json_rpc_provider_1.StaticJsonRpcProvider; } });
Object.defineProperty(exports, "UrlJsonRpcProvider", { enumerable: true, get: function () { return url_json_rpc_provider_1.UrlJsonRpcProvider; } });
2019-05-14 18:48:48 -04:00
var web3_provider_1 = require("./web3-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "Web3Provider", { enumerable: true, get: function () { return web3_provider_1.Web3Provider; } });
2020-03-12 19:14:50 +01:00
var websocket_provider_1 = require("./websocket-provider");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "WebSocketProvider", { enumerable: true, get: function () { return websocket_provider_1.WebSocketProvider; } });
2019-07-20 20:13:00 -03:00
var formatter_1 = require("./formatter");
2021-03-07 18:24:04 -05:00
Object.defineProperty(exports, "Formatter", { enumerable: true, get: function () { return formatter_1.Formatter; } });
Object.defineProperty(exports, "isCommunityResourcable", { enumerable: true, get: function () { return formatter_1.isCommunityResourcable; } });
Object.defineProperty(exports, "isCommunityResource", { enumerable: true, get: function () { return formatter_1.isCommunityResource; } });
Object.defineProperty(exports, "showThrottleMessage", { enumerable: true, get: function () { return formatter_1.showThrottleMessage; } });
2019-11-20 18:57:38 +09:00
var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version");
var logger = new logger_1.Logger(_version_1.version);
////////////////////////
// Helper Functions
function getDefaultProvider(network, options) {
if (network == null) {
network = "homestead";
}
2020-06-29 00:54:30 -04:00
// If passed a URL, figure out the right type of provider based on the scheme
if (typeof (network) === "string") {
// @TODO: Add support for IpcProvider; maybe if it ends in ".ipc"?
// Handle http and ws (and their secure variants)
var match = network.match(/^(ws|http)s?:/i);
if (match) {
2022-05-20 19:13:03 -04:00
switch (match[1].toLowerCase()) {
2020-06-29 00:54:30 -04:00
case "http":
2022-05-20 19:13:03 -04:00
case "https":
2020-06-29 00:54:30 -04:00
return new json_rpc_provider_1.JsonRpcProvider(network);
case "ws":
2022-05-20 19:13:03 -04:00
case "wss":
2020-06-29 00:54:30 -04:00
return new websocket_provider_1.WebSocketProvider(network);
default:
logger.throwArgumentError("unsupported URL scheme", "network", network);
}
}
}
2021-10-16 02:29:27 -04:00
var n = (0, networks_1.getNetwork)(network);
2019-11-20 18:57:38 +09:00
if (!n || !n._defaultProvider) {
logger.throwError("unsupported getDefaultProvider network", logger_1.Logger.errors.NETWORK_ERROR, {
operation: "getDefaultProvider",
network: network
});
}
return n._defaultProvider({
FallbackProvider: fallback_provider_1.FallbackProvider,
AlchemyProvider: alchemy_provider_1.AlchemyProvider,
2022-03-19 02:59:38 -04:00
AnkrProvider: ankr_provider_1.AnkrProvider,
2019-11-20 18:57:38 +09:00
CloudflareProvider: cloudflare_provider_1.CloudflareProvider,
EtherscanProvider: etherscan_provider_1.EtherscanProvider,
InfuraProvider: infura_provider_1.InfuraProvider,
JsonRpcProvider: json_rpc_provider_1.JsonRpcProvider,
NodesmithProvider: nodesmith_provider_1.NodesmithProvider,
2020-10-18 23:19:16 -04:00
PocketProvider: pocket_provider_1.PocketProvider,
2024-02-23 22:30:55 -05:00
QuickNodeProvider: quicknode_provider_1.QuickNodeProvider,
2019-11-20 18:57:38 +09:00
Web3Provider: web3_provider_1.Web3Provider,
IpcProvider: ipc_provider_1.IpcProvider,
}, options);
}
exports.getDefaultProvider = getDefaultProvider;
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=index.js.map