Skip to content

Commit

Permalink
support multiple endpoints (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Nov 23, 2023
1 parent b724995 commit 5a9e5d7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion configs/acala.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
endpoint: wss://acala-rpc.dwellir.com
endpoint:
- wss://acala-rpc.aca-api.network
- wss://acala-rpc.dwellir.com
mock-signature-host: true
block: ${env.ACALA_BLOCK_NUMBER}
db: ./db.sqlite
Expand Down
4 changes: 3 additions & 1 deletion configs/polkadot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
endpoint: wss://rpc.polkadot.io
endpoint:
- wss://rpc.polkadot.io
- wss://polkadot-rpc.dwellir.com
mock-signature-host: true
block: ${env.POLKADOT_BLOCK_NUMBER}
db: ./db.sqlite
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const zHash = z.string().length(66).and(zHex)
export const configSchema = z
.object({
port: z.number().optional(),
endpoint: z.string().optional(),
endpoint: z.union([z.string(), z.array(z.string())]).optional(),
block: z.union([z.string().length(66).startsWith('0x'), z.number(), z.null()]).optional(),
'build-block-mode': z.nativeEnum(BuildBlockMode).optional(),
'import-storage': z.any().optional(),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { defaultLogger } from './logger.js'

export type SetupOptions = {
endpoint?: string
endpoint?: string | string[]
block?: string | number | null
genesis?: GenesisProvider
buildBlockMode?: BuildBlockMode
Expand All @@ -37,7 +37,7 @@ export const setup = async (options: SetupOptions) => {
let provider: ProviderInterface
if (options.genesis) {
provider = options.genesis
} else if (/^(https|http):\/\//.test(options.endpoint || '')) {
} else if (typeof options.endpoint === 'string' && /^(https|http):\/\//.test(options.endpoint || '')) {
provider = new HttpProvider(options.endpoint)
} else {
provider = new WsProvider(options.endpoint, 3_000)
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { handler } from '@acala-network/chopsticks/rpc/index.js'
export { expectJson, expectHex, testingPairs } from '@acala-network/chopsticks-testing'

export type SetupOption = {
endpoint?: string
endpoint?: string | string[]
blockHash?: HexString
mockSignatureHost?: boolean
allowUnresolvedImports?: boolean
Expand Down Expand Up @@ -60,7 +60,7 @@ export const setupAll = async ({
let provider: ProviderInterface
if (genesis) {
provider = await genesisFromUrl(genesis)
} else if (/^(https|http):\/\//.test(endpoint || '')) {
} else if (typeof endpoint === 'string' && /^(https|http):\/\//.test(endpoint || '')) {
provider = new HttpProvider(endpoint)
} else {
provider = new WsProvider(endpoint, 3_000)
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { SetupOption, setupContext } from '@acala-network/chopsticks-testing'
dotenvConfig

const endpoints = {
polkadot: 'wss://rpc.polkadot.io',
acala: 'wss://acala-rpc-1.aca-api.network',
polkadot: ['wss://rpc.polkadot.io', 'wss://polkadot-rpc.dwellir.com'],
acala: ['wss://acala-rpc.aca-api.network', 'wss://acala-rpc.dwellir.com'],
}

const toNumber = (value: string | undefined): number | undefined => {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SubmittableExtrinsic } from '@polkadot/api-base/types'
export * from './signFake.js'

export type SetupOption = {
endpoint: string
endpoint: string | string[]
blockNumber?: number
blockHash?: HexString
wasmOverride?: string
Expand Down

0 comments on commit 5a9e5d7

Please sign in to comment.