11import { type ChildProcess , spawn } from 'node:child_process'
22
3- import { HDWallet } from '@xyo-network/wallet'
43import type { XyoViewer } from '@xyo-network/xl1-protocol-sdk'
5- import {
6- ADDRESS_INDEX , generateXyoBaseWalletFromPhrase , XyoViewerMoniker ,
7- } from '@xyo-network/xl1-protocol-sdk'
4+ import { XyoViewerMoniker } from '@xyo-network/xl1-protocol-sdk'
85
96import { getLocator } from './getLocator.ts'
7+ import { getSignerAccount } from './getSignerAccount.ts'
8+ import { getWalletMnemonic } from './getWalletMnemonic.ts'
109import { helloWorld } from './helloWorld.js'
1110import { waitForInitialBlocks } from './waitForInitialBlocks.js'
1211
12+ // Parse the relevant ENV VARs or use defaults
13+ const mnemonic = getWalletMnemonic ( )
14+
1315/**
1416 * Starts the XL1 node using command in a child process
1517 * The child process will be terminated when the parent process exits
@@ -18,8 +20,6 @@ import { waitForInitialBlocks } from './waitForInitialBlocks.js'
1820async function startXl1 ( ) : Promise < string > {
1921 console . log ( 'Starting XL1...' )
2022
21- const mnemonic = process . env . XYO_WALLET_MNEMONIC ?? HDWallet . generateMnemonic ( )
22-
2323 // Track the child process
2424 let xl1Process : ChildProcess | null = null
2525
@@ -49,12 +49,10 @@ async function startXl1(): Promise<string> {
4949 } )
5050
5151 try {
52- // log out the mnemonic and wallet address using same steps as producer
53- const wallet = await generateXyoBaseWalletFromPhrase ( mnemonic )
54- const account = await wallet . derivePath ( ADDRESS_INDEX . XYO )
55-
56- console . log ( 'Generated mnemonic:' , mnemonic )
57- console . log ( 'Producer Wallet address:' , account . address )
52+ // Log out the mnemonic and signer address in case random was generated
53+ const account = await getSignerAccount ( )
54+ console . log ( 'Using signer mnemonic:' , mnemonic )
55+ console . log ( 'Using producer address:' , account . address )
5856
5957 // Spawn the XL1 process
6058 xl1Process = spawn ( 'node' , [ './node_modules/@xyo-network/xl1-cli/scripts/xl1.mjs' , '--logLevel="warn"' , '--producer.mnemonic' , JSON . stringify ( mnemonic ) ] , {
@@ -101,10 +99,8 @@ async function startXl1(): Promise<string> {
10199 }
102100}
103101
104- let mnemonic : string
105-
106102try {
107- mnemonic = await startXl1 ( )
103+ await startXl1 ( )
108104} catch ( ex ) {
109105 console . error ( 'Failed to start XL1:' , ex )
110106 // eslint-disable-next-line unicorn/no-process-exit
@@ -114,7 +110,7 @@ try {
114110console . log ( 'XL1 is ready, starting sample...' )
115111
116112try {
117- await helloWorld ( mnemonic )
113+ await helloWorld ( )
118114} catch ( error ) {
119115 console . error ( 'Error importing application:' , error )
120116}
0 commit comments