Skip to content

Commit

Permalink
Pick rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa committed Aug 1, 2024
1 parent 6d1beb3 commit 64f7a71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion template/ts/files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helixbridge/helixconf",
"version": "1.1.5",
"version": "1.1.6",
"description": "Helix conf",
"main": "dist/src/index.js",
"publishConfig": {
Expand Down
27 changes: 27 additions & 0 deletions template/ts/files/src/helixconf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ export interface CoupleFilter {
symbol?: string
}

export interface PickRPCOptions {
strategy: PickRPCStrategy,
picker?: (rpcs: string[]) => Promise<string>,
}

export enum PickRPCStrategy {
Custom,
First,
Best,
}

export interface HelixChainConfType {
_network: _NetworkType
id: bigint
Expand Down Expand Up @@ -116,6 +127,22 @@ export class HelixChainConf {
// this._data[key] = value;
// }

async rpc(options?: PickRPCOptions): Promise<string> {
const strategy = options?.strategy ?? PickRPCStrategy.First;
switch (strategy) {
case PickRPCStrategy.Custom: {
if (!(options?.picker)) {
return this.rpcs[0];
}
return await options.picker(this.rpcs);
}
case PickRPCStrategy.First:
case PickRPCStrategy.Best:
default:
return this.rpcs[0];
}
}

keys(): Array<keyof HelixChainConfType> {
return Object.keys(this._data) as Array<keyof HelixChainConfType>;
}
Expand Down

0 comments on commit 64f7a71

Please sign in to comment.