Skip to content

Commit 165cfc0

Browse files
committed
pass viewer instead of creating one
1 parent 647bff0 commit 165cfc0

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/helloWorldRunner.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { type ChildProcess, spawn } from 'node:child_process'
22

33
import { HDWallet } from '@xyo-network/wallet'
4-
import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from '@xyo-network/xl1-protocol-sdk'
4+
import type { XyoViewer } from '@xyo-network/xl1-protocol-sdk'
5+
import {
6+
ADDRESS_INDEX, generateXyoBaseWalletFromPhrase, XyoViewerMoniker,
7+
} from '@xyo-network/xl1-protocol-sdk'
58

9+
import { getLocator } from './getGateway.ts'
610
import { helloWorld } from './helloWorld.js'
711
import { waitForInitialBlocks } from './waitForInitialBlocks.js'
812

@@ -83,7 +87,12 @@ async function startXl1(): Promise<string> {
8387
throw error
8488
})
8589

86-
await waitForInitialBlocks()
90+
// Get the XyoViewer instance
91+
const locator = await getLocator()
92+
const viewer = await locator.getInstance<XyoViewer>(XyoViewerMoniker)
93+
94+
// Wait for the initial blocks to be created
95+
await waitForInitialBlocks(viewer)
8796

8897
return mnemonic
8998
} catch (error) {

src/waitForInitialBlocks.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { assertEx } from '@xylabs/assert'
22
import { delay } from '@xylabs/delay'
33
import { isDefined } from '@xylabs/typeof'
4-
import { HttpRpcXyoConnection } from '@xyo-network/xl1-rpc'
5-
6-
export const waitForInitialBlocks = async (maxAttempts = 10): Promise<void> => {
7-
const connection = new HttpRpcXyoConnection({ endpoint: 'http://localhost:8080/rpc' })
8-
const viewer = assertEx(connection.viewer, () => 'Connection viewer is undefined')
4+
import type { XyoViewer } from '@xyo-network/xl1-sdk'
95

6+
export const waitForInitialBlocks = async (viewer: XyoViewer, maxAttempts = 10): Promise<void> => {
7+
assertEx(viewer, () => 'Connection viewer is undefined')
108
console.log('\n⏳ Waiting for genesis block creation...')
119
let attempts = 0
1210
while (attempts < maxAttempts) {

0 commit comments

Comments
 (0)