Skip to content

Commit

Permalink
Added getWebSocketProvider static method to InfuraProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 3, 2020
1 parent 472e5b0 commit a6c1174
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/providers/src.ts/infura-provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use strict";

import { Network } from "@ethersproject/networks";
import { Network, Networkish } from "@ethersproject/networks";
import { ConnectionInfo } from "@ethersproject/web";

import { WebSocketProvider } from "./websocket-provider";

import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
Expand All @@ -16,6 +18,19 @@ export class InfuraProvider extends UrlJsonRpcProvider {
readonly projectId: 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 {
const apiKeyObj: { apiKey: string, projectId: string, projectSecret: string } = {
apiKey: defaultProjectId,
Expand Down

0 comments on commit a6c1174

Please sign in to comment.