@xyo-network/xl1-cli 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/api/runApi.d.ts +6 -1
- package/build/commands/api/runApi.d.ts.map +1 -1
- package/build/commands/producer/runProducer.d.ts +7 -1
- package/build/commands/producer/runProducer.d.ts.map +1 -1
- package/build/commands/validator/runValidator.d.ts +7 -1
- package/build/commands/validator/runValidator.d.ts.map +1 -1
- package/build/initLogger.d.ts +3 -0
- package/build/initLogger.d.ts.map +1 -0
- package/build/node/index.mjs +70 -54
- package/build/node/index.mjs.map +1 -1
- package/build/node/xl1.mjs +82 -66
- package/build/node/xl1.mjs.map +1 -1
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +2 -1
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +1 -1
- package/build/orchestration/actor/implementation/ProducerActor.d.ts +2 -1
- package/build/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -1
- package/build/orchestration/actor/model/Actor.d.ts +2 -3
- package/build/orchestration/actor/model/Actor.d.ts.map +1 -1
- package/build/orchestration/actor/model/Orchestrator.d.ts +7 -4
- package/build/orchestration/actor/model/Orchestrator.d.ts.map +1 -1
- package/build/orchestration/archivists/StakeIntentState/local.d.ts.map +1 -1
- package/build/orchestration/initServices.d.ts +1 -1
- package/build/orchestration/initServices.d.ts.map +1 -1
- package/build/runCLI.d.ts +7 -1
- package/build/runCLI.d.ts.map +1 -1
- package/build/start.d.ts.map +1 -1
- package/dist/cli-min.mjs +9 -9
- package/package.json +32 -32
- package/src/commands/api/runApi.ts +8 -4
- package/src/commands/producer/runProducer.ts +13 -5
- package/src/commands/validator/runValidator.ts +10 -1
- package/src/initEnv.ts +1 -1
- package/src/initLogger.ts +15 -0
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +2 -2
- package/src/orchestration/actor/implementation/ProducerActor.ts +3 -3
- package/src/orchestration/actor/model/Actor.ts +3 -4
- package/src/orchestration/actor/model/Orchestrator.ts +17 -11
- package/src/orchestration/archivists/StakeIntentState/local.ts +0 -2
- package/src/orchestration/initServices.ts +6 -12
- package/src/runCLI.ts +16 -13
- package/src/start.ts +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/xl1-cli",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "XYO Layer One API",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -44,39 +44,39 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@opentelemetry/api": "^1.9.0",
|
|
47
|
-
"@xylabs/array": "^4.
|
|
48
|
-
"@xylabs/assert": "^4.
|
|
49
|
-
"@xylabs/base": "^4.
|
|
50
|
-
"@xylabs/creatable": "^4.
|
|
51
|
-
"@xylabs/delay": "^4.
|
|
52
|
-
"@xylabs/events": "^4.
|
|
53
|
-
"@xylabs/forget": "^4.
|
|
54
|
-
"@xylabs/hex": "^4.
|
|
55
|
-
"@xylabs/logger": "^4.
|
|
56
|
-
"@xylabs/promise": "^4.
|
|
57
|
-
"@xylabs/telemetry": "^4.
|
|
47
|
+
"@xylabs/array": "^4.13.5",
|
|
48
|
+
"@xylabs/assert": "^4.13.5",
|
|
49
|
+
"@xylabs/base": "^4.13.5",
|
|
50
|
+
"@xylabs/creatable": "^4.13.5",
|
|
51
|
+
"@xylabs/delay": "^4.13.5",
|
|
52
|
+
"@xylabs/events": "^4.13.5",
|
|
53
|
+
"@xylabs/forget": "^4.13.5",
|
|
54
|
+
"@xylabs/hex": "^4.13.5",
|
|
55
|
+
"@xylabs/logger": "^4.13.5",
|
|
56
|
+
"@xylabs/promise": "^4.13.5",
|
|
57
|
+
"@xylabs/telemetry": "^4.13.5",
|
|
58
58
|
"@xylabs/ts-scripts-yarn3": "^6.5.18",
|
|
59
59
|
"@xylabs/tsconfig": "^6.5.18",
|
|
60
|
-
"@xylabs/typeof": "^4.
|
|
61
|
-
"@xylabs/vitest-extended": "^4.
|
|
62
|
-
"@xyo-network/archivist-lmdb": "^4.0.
|
|
63
|
-
"@xyo-network/archivist-memory": "^4.0.
|
|
64
|
-
"@xyo-network/archivist-model": "^4.0.
|
|
65
|
-
"@xyo-network/chain-api": "^1.6.
|
|
66
|
-
"@xyo-network/chain-modules": "^1.6.
|
|
67
|
-
"@xyo-network/chain-orchestration": "^1.6.
|
|
68
|
-
"@xyo-network/chain-protocol": "^1.6.
|
|
69
|
-
"@xyo-network/chain-sdk": "^1.6.
|
|
70
|
-
"@xyo-network/chain-services": "^1.6.
|
|
71
|
-
"@xyo-network/chain-telemetry": "^1.6.
|
|
72
|
-
"@xyo-network/chain-utils": "^1.6.
|
|
73
|
-
"@xyo-network/chain-validation": "^1.6.
|
|
74
|
-
"@xyo-network/payload-builder": "^4.0.
|
|
75
|
-
"@xyo-network/payload-model": "^4.0.
|
|
76
|
-
"@xyo-network/wallet": "^4.0.
|
|
77
|
-
"@xyo-network/wallet-model": "^4.0.
|
|
78
|
-
"@xyo-network/xl1-protocol": "^1.6.
|
|
79
|
-
"@xyo-network/xl1-protocol-sdk": "^1.6.
|
|
60
|
+
"@xylabs/typeof": "^4.13.5",
|
|
61
|
+
"@xylabs/vitest-extended": "^4.13.5",
|
|
62
|
+
"@xyo-network/archivist-lmdb": "^4.0.3",
|
|
63
|
+
"@xyo-network/archivist-memory": "^4.0.3",
|
|
64
|
+
"@xyo-network/archivist-model": "^4.0.3",
|
|
65
|
+
"@xyo-network/chain-api": "^1.6.7",
|
|
66
|
+
"@xyo-network/chain-modules": "^1.6.6",
|
|
67
|
+
"@xyo-network/chain-orchestration": "^1.6.6",
|
|
68
|
+
"@xyo-network/chain-protocol": "^1.6.6",
|
|
69
|
+
"@xyo-network/chain-sdk": "^1.6.6",
|
|
70
|
+
"@xyo-network/chain-services": "^1.6.6",
|
|
71
|
+
"@xyo-network/chain-telemetry": "^1.6.6",
|
|
72
|
+
"@xyo-network/chain-utils": "^1.6.6",
|
|
73
|
+
"@xyo-network/chain-validation": "^1.6.6",
|
|
74
|
+
"@xyo-network/payload-builder": "^4.0.3",
|
|
75
|
+
"@xyo-network/payload-model": "^4.0.3",
|
|
76
|
+
"@xyo-network/wallet": "^4.0.3",
|
|
77
|
+
"@xyo-network/wallet-model": "^4.0.3",
|
|
78
|
+
"@xyo-network/xl1-protocol": "^1.6.2",
|
|
79
|
+
"@xyo-network/xl1-protocol-sdk": "^1.6.6",
|
|
80
80
|
"async-mutex": "^0.5.0",
|
|
81
81
|
"dotenv": "^17.2.0",
|
|
82
82
|
"ethers": "^6.15.0",
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger'
|
|
1
2
|
import { getServer } from '@xyo-network/chain-api'
|
|
2
|
-
import { config } from 'dotenv'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
interface RunApiContext {
|
|
5
|
+
logger?: Logger
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function runApi(context: RunApiContext) {
|
|
9
|
+
const { logger } = context
|
|
10
|
+
void getServer(undefined, undefined, logger)
|
|
7
11
|
}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger'
|
|
2
|
+
|
|
1
3
|
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
2
4
|
import {
|
|
3
5
|
BalanceActor, ChainHeadUpdateActor, initServices, ProducerActor,
|
|
4
6
|
} from '../../orchestration/index.ts'
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
interface RunProducerContext {
|
|
9
|
+
logger: Logger
|
|
10
|
+
orchestrator: Orchestrator
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const runProducer = async (context: RunProducerContext) => {
|
|
14
|
+
const { logger, orchestrator } = context
|
|
15
|
+
|
|
7
16
|
// Initialize services
|
|
8
|
-
|
|
9
|
-
const services = await initServices()
|
|
10
|
-
|
|
17
|
+
logger?.log('Services: Initializing...')
|
|
18
|
+
const services = await initServices(logger)
|
|
19
|
+
logger?.log('Services: Initialized')
|
|
11
20
|
|
|
12
21
|
// Create actors
|
|
13
22
|
const chainHeadUpdate = await ChainHeadUpdateActor.create(services)
|
|
14
23
|
const producer = await ProducerActor.create(services)
|
|
15
24
|
const balances = await BalanceActor.create(services)
|
|
16
25
|
const actors = [chainHeadUpdate, producer, balances]
|
|
17
|
-
// const actors = [chainHeadUpdate, producer]
|
|
18
26
|
|
|
19
27
|
for (const actor of actors) {
|
|
20
28
|
// Register the actor with the orchestrator
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger'
|
|
2
|
+
|
|
1
3
|
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
2
4
|
import { Actor } from '../../orchestration/index.ts'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
interface RunValidatorContext {
|
|
7
|
+
logger: Logger
|
|
8
|
+
orchestrator: Orchestrator
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const runValidator = async (context: RunValidatorContext) => {
|
|
12
|
+
const { orchestrator } = context
|
|
13
|
+
|
|
5
14
|
// Create a single actor
|
|
6
15
|
const myActor = new Actor('Validator', 'Validator', {})
|
|
7
16
|
|
package/src/initEnv.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Base } from '@xylabs/base'
|
|
2
|
+
import type { Logger } from '@xylabs/logger'
|
|
3
|
+
import { ConsoleLogger, LogLevel } from '@xylabs/logger'
|
|
4
|
+
import { isDefined } from '@xylabs/typeof'
|
|
5
|
+
|
|
6
|
+
export const initLogger = (): Logger => {
|
|
7
|
+
let level: LogLevel = LogLevel.info
|
|
8
|
+
if (isDefined(process.env.LOG_LEVEL)) {
|
|
9
|
+
const parsed = LogLevel[process.env.LOG_LEVEL.toLowerCase() as keyof typeof LogLevel]
|
|
10
|
+
if (isDefined(parsed)) level = parsed
|
|
11
|
+
}
|
|
12
|
+
const logger = new ConsoleLogger(level)
|
|
13
|
+
Base.defaultLogger = logger
|
|
14
|
+
return logger
|
|
15
|
+
}
|
|
@@ -2,6 +2,7 @@ import { filterAs } from '@xylabs/array'
|
|
|
2
2
|
import { assertEx } from '@xylabs/assert'
|
|
3
3
|
import type { BaseParams } from '@xylabs/base'
|
|
4
4
|
import { toHex } from '@xylabs/hex'
|
|
5
|
+
import type { Promisable } from '@xylabs/promise'
|
|
5
6
|
import { findMostRecentBlock, sortBlocks } from '@xyo-network/chain-protocol'
|
|
6
7
|
import type { Payload } from '@xyo-network/payload-model'
|
|
7
8
|
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
@@ -25,8 +26,7 @@ export class ChainHeadUpdateActor extends Actor<ChainHeadUpdateActorParams> {
|
|
|
25
26
|
return assertEx(this.params.chainIterator, () => 'chainIterator not set')
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
static
|
|
29
|
-
await Promise.resolve()
|
|
29
|
+
static create(params: ChainHeadUpdateActorParams): Promisable<ChainHeadUpdateActor> {
|
|
30
30
|
return new ChainHeadUpdateActor(params)
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import type { BaseParams } from '@xylabs/base'
|
|
3
3
|
import { toHex } from '@xylabs/hex'
|
|
4
|
+
import type { Promisable } from '@xylabs/promise'
|
|
4
5
|
import { isDefined, isUndefined } from '@xylabs/typeof'
|
|
5
6
|
import { createDeclarationIntent } from '@xyo-network/chain-protocol'
|
|
6
7
|
import { BaseBlockProducerService } from '@xyo-network/chain-services'
|
|
@@ -39,7 +40,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
39
40
|
protected _lastRedeclarationIntent: ChainStakeIntent | undefined
|
|
40
41
|
|
|
41
42
|
protected constructor(params: ProducerActorParams) {
|
|
42
|
-
super(
|
|
43
|
+
super(params.producer.address, 'Producer', params)
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
protected get account() {
|
|
@@ -74,8 +75,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
74
75
|
return assertEx(this.params.stakeIntentService, () => 'stakeIntentService not set')
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
static
|
|
78
|
-
await Promise.resolve()
|
|
78
|
+
static create(params: ProducerActorParams): Promisable<ProducerActor> {
|
|
79
79
|
return new ProducerActor(params)
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { TracerProvider } from '@opentelemetry/api'
|
|
2
|
-
import type
|
|
3
|
-
import { BaseEmitter } from '@xylabs/events'
|
|
2
|
+
import { Base, type BaseParams } from '@xylabs/base'
|
|
4
3
|
import { forget } from '@xylabs/forget'
|
|
5
4
|
import { IdLogger } from '@xylabs/logger'
|
|
6
5
|
import type { Promisable } from '@xylabs/promise'
|
|
@@ -15,14 +14,14 @@ export type ActorParams = BaseParams<{
|
|
|
15
14
|
traceProvider?: TracerProvider
|
|
16
15
|
}>
|
|
17
16
|
|
|
18
|
-
export class Actor<TParams extends ActorParams = ActorParams> extends
|
|
17
|
+
export class Actor<TParams extends ActorParams = ActorParams> extends Base<TParams> implements IActor {
|
|
19
18
|
protected readonly _timers: Map<string, ReturnType<typeof setTimeout>> = new Map()
|
|
20
19
|
private _active = false
|
|
21
20
|
private readonly _displayName: string
|
|
22
21
|
private readonly _id: string
|
|
23
22
|
|
|
24
23
|
constructor(id: string, displayName: string = 'Actor', params: TParams) {
|
|
25
|
-
const logger = params.logger ?? new IdLogger(console, () => `[${displayName} (${id})] `)
|
|
24
|
+
const logger = params.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `)
|
|
26
25
|
super({ ...params, logger })
|
|
27
26
|
this._displayName = displayName
|
|
28
27
|
this._id = id
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger'
|
|
2
|
+
|
|
3
|
+
import type { IActor } from './Actor.ts'
|
|
4
|
+
|
|
1
5
|
export interface IOrchestrator {
|
|
2
6
|
start(): Promise<void>
|
|
3
7
|
stop(): Promise<void>
|
|
4
8
|
}
|
|
5
9
|
|
|
6
|
-
import type { IActor } from './Actor.ts'
|
|
7
|
-
|
|
8
|
-
// TODO: Inject logger
|
|
9
10
|
export class Orchestrator implements IOrchestrator {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
protected actors: IActor[] = []
|
|
12
|
+
protected keepAliveHandle: NodeJS.Timeout | null = null
|
|
13
|
+
protected readonly logger?: Logger
|
|
14
|
+
protected running = false
|
|
15
|
+
|
|
16
|
+
constructor(logger?: Logger) {
|
|
17
|
+
this.logger = logger
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* Registers an actor.
|
|
@@ -29,11 +35,11 @@ export class Orchestrator implements IOrchestrator {
|
|
|
29
35
|
async start() {
|
|
30
36
|
await Promise.resolve()
|
|
31
37
|
if (this.running) {
|
|
32
|
-
|
|
38
|
+
this.logger?.warn('[Orchestrator] Already started.')
|
|
33
39
|
return
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
this.logger?.log('[Orchestrator] Starting...')
|
|
37
43
|
this.running = true
|
|
38
44
|
for (const actor of this.actors) {
|
|
39
45
|
await actor.start()
|
|
@@ -50,16 +56,16 @@ export class Orchestrator implements IOrchestrator {
|
|
|
50
56
|
async stop() {
|
|
51
57
|
await Promise.resolve()
|
|
52
58
|
if (!this.running) {
|
|
53
|
-
|
|
59
|
+
this.logger?.log('[Orchestrator] Already stopped.')
|
|
54
60
|
return
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
this.logger?.log('[Orchestrator] Stopping...')
|
|
58
64
|
for (const actor of this.actors) {
|
|
59
65
|
await actor.stop()
|
|
60
66
|
}
|
|
61
67
|
this.running = false
|
|
62
68
|
if (this.keepAliveHandle) clearInterval(this.keepAliveHandle)
|
|
63
|
-
|
|
69
|
+
this.logger?.log('[Orchestrator] Stopped...')
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -11,9 +11,7 @@ let singleton: ArchivistInstance | undefined
|
|
|
11
11
|
export const initLocalStakeIntentStateArchivist: Initializable<void, ArchivistInstance> = async (): Promise<ArchivistInstance> => {
|
|
12
12
|
return await mutex.runExclusive(async () => {
|
|
13
13
|
if (singleton) return singleton
|
|
14
|
-
console.log('[InitServices:LocalStakeIntentStateArchivist:Initializing]')
|
|
15
14
|
singleton = await getLocalPersistentArchivist('stakeIntent', 'state')
|
|
16
|
-
console.log('[InitServices:LocalStakeIntentStateArchivist:Initialized]')
|
|
17
15
|
return assertEx(singleton, () => new Error('Failed to initialize stake intent state archivist'))
|
|
18
16
|
})
|
|
19
17
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { Base } from '@xylabs/base'
|
|
3
2
|
import { asAddress } from '@xylabs/hex'
|
|
4
3
|
import type { Logger } from '@xylabs/logger'
|
|
5
4
|
import { isDefined } from '@xylabs/typeof'
|
|
6
5
|
import { balanceSummaryRepositoryFromMap } from '@xyo-network/chain-modules'
|
|
7
|
-
import type {
|
|
8
|
-
BaseBlockProducerServiceParams, BaseService, XyoValidatorParams,
|
|
9
|
-
} from '@xyo-network/chain-services'
|
|
6
|
+
import type { BaseBlockProducerServiceParams, XyoValidatorParams } from '@xyo-network/chain-services'
|
|
10
7
|
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
11
8
|
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
12
9
|
import { validateHydratedBlockState } from '@xyo-network/chain-validation'
|
|
@@ -43,15 +40,13 @@ const isStartable = (value: unknown): value is Startable => {
|
|
|
43
40
|
return isDefined((value as Startable).start) && typeof (value as Startable).start === 'function'
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
export const initServices = async (logger
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const statusReporter = new RuntimeStatusMonitor(logger ?? console)
|
|
43
|
+
export const initServices = async (logger: Logger): Promise<ChainServiceCollectionV2> => {
|
|
44
|
+
const statusReporter = new RuntimeStatusMonitor(logger)
|
|
50
45
|
statusReporter.onGlobalTransition({ to: 'started' }, () => {
|
|
51
|
-
|
|
46
|
+
logger.log('All services started.')
|
|
52
47
|
})
|
|
53
48
|
statusReporter.onGlobalTransition({ to: 'error' }, () => {
|
|
54
|
-
|
|
49
|
+
logger.error('Producer encountered an unhandled error!')
|
|
55
50
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
56
51
|
process.exit(1)
|
|
57
52
|
})
|
|
@@ -166,7 +161,6 @@ export const initServices = async (logger?: Logger): Promise<ChainServiceCollect
|
|
|
166
161
|
chainArchivist,
|
|
167
162
|
chainIterator,
|
|
168
163
|
chainStakeViewer,
|
|
169
|
-
logger: console,
|
|
170
164
|
stakeIntentStateArchivist,
|
|
171
165
|
traceProvider,
|
|
172
166
|
statusReporter,
|
|
@@ -229,7 +223,7 @@ export const initServices = async (logger?: Logger): Promise<ChainServiceCollect
|
|
|
229
223
|
stakeIntentService,
|
|
230
224
|
}
|
|
231
225
|
|
|
232
|
-
|
|
226
|
+
logger?.log('All services created. Starting...')
|
|
233
227
|
const startableServices = [balanceSummaryMap, ...Object.values(result)].filter(isStartable)
|
|
234
228
|
// Start all services that have a start method
|
|
235
229
|
await Promise.all(startableServices.map(service => service.start()))
|
package/src/runCLI.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import net from 'node:net'
|
|
2
2
|
|
|
3
|
+
import type { Logger } from '@xylabs/logger'
|
|
3
4
|
import yargs from 'yargs'
|
|
4
5
|
import { hideBin } from 'yargs/helpers'
|
|
5
6
|
|
|
@@ -33,21 +34,23 @@ function waitForPort(host: string, port: number): Promise<void> {
|
|
|
33
34
|
})
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
interface RunCliContext {
|
|
38
|
+
logger: Logger
|
|
39
|
+
orchestrator: Orchestrator
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
// Main entry point
|
|
37
|
-
export async function runCLI(
|
|
43
|
+
export async function runCLI(context: RunCliContext) {
|
|
38
44
|
async function validateTransaction() {
|
|
39
|
-
|
|
40
|
-
await Promise.resolve()
|
|
45
|
+
await Promise.reject('Not implemented yet')
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
async function submitTransaction() {
|
|
44
|
-
|
|
45
|
-
await Promise.resolve()
|
|
49
|
+
await Promise.reject('Not implemented yet')
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
async function checkBalance() {
|
|
49
|
-
|
|
50
|
-
await Promise.resolve()
|
|
53
|
+
await Promise.reject('Not implemented yet')
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
// Parse command-line arguments using Yargs
|
|
@@ -57,11 +60,11 @@ export async function runCLI(orchestrator: Orchestrator) {
|
|
|
57
60
|
.command('validator', 'Run the XL1 validator', (yargs) => {
|
|
58
61
|
return yargs
|
|
59
62
|
// Default command is to run
|
|
60
|
-
.command('$0', 'Run as a XL1 validator node', () => {}, () => runValidator(
|
|
63
|
+
.command('$0', 'Run as a XL1 validator node', () => {}, () => runValidator(context))
|
|
61
64
|
})
|
|
62
65
|
.command('producer', 'Run the XL1 producer', (yargs) => {
|
|
63
66
|
return yargs
|
|
64
|
-
.command('$0', 'Run as a XL1 producer node', () => {}, () => runProducer(
|
|
67
|
+
.command('$0', 'Run as a XL1 producer node', () => {}, () => runProducer(context))
|
|
65
68
|
})
|
|
66
69
|
.command('client', 'Client-related operations', (yargs) => {
|
|
67
70
|
return yargs
|
|
@@ -73,15 +76,15 @@ export async function runCLI(orchestrator: Orchestrator) {
|
|
|
73
76
|
})
|
|
74
77
|
.command('api', 'Run as a api node', (yargs) => {
|
|
75
78
|
return yargs
|
|
76
|
-
.command('$0', 'Run as a api node', () => {}, () => runApi())
|
|
77
|
-
.command('run', 'Run as a api node', () => {}, () => runApi())
|
|
79
|
+
.command('$0', 'Run as a api node', () => {}, () => runApi(context))
|
|
80
|
+
.command('run', 'Run as a api node', () => {}, () => runApi(context))
|
|
78
81
|
})
|
|
79
82
|
.command('$0', 'Run a full XL1 deployment', (yargs) => {
|
|
80
83
|
return yargs
|
|
81
84
|
.command('$0', 'Start the API and a producer', () => {}, async () => {
|
|
82
|
-
runApi()
|
|
85
|
+
runApi(context)
|
|
83
86
|
await waitForPort('localhost', 8080)
|
|
84
|
-
await runProducer(
|
|
87
|
+
await runProducer(context)
|
|
85
88
|
})
|
|
86
89
|
})
|
|
87
90
|
.command('account', 'Account-related operations', (yargs) => {
|
package/src/start.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { initEnv } from './initEnv.ts'
|
|
2
|
+
import { initLogger } from './initLogger.ts'
|
|
2
3
|
import { Orchestrator } from './orchestration/index.ts'
|
|
3
4
|
import { runCLI } from './runCLI.ts'
|
|
4
5
|
|
|
5
6
|
export const start = async () => {
|
|
6
7
|
initEnv()
|
|
7
|
-
const
|
|
8
|
+
const logger = initLogger()
|
|
9
|
+
const orchestrator = new Orchestrator(logger)
|
|
8
10
|
|
|
9
11
|
// Handle cancellation (Ctrl+C)
|
|
10
12
|
process.on('SIGINT', () => {
|
|
11
13
|
void (async () => {
|
|
12
14
|
try {
|
|
13
|
-
|
|
15
|
+
logger.log('\nSIGINT received. Attempting graceful shutdown...')
|
|
14
16
|
await orchestrator?.stop()
|
|
15
|
-
|
|
17
|
+
logger.log('Orchestrator stopped, exiting now.')
|
|
16
18
|
process.exit(0)
|
|
17
19
|
} catch (err) {
|
|
18
|
-
|
|
20
|
+
logger.error('Error stopping orchestrator:', err)
|
|
19
21
|
process.exit(1)
|
|
20
22
|
}
|
|
21
23
|
})()
|
|
22
24
|
})
|
|
23
25
|
|
|
24
26
|
// Execute the CLI logic
|
|
25
|
-
await runCLI(orchestrator)
|
|
27
|
+
await runCLI({ logger, orchestrator })
|
|
26
28
|
}
|