Added getWebSocketProvider static method to InfuraProvider.
This commit is contained in:
parent
472e5b07ea
commit
a6c1174dff
@ -1,8 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { Network } from "@ethersproject/networks";
|
import { Network, Networkish } from "@ethersproject/networks";
|
||||||
import { ConnectionInfo } from "@ethersproject/web";
|
import { ConnectionInfo } from "@ethersproject/web";
|
||||||
|
|
||||||
|
import { WebSocketProvider } from "./websocket-provider";
|
||||||
|
|
||||||
import { Logger } from "@ethersproject/logger";
|
import { Logger } from "@ethersproject/logger";
|
||||||
import { version } from "./_version";
|
import { version } from "./_version";
|
||||||
const logger = new Logger(version);
|
const logger = new Logger(version);
|
||||||
@ -16,6 +18,19 @@ export class InfuraProvider extends UrlJsonRpcProvider {
|
|||||||
readonly projectId: string;
|
readonly projectId: string;
|
||||||
readonly projectSecret: string;
|
readonly projectSecret: string;
|
||||||
|
|
||||||
|
static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider {
|
||||||
|
const provider = new InfuraProvider(network, apiKey);
|
||||||
|
const connection = provider.connection;
|
||||||
|
if (connection.password) {
|
||||||
|
logger.throwError("INFURA WebSocket project secrets unsupported", Logger.errors.UNSUPPORTED_OPERATION, {
|
||||||
|
operation: "InfuraProvider.getWebSocketProvider()"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/");
|
||||||
|
return new WebSocketProvider(url, network);
|
||||||
|
}
|
||||||
|
|
||||||
static getApiKey(apiKey: any): any {
|
static getApiKey(apiKey: any): any {
|
||||||
const apiKeyObj: { apiKey: string, projectId: string, projectSecret: string } = {
|
const apiKeyObj: { apiKey: string, projectId: string, projectSecret: string } = {
|
||||||
apiKey: defaultProjectId,
|
apiKey: defaultProjectId,
|
||||||
|
Loading…
Reference in New Issue
Block a user