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";
|
|
|
|
|
2020-09-04 01:18:57 -04:00
|
|
|
import { BaseProvider, EnsProvider, EnsResolver, Resolver } from "./base-provider";
|
2019-05-14 18:25:46 -04:00
|
|
|
|
2020-10-07 17:28:18 -04:00
|
|
|
import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
|
2022-03-19 02:44:29 -04:00
|
|
|
import { AnkrProvider } from "./ankr-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";
|
2021-10-04 10:44:24 -04:00
|
|
|
import { FallbackProvider, FallbackProviderConfig } from "./fallback-provider";
|
2019-05-14 18:25:46 -04:00
|
|
|
import { IpcProvider } from "./ipc-provider";
|
2020-10-07 17:28:18 -04:00
|
|
|
import { InfuraProvider, InfuraWebSocketProvider } from "./infura-provider";
|
2019-05-14 18:25:46 -04:00
|
|
|
import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
|
2021-04-17 18:12:08 -04:00
|
|
|
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";
|
2020-06-29 00:21:59 -04:00
|
|
|
import { StaticJsonRpcProvider, UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
2019-05-14 18:25:46 -04:00
|
|
|
import { Web3Provider } from "./web3-provider";
|
2020-03-12 18:53:34 +01:00
|
|
|
import { WebSocketProvider } from "./websocket-provider";
|
2020-04-27 06:15:44 -04:00
|
|
|
import { ExternalProvider, JsonRpcFetchFunc } from "./web3-provider";
|
2019-05-14 18:25:46 -04:00
|
|
|
|
2020-10-07 17:28:18 -04:00
|
|
|
import { CommunityResourcable, Formatter, isCommunityResourcable, isCommunityResource, showThrottleMessage } from "./formatter";
|
2019-05-14 18:25:46 -04:00
|
|
|
|
2019-11-01 23:51:08 +09:00
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
// Helper Functions
|
|
|
|
|
2021-10-04 10:57:00 -04:00
|
|
|
function getDefaultProvider(network?: Networkish, options?: any): BaseProvider {
|
2019-11-01 23:51:08 +09:00
|
|
|
if (network == null) { network = "homestead"; }
|
2020-06-29 00:06:31 -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)
|
|
|
|
const match = network.match(/^(ws|http)s?:/i);
|
|
|
|
if (match) {
|
2022-05-14 02:50:53 -04:00
|
|
|
switch (match[1].toLowerCase()) {
|
|
|
|
case "http": case "https":
|
2020-06-29 00:06:31 -04:00
|
|
|
return new JsonRpcProvider(network);
|
2022-05-14 02:50:53 -04:00
|
|
|
case "ws": case "wss":
|
2020-06-29 00:06:31 -04:00
|
|
|
return new WebSocketProvider(network);
|
|
|
|
default:
|
|
|
|
logger.throwArgumentError("unsupported URL scheme", "network", network);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 23:51:08 +09: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,
|
2022-03-19 02:44:29 -04:00
|
|
|
AnkrProvider,
|
2019-11-01 23:51:08 +09:00
|
|
|
CloudflareProvider,
|
|
|
|
EtherscanProvider,
|
|
|
|
InfuraProvider,
|
|
|
|
JsonRpcProvider,
|
|
|
|
NodesmithProvider,
|
2020-10-08 20:21:32 -04:00
|
|
|
PocketProvider,
|
2019-11-01 23:51:08 +09:00
|
|
|
Web3Provider,
|
|
|
|
|
|
|
|
IpcProvider,
|
|
|
|
}, options);
|
|
|
|
}
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
////////////////////////
|
|
|
|
// Exports
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
|
|
|
// Abstract Providers (or Abstract-ish)
|
|
|
|
Provider,
|
|
|
|
BaseProvider,
|
|
|
|
|
2020-09-04 01:18:57 -04:00
|
|
|
Resolver,
|
|
|
|
|
2020-06-29 00:21:59 -04:00
|
|
|
UrlJsonRpcProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
|
|
|
|
///////////////////////
|
2021-10-04 11:46:24 -04:00
|
|
|
// Concrete Providers
|
2019-05-14 18:25:46 -04:00
|
|
|
|
|
|
|
FallbackProvider,
|
|
|
|
|
|
|
|
AlchemyProvider,
|
2020-10-07 17:28:18 -04:00
|
|
|
AlchemyWebSocketProvider,
|
2022-03-19 02:44:29 -04:00
|
|
|
AnkrProvider,
|
2019-08-21 01:45:06 -04:00
|
|
|
CloudflareProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
EtherscanProvider,
|
|
|
|
InfuraProvider,
|
2020-10-07 17:28:18 -04:00
|
|
|
InfuraWebSocketProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
JsonRpcProvider,
|
2021-04-17 18:12:08 -04:00
|
|
|
JsonRpcBatchProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
NodesmithProvider,
|
2020-10-08 20:21:32 -04:00
|
|
|
PocketProvider,
|
2020-06-29 00:21:59 -04:00
|
|
|
StaticJsonRpcProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
Web3Provider,
|
2020-03-12 18:53:34 +01:00
|
|
|
WebSocketProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
|
|
|
|
IpcProvider,
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
// Signer
|
|
|
|
|
|
|
|
JsonRpcSigner,
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
// Functions
|
|
|
|
|
2019-11-01 23:51:08 +09:00
|
|
|
getDefaultProvider,
|
2019-05-14 18:25:46 -04:00
|
|
|
getNetwork,
|
2020-10-07 17:28:18 -04:00
|
|
|
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,
|
|
|
|
|
2020-04-27 06:15:44 -04:00
|
|
|
ExternalProvider,
|
|
|
|
JsonRpcFetchFunc,
|
2019-05-14 18:25:46 -04:00
|
|
|
|
2021-10-04 10:44:24 -04:00
|
|
|
FallbackProviderConfig,
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
Network,
|
2020-09-04 01:18:57 -04:00
|
|
|
Networkish,
|
|
|
|
|
|
|
|
EnsProvider,
|
2020-10-07 17:28:18 -04:00
|
|
|
EnsResolver,
|
|
|
|
|
|
|
|
CommunityResourcable
|
2019-05-14 18:25:46 -04:00
|
|
|
};
|
|
|
|
|