Set sensible defaults for INFURA and AlchemyAPI getWebSocketProvider methods.
This commit is contained in:
parent
619a8888eb
commit
e3d3e604f2
@ -20,7 +20,7 @@ const defaultApiKey = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC"
|
|||||||
export class AlchemyProvider extends UrlJsonRpcProvider {
|
export class AlchemyProvider extends UrlJsonRpcProvider {
|
||||||
readonly apiKey: string;
|
readonly apiKey: string;
|
||||||
|
|
||||||
static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider {
|
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider {
|
||||||
const provider = new AlchemyProvider(network, apiKey);
|
const provider = new AlchemyProvider(network, apiKey);
|
||||||
|
|
||||||
const url = provider.connection.url.replace(/^http/i, "ws")
|
const url = provider.connection.url.replace(/^http/i, "ws")
|
||||||
|
@ -18,7 +18,7 @@ export class InfuraProvider extends UrlJsonRpcProvider {
|
|||||||
readonly projectId: string;
|
readonly projectId: string;
|
||||||
readonly projectSecret: string;
|
readonly projectSecret: string;
|
||||||
|
|
||||||
static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider {
|
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider {
|
||||||
const provider = new InfuraProvider(network, apiKey);
|
const provider = new InfuraProvider(network, apiKey);
|
||||||
const connection = provider.connection;
|
const connection = provider.connection;
|
||||||
if (connection.password) {
|
if (connection.password) {
|
||||||
@ -44,12 +44,11 @@ export class InfuraProvider extends UrlJsonRpcProvider {
|
|||||||
apiKeyObj.projectId = apiKey;
|
apiKeyObj.projectId = apiKey;
|
||||||
|
|
||||||
} else if (apiKey.projectSecret != null) {
|
} else if (apiKey.projectSecret != null) {
|
||||||
if (typeof(apiKey.projectId) !== "string") {
|
logger.assertArgument((typeof(apiKey.projectId) === "string"),
|
||||||
logger.throwArgumentError("projectSecret requires a projectId", "projectId", apiKey.projectId);
|
"projectSecret requires a projectId", "projectId", apiKey.projectId);
|
||||||
}
|
logger.assertArgument((typeof(apiKey.projectSecret) === "string"),
|
||||||
if (typeof(apiKey.projectSecret) !== "string") {
|
"invalid projectSecret", "projectSecret", "[REDACTED]");
|
||||||
logger.throwArgumentError("invalid projectSecret", "projectSecret", "[REDACTED]");
|
|
||||||
}
|
|
||||||
apiKeyObj.projectId = apiKey.projectId;
|
apiKeyObj.projectId = apiKey.projectId;
|
||||||
apiKeyObj.projectSecret = apiKey.projectSecret;
|
apiKeyObj.projectSecret = apiKey.projectSecret;
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ export class InfuraProvider extends UrlJsonRpcProvider {
|
|||||||
|
|
||||||
static getUrl(network: Network, apiKey: any): string | ConnectionInfo {
|
static getUrl(network: Network, apiKey: any): string | ConnectionInfo {
|
||||||
let host: string = null;
|
let host: string = null;
|
||||||
switch(network.name) {
|
switch(network ? network.name: "unknown") {
|
||||||
case "homestead":
|
case "homestead":
|
||||||
host = "mainnet.infura.io";
|
host = "mainnet.infura.io";
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user