Skip to content

Commit 1a1819b

Browse files
committed
extract getLocator helper to new file
1 parent 165cfc0 commit 1a1819b

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/getGateway.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { assertEx } from '@xylabs/assert'
2-
import { isDefined } from '@xylabs/typeof'
3-
import type {
4-
CreatableProviderContext,
5-
ProviderFactoryLocator,
6-
RpcSchemaMap, TransportFactory, XyoConnection,
7-
} from '@xyo-network/xl1-sdk'
2+
import type { XyoConnection } from '@xyo-network/xl1-sdk'
83
import {
9-
ADDRESS_INDEX, buildJsonRpcProviderLocator, buildSimpleXyoSigner, generateXyoBaseWalletFromPhrase,
10-
HttpRpcTransport, SimpleXyoGatewayRunner, XyoConnectionMoniker,
4+
ADDRESS_INDEX,
5+
buildSimpleXyoSigner, generateXyoBaseWalletFromPhrase,
6+
SimpleXyoGatewayRunner, XyoConnectionMoniker,
117
} from '@xyo-network/xl1-sdk'
128

13-
let locator: ProviderFactoryLocator<CreatableProviderContext, string[]>
9+
import { getLocator } from './getLocator.ts'
1410

1511
export const getGateway = async (mnemonic?: string, rpcEndpoint = 'http://localhost:8080/rpc') => {
1612
// Load the account to use for the transaction
@@ -30,14 +26,3 @@ export const getGateway = async (mnemonic?: string, rpcEndpoint = 'http://localh
3026
// Return a new SimpleXyoGatewayRunner instance
3127
return new SimpleXyoGatewayRunner(connection, signer)
3228
}
33-
34-
export const getLocator = async (rpcEndpoint = 'http://localhost:8080/rpc') => {
35-
if (isDefined(locator)) return locator
36-
// Determine the RPC endpoint to use for the chain connection
37-
const endpoint = process.env.XYO_CHAIN_RPC_URL ?? rpcEndpoint
38-
console.log('Using endpoint:', endpoint)
39-
40-
const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)
41-
locator = await buildJsonRpcProviderLocator({ transportFactory })
42-
return locator
43-
}

src/getLocator.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { isDefined } from '@xylabs/typeof'
2+
import type {
3+
ProviderFactoryLocator, RpcSchemaMap, TransportFactory,
4+
} from '@xyo-network/xl1-sdk'
5+
import { buildJsonRpcProviderLocator, HttpRpcTransport } from '@xyo-network/xl1-sdk'
6+
7+
let locator: ProviderFactoryLocator
8+
9+
export const getLocator = async (rpcEndpoint = 'http://localhost:8080/rpc') => {
10+
if (isDefined(locator)) return locator
11+
// Determine the RPC endpoint to use for the chain connection
12+
const endpoint = process.env.XYO_CHAIN_RPC_URL ?? rpcEndpoint
13+
console.log('Using endpoint:', endpoint)
14+
15+
const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)
16+
locator = await buildJsonRpcProviderLocator({ transportFactory })
17+
return locator
18+
}

src/helloWorldRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ADDRESS_INDEX, generateXyoBaseWalletFromPhrase, XyoViewerMoniker,
77
} from '@xyo-network/xl1-protocol-sdk'
88

9-
import { getLocator } from './getGateway.ts'
9+
import { getLocator } from './getLocator.ts'
1010
import { helloWorld } from './helloWorld.js'
1111
import { waitForInitialBlocks } from './waitForInitialBlocks.js'
1212

0 commit comments

Comments
 (0)