-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bring back modified ws rpc provider
- Loading branch information
1 parent
ac88d80
commit 9592c3f
Showing
14 changed files
with
325 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./jsonRpcProviderBase"; | ||
export * from "./jsonRpcProviderExtended"; | ||
export * from "./webSocketProviderExtended"; | ||
export * from "./wrappedWebSocketProvider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
packages/data-fetcher/src/rpcProvider/webSocketProviderExtended.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/data-fetcher/src/rpcProvider/wrappedWebSocketProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ProviderState } from "./jsonRpcProviderBase"; | ||
import { WebSocketProviderExtended } from "./webSocketProviderExtended"; | ||
|
||
const monitorInterval = 10000; | ||
|
||
export class WrappedWebSocketProvider { | ||
private readonly providerUrl: string; | ||
private readonly connectionTimeout: number; | ||
private readonly connectionQuickTimeout: number; | ||
private instances: WebSocketProviderExtended[] = []; | ||
|
||
constructor(providerUrl: string, connectionTimeout: number, connectionQuickTimeout: number, maxConnections = 5) { | ||
this.providerUrl = providerUrl; | ||
this.connectionTimeout = connectionTimeout; | ||
this.connectionQuickTimeout = connectionQuickTimeout; | ||
|
||
for (let i = 0; i < maxConnections; i++) { | ||
this.instances[i] = new WebSocketProviderExtended( | ||
this.providerUrl, | ||
this.connectionTimeout, | ||
this.connectionQuickTimeout | ||
); | ||
} | ||
this.monitorInstances(); | ||
} | ||
|
||
public getProvider(): WebSocketProviderExtended { | ||
const totalActiveInstances = this.instances.filter((instance) => instance.getState() !== "closed"); | ||
const randomInstanceNumber = Math.floor(Math.random() * totalActiveInstances.length); | ||
return this.instances[randomInstanceNumber]; | ||
} | ||
|
||
private monitorInstances(): void { | ||
setInterval(() => { | ||
for (let i = 0; i < this.instances.length; i++) { | ||
if (this.instances[i].getState() === "closed") { | ||
this.instances[i] = new WebSocketProviderExtended( | ||
this.providerUrl, | ||
this.connectionTimeout, | ||
this.connectionQuickTimeout | ||
); | ||
} | ||
} | ||
}, monitorInterval); | ||
} | ||
|
||
public getState(): ProviderState { | ||
if (this.instances.find((instance) => instance.getState() === "open")) { | ||
return "open"; | ||
} | ||
if (this.instances.find((instance) => instance.getState() === "connecting")) { | ||
return "connecting"; | ||
} | ||
return "closed"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./jsonRpcProviderBase"; | ||
export * from "./jsonRpcProviderExtended"; | ||
export * from "./webSocketProviderExtended"; | ||
export * from "./wrappedWebSocketProvider"; |
Oops, something went wrong.