diff --git a/.changeset/quick-parrots-kick.md b/.changeset/quick-parrots-kick.md new file mode 100644 index 00000000..0d142179 --- /dev/null +++ b/.changeset/quick-parrots-kick.md @@ -0,0 +1,6 @@ +--- +'@moonbeam-network/xcm-types': patch +'@moonbeam-network/xcm-utils': patch +--- + +Multiple WS urls for PolkadotJS API diff --git a/packages/types/src/chain/parachain/EvmParachain.ts b/packages/types/src/chain/parachain/EvmParachain.ts index f221b2b7..2ce1b8e5 100644 --- a/packages/types/src/chain/parachain/EvmParachain.ts +++ b/packages/types/src/chain/parachain/EvmParachain.ts @@ -58,7 +58,7 @@ export class EvmParachain extends Parachain { rpcUrls: { default: { http: [this.rpc], - webSocket: [this.ws], + webSocket: Array.isArray(this.ws) ? this.ws : [this.ws], }, }, }); diff --git a/packages/types/src/chain/parachain/Parachain.ts b/packages/types/src/chain/parachain/Parachain.ts index 7e575a5f..ddfb5b4e 100644 --- a/packages/types/src/chain/parachain/Parachain.ts +++ b/packages/types/src/chain/parachain/Parachain.ts @@ -12,7 +12,7 @@ export interface ParachainConstructorParams ss58Format: number; usesChainDecimals?: boolean; weight?: number; - ws: string; + ws: string | string[]; } export class Parachain extends Chain { @@ -28,7 +28,7 @@ export class Parachain extends Chain { readonly weight: number | undefined; - readonly ws: string; + readonly ws: string | string[]; constructor({ assetsData, diff --git a/packages/utils/src/polkadot/polkadot.api.ts b/packages/utils/src/polkadot/polkadot.api.ts index 3700d0be..a21b13ee 100644 --- a/packages/utils/src/polkadot/polkadot.api.ts +++ b/packages/utils/src/polkadot/polkadot.api.ts @@ -22,9 +22,12 @@ const cache = new LRUCache>({ }, }); -export async function getPolkadotApi(ws: string): Promise { +export async function getPolkadotApi( + ws: string | string[], +): Promise { + const key = Array.isArray(ws) ? ws.join(';') : ws; const promise = - cache.get(ws) || + cache.get(key) || ApiPromise.create({ noInitWarn: true, provider: new WsProvider(ws), @@ -39,7 +42,7 @@ export async function getPolkadotApi(ws: string): Promise { typesBundle, }); - cache.set(ws, promise); + cache.set(key, promise); const api = await promise;