Skip to content

Commit

Permalink
fix: remove protocol config options
Browse files Browse the repository at this point in the history
Currently there are not many wss rpcs. most of the available ones are not responding. Skip them for now.
  • Loading branch information
EresDev committed Jun 16, 2024
1 parent 1a8b6e7 commit e3cd0f0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 25 deletions.
1 change: 0 additions & 1 deletion tests/benchmark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const testConfig: HandlerConstructorConfig = {
rpcTimeout: 1500,
runtimeRpcs: null,
tracking: "yes",
protocol: "all",
};

describe("RPCHandler", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const testConfig: HandlerConstructorConfig = {
rpcTimeout: 1500,
runtimeRpcs: null,
tracking: "yes",
protocol: "all",
};

describe("RPCHandler", () => {
Expand Down
3 changes: 1 addition & 2 deletions types/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonRpcProvider } from "@ethersproject/providers";
import { ChainId, networkCurrencies, networkExplorers, networkIds, networkNames, networkRpcs, networkRpcsOriginal, tokens } from "./constants";
import { Protocol, RpcType, Tracking } from "./shared";
import { RpcType, Tracking } from "./shared";

export type ValidBlockData = {
jsonrpc: string;
Expand Down Expand Up @@ -39,7 +39,6 @@ export type HandlerConstructorConfig = {
runtimeRpcs: string[] | null;
rpcTimeout: number | null;
tracking: Tracking;
protocol: Protocol;
};

export type NetworkRPCs = typeof networkRpcs;
Expand Down
25 changes: 5 additions & 20 deletions types/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HandlerInterface, HandlerConstructorConfig } from "./handler";

import { RPCService } from "../src/services/rpc-service";
import { StorageService } from "../src/services/storage-service";
import { Protocol, RpcType, Tracking, getRpcUrls } from "./shared";
import { RpcType, Tracking, getRpcUrls } from "./shared";

export class RPCHandler implements HandlerInterface {
private static _instance: RPCHandler | null = null;
Expand All @@ -25,13 +25,13 @@ export class RPCHandler implements HandlerInterface {

constructor(config: HandlerConstructorConfig) {
this._networkId = config.networkId;
this._networkRpcs = this.filterNetworks(networkRpcsOriginal[this._networkId], config.tracking, config.protocol);
this._networkRpcs = this.filterNetworks(networkRpcsOriginal[this._networkId], config.tracking);
this._networkName = networkNames[this._networkId];
this._initialize(config);
}

public filterNetworks(networks: RpcType[], tracking: Tracking, protocol: Protocol) {
const trackingFilteredRpc = networks.filter((rpc) => {
public filterNetworks(networks: RpcType[], tracking: Tracking) {
const filteredRpcs = networks.filter((rpc) => {
if (tracking == "yes") {
return true;
} else if (tracking == "limited" && typeof rpc != "string") {
Expand All @@ -41,22 +41,7 @@ export class RPCHandler implements HandlerInterface {
}
return false;
});

const fullyFilteredRpcs = trackingFilteredRpc.filter((rpc) => {
if (protocol == "all") {
return true;
}

const url = typeof rpc == "string" ? rpc : rpc.url;
if (protocol == "https") {
return url.indexOf("https") === 0;
} else if (protocol == "wss") {
return url.indexOf("wss") === 0;
}
return false;
});

return fullyFilteredRpcs;
return filteredRpcs;
}

public async getFastestRpcProvider(): Promise<JsonRpcProvider> {
Expand Down
1 change: 0 additions & 1 deletion types/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type Tracking = "yes" | "limited" | "none";
export type Protocol = "all" | "https" | "wss";

export type RpcType =
| string // if string then it is the official rpc of the chain
Expand Down

0 comments on commit e3cd0f0

Please sign in to comment.