ethers.js/packages/providers/src.ts/index.ts

174 lines
4.1 KiB
TypeScript
Raw Permalink Normal View History

2019-05-14 18:25:46 -04:00
"use strict";
import {
Block,
BlockTag,
EventType,
2021-06-14 22:24:14 -04:00
FeeData,
2019-05-14 18:25:46 -04:00
Filter,
Log,
Listener,
Provider,
TransactionReceipt,
TransactionRequest,
TransactionResponse
} from "@ethersproject/abstract-provider";
import { getNetwork } from "@ethersproject/networks";
import { Network, Networkish } from "@ethersproject/networks";
import { BaseProvider, EnsProvider, EnsResolver, Resolver } from "./base-provider";
2019-05-14 18:25:46 -04:00
import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
2019-08-21 01:45:06 -04:00
import { CloudflareProvider } from "./cloudflare-provider";
2019-05-14 18:25:46 -04:00
import { EtherscanProvider } from "./etherscan-provider";
import { FallbackProvider } from "./fallback-provider";
import { IpcProvider } from "./ipc-provider";
import { InfuraProvider, InfuraWebSocketProvider } from "./infura-provider";
2019-05-14 18:25:46 -04:00
import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
import { JsonRpcBatchProvider } from "./json-rpc-batch-provider";
2019-05-14 18:25:46 -04:00
import { NodesmithProvider } from "./nodesmith-provider";
2020-10-08 20:21:32 -04:00
import { PocketProvider } from "./pocket-provider";
import { StaticJsonRpcProvider, UrlJsonRpcProvider } from "./url-json-rpc-provider";
2019-05-14 18:25:46 -04:00
import { Web3Provider } from "./web3-provider";
import { WebSocketProvider } from "./websocket-provider";
import { ExternalProvider, JsonRpcFetchFunc } from "./web3-provider";
2019-05-14 18:25:46 -04:00
import { CommunityResourcable, Formatter, isCommunityResourcable, isCommunityResource, showThrottleMessage } from "./formatter";
2019-05-14 18:25:46 -04:00
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
////////////////////////
// Helper Functions
function getDefaultProvider(network?: Network | string, options?: any): BaseProvider {
if (network == null) { network = "homestead"; }
// 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);
}
}
}
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-08 20:21:32 -04:00
PocketProvider,
Web3Provider,
IpcProvider,
}, options);
}
2019-05-14 18:25:46 -04:00
////////////////////////
// Exports
export {
// Abstract Providers (or Abstract-ish)
Provider,
BaseProvider,
Resolver,
UrlJsonRpcProvider,
2019-05-14 18:25:46 -04:00
///////////////////////
// Concreate Providers
FallbackProvider,
AlchemyProvider,
AlchemyWebSocketProvider,
2019-08-21 01:45:06 -04:00
CloudflareProvider,
2019-05-14 18:25:46 -04:00
EtherscanProvider,
InfuraProvider,
InfuraWebSocketProvider,
2019-05-14 18:25:46 -04:00
JsonRpcProvider,
JsonRpcBatchProvider,
2019-05-14 18:25:46 -04:00
NodesmithProvider,
2020-10-08 20:21:32 -04:00
PocketProvider,
StaticJsonRpcProvider,
2019-05-14 18:25:46 -04:00
Web3Provider,
WebSocketProvider,
2019-05-14 18:25:46 -04:00
IpcProvider,
///////////////////////
// Signer
JsonRpcSigner,
///////////////////////
// Functions
getDefaultProvider,
2019-05-14 18:25:46 -04:00
getNetwork,
isCommunityResource,
isCommunityResourcable,
showThrottleMessage,
2019-05-14 18:25:46 -04:00
2019-07-20 20:09:49 -03:00
///////////////////////
// Objects
Formatter,
2019-05-14 18:25:46 -04:00
///////////////////////
// Types
Block,
BlockTag,
EventType,
2021-06-14 22:24:14 -04:00
FeeData,
2019-05-14 18:25:46 -04:00
Filter,
Log,
Listener,
TransactionReceipt,
TransactionRequest,
TransactionResponse,
ExternalProvider,
JsonRpcFetchFunc,
2019-05-14 18:25:46 -04:00
Network,
Networkish,
EnsProvider,
EnsResolver,
CommunityResourcable
2019-05-14 18:25:46 -04:00
};