Added getWebSocketProvider static method to InfuraProvider.

This commit is contained in:
Richard Moore 2020-05-03 14:20:33 -04:00
parent 472e5b07ea
commit a6c1174dff
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -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,