2019-08-25 09:39:20 +03:00
|
|
|
"use strict";
|
|
|
|
import { Provider } from "@ethersproject/abstract-provider";
|
|
|
|
import { getNetwork } from "@ethersproject/networks";
|
2020-09-04 08:37:14 +03:00
|
|
|
import { BaseProvider, Resolver } from "./base-provider";
|
2020-10-08 03:10:50 +03:00
|
|
|
import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
|
2019-08-25 09:39:20 +03:00
|
|
|
import { CloudflareProvider } from "./cloudflare-provider";
|
|
|
|
import { EtherscanProvider } from "./etherscan-provider";
|
|
|
|
import { FallbackProvider } from "./fallback-provider";
|
|
|
|
import { IpcProvider } from "./ipc-provider";
|
2020-10-08 03:10:50 +03:00
|
|
|
import { InfuraProvider, InfuraWebSocketProvider } from "./infura-provider";
|
2019-08-25 09:39:20 +03:00
|
|
|
import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
|
|
|
|
import { NodesmithProvider } from "./nodesmith-provider";
|
2020-10-19 06:19:16 +03:00
|
|
|
import { PocketProvider } from "./pocket-provider";
|
2020-06-29 07:54:30 +03:00
|
|
|
import { StaticJsonRpcProvider, UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
2019-08-25 09:39:20 +03:00
|
|
|
import { Web3Provider } from "./web3-provider";
|
2020-03-12 21:14:50 +03:00
|
|
|
import { WebSocketProvider } from "./websocket-provider";
|
2020-10-08 03:10:50 +03:00
|
|
|
import { Formatter, isCommunityResourcable, isCommunityResource, showThrottleMessage } from "./formatter";
|
2019-11-20 12:57:38 +03:00
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
|
|
|
////////////////////////
|
|
|
|
// Helper Functions
|
|
|
|
function getDefaultProvider(network, options) {
|
|
|
|
if (network == null) {
|
|
|
|
network = "homestead";
|
|
|
|
}
|
2020-06-29 07:54:30 +03: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)
|
|
|
|
const match = network.match(/^(ws|http)s?:/i);
|
|
|
|
if (match) {
|
|
|
|
switch (match[1]) {
|
|
|
|
case "http":
|
|
|
|
return new JsonRpcProvider(network);
|
|
|
|
case "ws":
|
|
|
|
return new WebSocketProvider(network);
|
|
|
|
default:
|
|
|
|
logger.throwArgumentError("unsupported URL scheme", "network", network);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 12:57:38 +03:00
|
|
|
const n = getNetwork(network);
|
|
|
|
if (!n || !n._defaultProvider) {
|
|
|
|
logger.throwError("unsupported getDefaultProvider network", Logger.errors.NETWORK_ERROR, {
|
|
|
|
operation: "getDefaultProvider",
|
|
|
|
network: network
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return n._defaultProvider({
|
|
|
|
FallbackProvider,
|
|
|
|
AlchemyProvider,
|
|
|
|
CloudflareProvider,
|
|
|
|
EtherscanProvider,
|
|
|
|
InfuraProvider,
|
|
|
|
JsonRpcProvider,
|
|
|
|
NodesmithProvider,
|
2020-10-19 06:19:16 +03:00
|
|
|
PocketProvider,
|
2019-11-20 12:57:38 +03:00
|
|
|
Web3Provider,
|
|
|
|
IpcProvider,
|
|
|
|
}, options);
|
|
|
|
}
|
2019-08-25 09:39:20 +03:00
|
|
|
////////////////////////
|
|
|
|
// Exports
|
|
|
|
export {
|
|
|
|
// Abstract Providers (or Abstract-ish)
|
2020-09-04 08:37:14 +03:00
|
|
|
Provider, BaseProvider, Resolver, UrlJsonRpcProvider,
|
2019-08-25 09:39:20 +03:00
|
|
|
///////////////////////
|
|
|
|
// Concreate Providers
|
2020-10-19 06:19:16 +03:00
|
|
|
FallbackProvider, AlchemyProvider, AlchemyWebSocketProvider, CloudflareProvider, EtherscanProvider, InfuraProvider, InfuraWebSocketProvider, JsonRpcProvider, NodesmithProvider, PocketProvider, StaticJsonRpcProvider, Web3Provider, WebSocketProvider, IpcProvider,
|
2019-08-25 09:39:20 +03:00
|
|
|
///////////////////////
|
|
|
|
// Signer
|
|
|
|
JsonRpcSigner,
|
|
|
|
///////////////////////
|
|
|
|
// Functions
|
2020-10-08 03:10:50 +03:00
|
|
|
getDefaultProvider, getNetwork, isCommunityResource, isCommunityResourcable, showThrottleMessage,
|
2019-08-25 09:39:20 +03:00
|
|
|
///////////////////////
|
|
|
|
// Objects
|
|
|
|
Formatter };
|
2020-07-13 15:03:56 +03:00
|
|
|
//# sourceMappingURL=index.js.map
|