@xyo-network/xl1-cli 1.6.2
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/LICENSE +165 -0
- package/README.md +23 -0
- package/build/commands/api/index.d.ts +2 -0
- package/build/commands/api/index.d.ts.map +1 -0
- package/build/commands/api/runApi.d.ts +2 -0
- package/build/commands/api/runApi.d.ts.map +1 -0
- package/build/commands/index.d.ts +4 -0
- package/build/commands/index.d.ts.map +1 -0
- package/build/commands/producer/createDeclaration.d.ts +2 -0
- package/build/commands/producer/createDeclaration.d.ts.map +1 -0
- package/build/commands/producer/index.d.ts +3 -0
- package/build/commands/producer/index.d.ts.map +1 -0
- package/build/commands/producer/runProducer.d.ts +3 -0
- package/build/commands/producer/runProducer.d.ts.map +1 -0
- package/build/commands/validator/index.d.ts +2 -0
- package/build/commands/validator/index.d.ts.map +1 -0
- package/build/commands/validator/runValidator.d.ts +3 -0
- package/build/commands/validator/runValidator.d.ts.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/initEnv.d.ts +2 -0
- package/build/initEnv.d.ts.map +1 -0
- package/build/node/index.mjs +1502 -0
- package/build/node/index.mjs.map +1 -0
- package/build/node/xl1.mjs +1474 -0
- package/build/node/xl1.mjs.map +1 -0
- package/build/orchestration/actor/implementation/BalanceActor.d.ts +17 -0
- package/build/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +16 -0
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/ProducerActor.d.ts +25 -0
- package/build/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/index.d.ts +4 -0
- package/build/orchestration/actor/implementation/index.d.ts.map +1 -0
- package/build/orchestration/actor/index.d.ts +3 -0
- package/build/orchestration/actor/index.d.ts.map +1 -0
- package/build/orchestration/actor/model/Actor.d.ts +38 -0
- package/build/orchestration/actor/model/Actor.d.ts.map +1 -0
- package/build/orchestration/actor/model/Orchestrator.d.ts +24 -0
- package/build/orchestration/actor/model/Orchestrator.d.ts.map +1 -0
- package/build/orchestration/actor/model/index.d.ts +3 -0
- package/build/orchestration/actor/model/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/archivist.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/index.d.ts +2 -0
- package/build/orchestration/archivists/ChainFinalized/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/local.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/local.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/remote.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/index.d.ts +2 -0
- package/build/orchestration/archivists/ChainSubmissions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/remote.d.ts +4 -0
- package/build/orchestration/archivists/ChainSubmissions/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/index.d.ts +2 -0
- package/build/orchestration/archivists/PendingTransactions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/local.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/local.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/remote.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/index.d.ts +2 -0
- package/build/orchestration/archivists/RejectedTransactions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/local.d.ts +4 -0
- package/build/orchestration/archivists/RejectedTransactions/local.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/archivist.d.ts +4 -0
- package/build/orchestration/archivists/StakeIntentState/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/index.d.ts +2 -0
- package/build/orchestration/archivists/StakeIntentState/index.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/local.d.ts +4 -0
- package/build/orchestration/archivists/StakeIntentState/local.d.ts.map +1 -0
- package/build/orchestration/archivists/index.d.ts +6 -0
- package/build/orchestration/archivists/index.d.ts.map +1 -0
- package/build/orchestration/archivists/lib/index.d.ts +2 -0
- package/build/orchestration/archivists/lib/index.d.ts.map +1 -0
- package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts +12 -0
- package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +1 -0
- package/build/orchestration/health/index.d.ts +2 -0
- package/build/orchestration/health/index.d.ts.map +1 -0
- package/build/orchestration/health/initHealthEndpoints.d.ts +7 -0
- package/build/orchestration/health/initHealthEndpoints.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultHost.d.ts +12 -0
- package/build/orchestration/host/implementation/DefaultHost.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts +24 -0
- package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts +7 -0
- package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts.map +1 -0
- package/build/orchestration/host/implementation/index.d.ts +3 -0
- package/build/orchestration/host/implementation/index.d.ts.map +1 -0
- package/build/orchestration/host/index.d.ts +3 -0
- package/build/orchestration/host/index.d.ts.map +1 -0
- package/build/orchestration/host/model/Host.d.ts +19 -0
- package/build/orchestration/host/model/Host.d.ts.map +1 -0
- package/build/orchestration/host/model/ServiceCollection.d.ts +20 -0
- package/build/orchestration/host/model/ServiceCollection.d.ts.map +1 -0
- package/build/orchestration/host/model/ServiceProvider.d.ts +4 -0
- package/build/orchestration/host/model/ServiceProvider.d.ts.map +1 -0
- package/build/orchestration/host/model/index.d.ts +4 -0
- package/build/orchestration/host/model/index.d.ts.map +1 -0
- package/build/orchestration/index.d.ts +6 -0
- package/build/orchestration/index.d.ts.map +1 -0
- package/build/orchestration/initServices.d.ts +4 -0
- package/build/orchestration/initServices.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/index.d.ts +2 -0
- package/build/orchestration/map/BalanceSummary/index.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts +7 -0
- package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/local.d.ts +6 -0
- package/build/orchestration/map/BalanceSummary/local.d.ts.map +1 -0
- package/build/orchestration/map/driver/index.d.ts +2 -0
- package/build/orchestration/map/driver/index.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/Params.d.ts +7 -0
- package/build/orchestration/map/driver/lmdb/Params.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts +32 -0
- package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/index.d.ts +2 -0
- package/build/orchestration/map/driver/lmdb/index.d.ts.map +1 -0
- package/build/orchestration/map/index.d.ts +3 -0
- package/build/orchestration/map/index.d.ts.map +1 -0
- package/build/orchestration/map/localPersistentMap.d.ts +12 -0
- package/build/orchestration/map/localPersistentMap.d.ts.map +1 -0
- package/build/orchestration/repository/index.d.ts +2 -0
- package/build/orchestration/repository/index.d.ts.map +1 -0
- package/build/orchestration/repository/lib/index.d.ts +2 -0
- package/build/orchestration/repository/lib/index.d.ts.map +1 -0
- package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts +6 -0
- package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts.map +1 -0
- package/build/orchestration/services/implementation/account.d.ts +4 -0
- package/build/orchestration/services/implementation/account.d.ts.map +1 -0
- package/build/orchestration/services/implementation/balance.d.ts +4 -0
- package/build/orchestration/services/implementation/balance.d.ts.map +1 -0
- package/build/orchestration/services/implementation/chain/evm.d.ts +6 -0
- package/build/orchestration/services/implementation/chain/evm.d.ts.map +1 -0
- package/build/orchestration/services/implementation/chain/index.d.ts +4 -0
- package/build/orchestration/services/implementation/chain/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/index.d.ts +2 -0
- package/build/orchestration/services/implementation/evm/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initChainId.d.ts +3 -0
- package/build/orchestration/services/implementation/evm/initChainId.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts +4 -0
- package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts +5 -0
- package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts +5 -0
- package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/head.d.ts +10 -0
- package/build/orchestration/services/implementation/head.d.ts.map +1 -0
- package/build/orchestration/services/implementation/index.d.ts +11 -0
- package/build/orchestration/services/implementation/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/iterator.d.ts +6 -0
- package/build/orchestration/services/implementation/iterator.d.ts.map +1 -0
- package/build/orchestration/services/implementation/pendingTransactions.d.ts +4 -0
- package/build/orchestration/services/implementation/pendingTransactions.d.ts.map +1 -0
- package/build/orchestration/services/implementation/producer.d.ts +4 -0
- package/build/orchestration/services/implementation/producer.d.ts.map +1 -0
- package/build/orchestration/services/implementation/reward.d.ts +4 -0
- package/build/orchestration/services/implementation/reward.d.ts.map +1 -0
- package/build/orchestration/services/implementation/validator.d.ts +4 -0
- package/build/orchestration/services/implementation/validator.d.ts.map +1 -0
- package/build/orchestration/services/index.d.ts +2 -0
- package/build/orchestration/services/index.d.ts.map +1 -0
- package/build/orchestration/status/RuntimeStatusMonitor.d.ts +31 -0
- package/build/orchestration/status/RuntimeStatusMonitor.d.ts.map +1 -0
- package/build/orchestration/status/ServiceStatus.d.ts +9 -0
- package/build/orchestration/status/ServiceStatus.d.ts.map +1 -0
- package/build/orchestration/status/index.d.ts +3 -0
- package/build/orchestration/status/index.d.ts.map +1 -0
- package/build/orchestration/store/StoreKind.d.ts +2 -0
- package/build/orchestration/store/StoreKind.d.ts.map +1 -0
- package/build/orchestration/store/getStoreDirectory.d.ts +9 -0
- package/build/orchestration/store/getStoreDirectory.d.ts.map +1 -0
- package/build/orchestration/store/index.d.ts +3 -0
- package/build/orchestration/store/index.d.ts.map +1 -0
- package/build/runCLI.d.ts +3 -0
- package/build/runCLI.d.ts.map +1 -0
- package/build/start.d.ts +2 -0
- package/build/start.d.ts.map +1 -0
- package/build/xl1.d.ts +2 -0
- package/build/xl1.d.ts.map +1 -0
- package/dist/cli-min.mjs +400 -0
- package/nodemon.json +9 -0
- package/package.json +97 -0
- package/rollup.config.mjs +73 -0
- package/scripts/xl1.mjs +3 -0
- package/src/commands/api/index.ts +1 -0
- package/src/commands/api/runApi.ts +7 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/producer/createDeclaration.ts +17 -0
- package/src/commands/producer/index.ts +2 -0
- package/src/commands/producer/runProducer.ts +25 -0
- package/src/commands/validator/index.ts +1 -0
- package/src/commands/validator/runValidator.ts +13 -0
- package/src/index.ts +3 -0
- package/src/initEnv.ts +8 -0
- package/src/orchestration/actor/implementation/BalanceActor.ts +51 -0
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +65 -0
- package/src/orchestration/actor/implementation/ProducerActor.ts +250 -0
- package/src/orchestration/actor/implementation/index.ts +3 -0
- package/src/orchestration/actor/index.ts +2 -0
- package/src/orchestration/actor/model/Actor.ts +113 -0
- package/src/orchestration/actor/model/Orchestrator.ts +65 -0
- package/src/orchestration/actor/model/index.ts +2 -0
- package/src/orchestration/archivists/ChainFinalized/archivist.ts +27 -0
- package/src/orchestration/archivists/ChainFinalized/index.ts +1 -0
- package/src/orchestration/archivists/ChainFinalized/local.ts +16 -0
- package/src/orchestration/archivists/ChainFinalized/remote.ts +18 -0
- package/src/orchestration/archivists/ChainSubmissions/archivist.ts +19 -0
- package/src/orchestration/archivists/ChainSubmissions/index.ts +1 -0
- package/src/orchestration/archivists/ChainSubmissions/remote.ts +18 -0
- package/src/orchestration/archivists/PendingTransactions/archivist.ts +29 -0
- package/src/orchestration/archivists/PendingTransactions/index.ts +1 -0
- package/src/orchestration/archivists/PendingTransactions/local.ts +20 -0
- package/src/orchestration/archivists/PendingTransactions/remote.ts +18 -0
- package/src/orchestration/archivists/RejectedTransactions/archivist.ts +18 -0
- package/src/orchestration/archivists/RejectedTransactions/index.ts +1 -0
- package/src/orchestration/archivists/RejectedTransactions/local.ts +20 -0
- package/src/orchestration/archivists/StakeIntentState/archivist.ts +19 -0
- package/src/orchestration/archivists/StakeIntentState/index.ts +1 -0
- package/src/orchestration/archivists/StakeIntentState/local.ts +19 -0
- package/src/orchestration/archivists/index.ts +5 -0
- package/src/orchestration/archivists/lib/index.ts +1 -0
- package/src/orchestration/archivists/lib/localPersistentArchivist.ts +44 -0
- package/src/orchestration/health/index.ts +1 -0
- package/src/orchestration/health/initHealthEndpoints.ts +70 -0
- package/src/orchestration/host/implementation/DefaultHost.ts +25 -0
- package/src/orchestration/host/implementation/DefaultServiceCollection.ts +60 -0
- package/src/orchestration/host/implementation/DefaultServiceProvider.ts +12 -0
- package/src/orchestration/host/implementation/index.ts +2 -0
- package/src/orchestration/host/index.ts +2 -0
- package/src/orchestration/host/model/Host.ts +21 -0
- package/src/orchestration/host/model/ServiceCollection.ts +22 -0
- package/src/orchestration/host/model/ServiceProvider.ts +3 -0
- package/src/orchestration/host/model/index.ts +3 -0
- package/src/orchestration/index.ts +5 -0
- package/src/orchestration/initServices.ts +237 -0
- package/src/orchestration/map/BalanceSummary/index.ts +1 -0
- package/src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts +22 -0
- package/src/orchestration/map/BalanceSummary/local.ts +19 -0
- package/src/orchestration/map/driver/index.ts +1 -0
- package/src/orchestration/map/driver/lmdb/Params.ts +7 -0
- package/src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts +67 -0
- package/src/orchestration/map/driver/lmdb/index.ts +1 -0
- package/src/orchestration/map/index.ts +2 -0
- package/src/orchestration/map/localPersistentMap.ts +39 -0
- package/src/orchestration/repository/index.ts +1 -0
- package/src/orchestration/repository/lib/index.ts +1 -0
- package/src/orchestration/repository/lib/repositoryFromArchivist.ts +27 -0
- package/src/orchestration/services/implementation/account.ts +23 -0
- package/src/orchestration/services/implementation/balance.ts +13 -0
- package/src/orchestration/services/implementation/chain/evm.ts +35 -0
- package/src/orchestration/services/implementation/chain/index.ts +27 -0
- package/src/orchestration/services/implementation/evm/index.ts +1 -0
- package/src/orchestration/services/implementation/evm/initChainId.ts +18 -0
- package/src/orchestration/services/implementation/evm/initEvmProvider.ts +21 -0
- package/src/orchestration/services/implementation/evm/initGanacheProvider.ts +19 -0
- package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +25 -0
- package/src/orchestration/services/implementation/head.ts +44 -0
- package/src/orchestration/services/implementation/index.ts +10 -0
- package/src/orchestration/services/implementation/iterator.ts +36 -0
- package/src/orchestration/services/implementation/pendingTransactions.ts +14 -0
- package/src/orchestration/services/implementation/producer.ts +13 -0
- package/src/orchestration/services/implementation/reward.ts +37 -0
- package/src/orchestration/services/implementation/validator.ts +14 -0
- package/src/orchestration/services/index.ts +1 -0
- package/src/orchestration/status/RuntimeStatusMonitor.ts +117 -0
- package/src/orchestration/status/ServiceStatus.ts +21 -0
- package/src/orchestration/status/index.ts +2 -0
- package/src/orchestration/store/StoreKind.ts +1 -0
- package/src/orchestration/store/getStoreDirectory.ts +15 -0
- package/src/orchestration/store/index.ts +2 -0
- package/src/runCLI.ts +96 -0
- package/src/spec/MultiProducer.ChainOutput.json +864 -0
- package/src/start.ts +26 -0
- package/src/xl1.ts +6 -0
- package/vitest.config.ts +11 -0
- package/xy.config.ts +11 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import type { BaseAccountableServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import { MemoryChainService } from '@xyo-network/chain-services'
|
|
4
|
+
import type { ChainService, Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
import { canUseEvmContractChainService, initEvmContractChainService } from './evm.ts'
|
|
7
|
+
|
|
8
|
+
let chainStakeServiceSingleton: Promisable<ChainService> | undefined
|
|
9
|
+
|
|
10
|
+
export const initChainService: Initializable<BaseAccountableServiceParams, ChainService> = ({ account }) => init({ name: 'ChainService', account })
|
|
11
|
+
|
|
12
|
+
const init: Initializable<BaseAccountableServiceParams, ChainService> = ({
|
|
13
|
+
account, traceProvider, meterProvider, logger,
|
|
14
|
+
}): Promisable<ChainService> => {
|
|
15
|
+
if (chainStakeServiceSingleton) return chainStakeServiceSingleton
|
|
16
|
+
chainStakeServiceSingleton = canUseEvmContractChainService()
|
|
17
|
+
? initEvmContractChainService({
|
|
18
|
+
name: 'ChainStakeService',
|
|
19
|
+
account,
|
|
20
|
+
traceProvider,
|
|
21
|
+
meterProvider,
|
|
22
|
+
logger,
|
|
23
|
+
})
|
|
24
|
+
: MemoryChainService.create({})
|
|
25
|
+
// Create service
|
|
26
|
+
return chainStakeServiceSingleton
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './initEvmProvider.ts'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { hexFrom, isHex } from '@xylabs/hex'
|
|
3
|
+
|
|
4
|
+
export const canUseChainId = (): boolean => {
|
|
5
|
+
return process.env.XYO_JSON_RPC_NETWORK !== undefined
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const getChainId = () => {
|
|
9
|
+
const chainId = assertEx(process.env.XYO_JSON_RPC_NETWORK, () => 'Missing XYO_JSON_RPC_NETWORK ENV VAR')
|
|
10
|
+
if (isHex(chainId, { prefix: true })) {
|
|
11
|
+
const hex = hexFrom(chainId)
|
|
12
|
+
const parsed = Number.parseInt(hex, 16)
|
|
13
|
+
return parsed
|
|
14
|
+
} else {
|
|
15
|
+
const parsed = Number.parseInt(chainId, 10)
|
|
16
|
+
return parsed
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { JsonRpcProvider } from 'ethers/providers'
|
|
3
|
+
|
|
4
|
+
import { canUseJsonRpcProvider, initJsonRpcProvider } from './initGanacheProvider.ts'
|
|
5
|
+
import { canUseInfuraProvider, initInfuraProvider } from './initInfuraProvider.ts'
|
|
6
|
+
|
|
7
|
+
let provider: Promise<JsonRpcProvider> | undefined
|
|
8
|
+
|
|
9
|
+
export const initEvmProvider = async () => {
|
|
10
|
+
if (provider) return provider
|
|
11
|
+
if (canUseInfuraProvider()) {
|
|
12
|
+
provider = initInfuraProvider()
|
|
13
|
+
} else if (canUseJsonRpcProvider()) {
|
|
14
|
+
provider = initJsonRpcProvider()
|
|
15
|
+
}
|
|
16
|
+
return assertEx(await provider, () => 'Error: No provider available')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const canUseEvmProvider = () => {
|
|
20
|
+
return canUseInfuraProvider() || canUseJsonRpcProvider()
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { JsonRpcProvider } from 'ethers/providers'
|
|
3
|
+
|
|
4
|
+
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
5
|
+
|
|
6
|
+
export const initJsonRpcProvider = () => {
|
|
7
|
+
const config = getJsonRpcProviderConfig()
|
|
8
|
+
return Promise.resolve(new JsonRpcProvider(...config))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const canUseJsonRpcProvider = () => {
|
|
12
|
+
return canUseChainId()
|
|
13
|
+
&& process.env.XYO_JSON_RPC_URL !== undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getJsonRpcProviderConfig = () => {
|
|
17
|
+
const jsonRpcUrl = assertEx(process.env.XYO_JSON_RPC_URL, () => 'Missing XYO_JSON_RPC_URL ENV VAR')
|
|
18
|
+
return [jsonRpcUrl, getChainId()] as const
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { InfuraProvider } from 'ethers/providers'
|
|
3
|
+
|
|
4
|
+
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
5
|
+
|
|
6
|
+
let instance: Promise<InfuraProvider> | undefined
|
|
7
|
+
|
|
8
|
+
export const initInfuraProvider = () => {
|
|
9
|
+
if (instance) return instance
|
|
10
|
+
const config = getInfuraProviderConfig()
|
|
11
|
+
instance = Promise.resolve(new InfuraProvider(...config))
|
|
12
|
+
return instance
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const canUseInfuraProvider = (): boolean => {
|
|
16
|
+
return canUseChainId()
|
|
17
|
+
&& process.env.INFURA_PROJECT_ID != undefined
|
|
18
|
+
&& process.env.INFURA_PROJECT_SECRET != undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getInfuraProviderConfig = () => {
|
|
22
|
+
const projectId = assertEx(process.env.INFURA_PROJECT_ID, () => 'Missing INFURA_PROJECT_ID ENV VAR')
|
|
23
|
+
const projectSecret = assertEx(process.env.INFURA_PROJECT_SECRET, () => 'Missing INFURA_PROJECT_SECRET ENV VAR')
|
|
24
|
+
return [getChainId(), projectId, projectSecret] as const
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { delay } from '@xylabs/delay'
|
|
2
|
+
import { ZERO_ADDRESS } from '@xylabs/hex'
|
|
3
|
+
import type { Promisable } from '@xylabs/promise'
|
|
4
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
5
|
+
import { createGenesisBlock, findMostRecentBlock } from '@xyo-network/chain-protocol'
|
|
6
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
+
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
8
|
+
import type { BlockBoundWitness, Initializable } from '@xyo-network/xl1-protocol'
|
|
9
|
+
import { flattenHydratedBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
+
|
|
11
|
+
let headSingleton: Promisable<WithStorageMeta<BlockBoundWitness>> | undefined
|
|
12
|
+
|
|
13
|
+
const createBootstrapHead = async (
|
|
14
|
+
chainSubmissionsArchivistWrite: ArchivistInstance,
|
|
15
|
+
chainArchivist: ArchivistInstance,
|
|
16
|
+
account: WalletInstance,
|
|
17
|
+
): Promise<WithStorageMeta<BlockBoundWitness>> => {
|
|
18
|
+
const block = await createGenesisBlock(account, ZERO_ADDRESS, 10_000_000n, account.address)
|
|
19
|
+
const [bw] = block
|
|
20
|
+
await chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(block))
|
|
21
|
+
// Wait for block to show up in finalized archivist
|
|
22
|
+
while (true) {
|
|
23
|
+
const result = await chainArchivist.get([bw._hash])
|
|
24
|
+
if (result.length > 0) break
|
|
25
|
+
await delay(1000) // Wait 1 second before retrying
|
|
26
|
+
}
|
|
27
|
+
return bw
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const initHead: Initializable<{
|
|
31
|
+
account: WalletInstance
|
|
32
|
+
chainArchivist: ArchivistInstance
|
|
33
|
+
chainSubmissionsArchivistWrite: ArchivistInstance
|
|
34
|
+
}, WithStorageMeta<BlockBoundWitness>>
|
|
35
|
+
= async (params): Promise<WithStorageMeta<BlockBoundWitness>> => {
|
|
36
|
+
const {
|
|
37
|
+
account, chainArchivist, chainSubmissionsArchivistWrite,
|
|
38
|
+
} = params
|
|
39
|
+
if (headSingleton) return headSingleton
|
|
40
|
+
let head = await findMostRecentBlock(chainArchivist)
|
|
41
|
+
if (!head) head = await createBootstrapHead(chainSubmissionsArchivistWrite, chainArchivist, account)
|
|
42
|
+
headSingleton = head
|
|
43
|
+
return headSingleton
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './account.ts'
|
|
2
|
+
export * from './balance.ts'
|
|
3
|
+
export * from './chain/index.ts'
|
|
4
|
+
export * from './evm/index.ts'
|
|
5
|
+
export * from './head.ts'
|
|
6
|
+
export * from './iterator.ts'
|
|
7
|
+
export * from './pendingTransactions.ts'
|
|
8
|
+
export * from './producer.ts'
|
|
9
|
+
export * from './reward.ts'
|
|
10
|
+
export * from './validator.ts'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseElectionServicesParams,
|
|
3
|
+
XyoChainIteratorParams,
|
|
4
|
+
XyoStakeIntentServiceParams,
|
|
5
|
+
} from '@xyo-network/chain-services'
|
|
6
|
+
import {
|
|
7
|
+
BaseElectionService, ChainBlockNumberIterationService,
|
|
8
|
+
XyoStakeIntentService,
|
|
9
|
+
} from '@xyo-network/chain-services'
|
|
10
|
+
import type {
|
|
11
|
+
ElectionService, EventingChainBlockNumberIterator, Initializable, StakeIntentService,
|
|
12
|
+
} from '@xyo-network/xl1-protocol'
|
|
13
|
+
|
|
14
|
+
let chainIteratorServiceSingleton: Promise<EventingChainBlockNumberIterator> | undefined
|
|
15
|
+
let stakeIntentServiceSingleton: Promise<StakeIntentService> | undefined
|
|
16
|
+
let electionServiceSingleton: Promise<ElectionService> | undefined
|
|
17
|
+
|
|
18
|
+
export const initChainIterator: Initializable<XyoChainIteratorParams, EventingChainBlockNumberIterator> = (params) => {
|
|
19
|
+
if (chainIteratorServiceSingleton) return chainIteratorServiceSingleton
|
|
20
|
+
chainIteratorServiceSingleton = ChainBlockNumberIterationService.create(params)
|
|
21
|
+
return chainIteratorServiceSingleton
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const initStakeIntentService: Initializable<XyoStakeIntentServiceParams, StakeIntentService>
|
|
25
|
+
= (params) => {
|
|
26
|
+
if (stakeIntentServiceSingleton) return stakeIntentServiceSingleton
|
|
27
|
+
stakeIntentServiceSingleton = XyoStakeIntentService.create(params)
|
|
28
|
+
return stakeIntentServiceSingleton
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const initElectionService: Initializable<BaseElectionServicesParams, ElectionService>
|
|
32
|
+
= (params) => {
|
|
33
|
+
if (electionServiceSingleton) return electionServiceSingleton
|
|
34
|
+
electionServiceSingleton = BaseElectionService.create(params)
|
|
35
|
+
return electionServiceSingleton
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import type { BasePendingTransactionsServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import { BasePendingTransactionsService } from '@xyo-network/chain-services'
|
|
4
|
+
import type { Initializable, PendingTransactionsService } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
let serviceSingleton: Promisable<PendingTransactionsService> | undefined
|
|
7
|
+
|
|
8
|
+
export const initPendingTransactions: Initializable<BasePendingTransactionsServiceParams, PendingTransactionsService> = async (
|
|
9
|
+
params: BasePendingTransactionsServiceParams,
|
|
10
|
+
): Promise<PendingTransactionsService> => {
|
|
11
|
+
if (serviceSingleton) return serviceSingleton
|
|
12
|
+
serviceSingleton = await BasePendingTransactionsService.create(params)
|
|
13
|
+
return serviceSingleton
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import type { BaseBlockProducerServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import { BaseBlockProducerService } from '@xyo-network/chain-services'
|
|
4
|
+
import type { BlockProducerService, Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
let serviceSingleton: Promisable<BlockProducerService> | undefined
|
|
7
|
+
|
|
8
|
+
export const initBlockProducer: Initializable<BaseBlockProducerServiceParams, BlockProducerService>
|
|
9
|
+
= async (params: BaseBlockProducerServiceParams): Promise<BlockProducerService> => {
|
|
10
|
+
if (serviceSingleton) return serviceSingleton
|
|
11
|
+
serviceSingleton = await BaseBlockProducerService.create(params)
|
|
12
|
+
return serviceSingleton
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { BaseBlockRewardServiceParams, EvmBlockRewardServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import { EvmBlockRewardService, MemoryBlockRewardService } from '@xyo-network/chain-services'
|
|
4
|
+
import type { BlockRewardService, Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
import { canUseEvmProvider, initEvmProvider } from './evm/index.ts'
|
|
7
|
+
|
|
8
|
+
let rewardServiceSingleton: Promise<BlockRewardService> | undefined
|
|
9
|
+
|
|
10
|
+
export const initBlockRewardService: Initializable<
|
|
11
|
+
BaseBlockRewardServiceParams | EvmBlockRewardServiceParams,
|
|
12
|
+
BlockRewardService
|
|
13
|
+
> = (params): Promise<BlockRewardService> => {
|
|
14
|
+
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
15
|
+
rewardServiceSingleton = canUseEvmBlockRewardService() ? initEvmBlockRewardService(params as EvmBlockRewardServiceParams) : initXyoBlockRewardService(params)
|
|
16
|
+
return rewardServiceSingleton
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const initXyoBlockRewardService = (params: BaseBlockRewardServiceParams): Promise<BlockRewardService> => {
|
|
20
|
+
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
21
|
+
rewardServiceSingleton = MemoryBlockRewardService.create(params)
|
|
22
|
+
return rewardServiceSingleton
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const canUseEvmBlockRewardService = () => canUseEvmProvider()
|
|
26
|
+
|
|
27
|
+
const initEvmBlockRewardService = async (params: EvmBlockRewardServiceParams): Promise<BlockRewardService> => {
|
|
28
|
+
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
29
|
+
const { account: paramsAccount } = params
|
|
30
|
+
const account = assertEx(paramsAccount, () => 'Error: Account is required')
|
|
31
|
+
const provider = assertEx(await initEvmProvider())
|
|
32
|
+
const evmBlockRewardServiceParams: EvmBlockRewardServiceParams = {
|
|
33
|
+
...params, provider, account,
|
|
34
|
+
}
|
|
35
|
+
rewardServiceSingleton = EvmBlockRewardService.create(evmBlockRewardServiceParams)
|
|
36
|
+
return rewardServiceSingleton
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import type { BaseBlockProducerServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import type { BlockProducerService, Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
+
|
|
5
|
+
import { initBlockProducer } from './producer.ts'
|
|
6
|
+
|
|
7
|
+
let serviceSingleton: Promisable<BlockProducerService> | undefined
|
|
8
|
+
|
|
9
|
+
export const initValidator: Initializable<BaseBlockProducerServiceParams, BlockProducerService>
|
|
10
|
+
= (params: BaseBlockProducerServiceParams): Promisable<BlockProducerService> => {
|
|
11
|
+
if (serviceSingleton) return serviceSingleton
|
|
12
|
+
serviceSingleton = initBlockProducer(params)
|
|
13
|
+
return serviceSingleton
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './implementation/index.ts'
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CreatableStatus } from '@xylabs/creatable'
|
|
2
|
+
|
|
3
|
+
import { LoggerStatusReporter } from './ServiceStatus.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enum-like record for statuses with priority allowing
|
|
7
|
+
* for determination of the aggregated status.
|
|
8
|
+
*/
|
|
9
|
+
const statusPriority: Record<CreatableStatus, number> = {
|
|
10
|
+
error: 0,
|
|
11
|
+
stopped: 1,
|
|
12
|
+
stopping: 2,
|
|
13
|
+
creating: 3,
|
|
14
|
+
created: 4,
|
|
15
|
+
starting: 5,
|
|
16
|
+
started: 6,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A sentinel status that represents the initial state
|
|
21
|
+
* before any statuses are reported.
|
|
22
|
+
* It is used to ensure that the monitor has a valid status
|
|
23
|
+
* even when no statuses have been reported yet and to
|
|
24
|
+
* prevent the system from showing an "error" state
|
|
25
|
+
* when no statuses are available.
|
|
26
|
+
*/
|
|
27
|
+
const SENTINEL_STATUS: CreatableStatus = 'starting'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Given an array of statuses, this function reduces them
|
|
31
|
+
* to the minimum status based on the defined priority.
|
|
32
|
+
* @param statuses An array of statuses to reduce.
|
|
33
|
+
* @returns The minimum status based on priority.
|
|
34
|
+
*/
|
|
35
|
+
const reduceToMinimumStatus = (statuses: CreatableStatus[]): CreatableStatus => {
|
|
36
|
+
let minStatus: CreatableStatus = SENTINEL_STATUS
|
|
37
|
+
let minPriority = Infinity
|
|
38
|
+
|
|
39
|
+
for (const status of statuses) {
|
|
40
|
+
const priority = statusPriority[status]
|
|
41
|
+
if (priority < minPriority) {
|
|
42
|
+
minPriority = priority
|
|
43
|
+
minStatus = status
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return minStatus
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type GlobalTransitionHandler = {
|
|
50
|
+
from?: CreatableStatus
|
|
51
|
+
handler: (from: CreatableStatus, to: CreatableStatus) => void
|
|
52
|
+
to?: CreatableStatus
|
|
53
|
+
}
|
|
54
|
+
export type TransitionHandler = GlobalTransitionHandler & {
|
|
55
|
+
name?: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class RuntimeStatusMonitor extends LoggerStatusReporter {
|
|
59
|
+
private globalTransitions: GlobalTransitionHandler[] = []
|
|
60
|
+
private transitions: TransitionHandler[] = []
|
|
61
|
+
|
|
62
|
+
getGlobalStatus(): CreatableStatus {
|
|
63
|
+
// If no statuses have been reported, return the sentinel status
|
|
64
|
+
if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS
|
|
65
|
+
return reduceToMinimumStatus(Object.values(this.statusMap))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getStatus(name: string): CreatableStatus | undefined {
|
|
69
|
+
return this.statusMap[name]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onGlobalTransition(match: { from?: CreatableStatus; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
73
|
+
this.globalTransitions.push({ ...match, handler })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Register a callback to be called on a specific transition.
|
|
78
|
+
*/
|
|
79
|
+
onTransition(match: { from?: CreatableStatus; name: string; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
80
|
+
this.transitions.push({ ...match, handler })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override report(name: string, status: CreatableStatus, progress?: number | Error): void {
|
|
84
|
+
// Capture the current status before updating
|
|
85
|
+
const previous = this.statusMap[name]
|
|
86
|
+
const previousGlobal = this.getGlobalStatus()
|
|
87
|
+
|
|
88
|
+
// Update the status map with the new status
|
|
89
|
+
super.report(name, status, progress)
|
|
90
|
+
|
|
91
|
+
// If the status hasn't changed, do not run handlers
|
|
92
|
+
if (previous === status) return
|
|
93
|
+
this.runTransitions(this.transitions, previous, status, name)
|
|
94
|
+
|
|
95
|
+
// If the global status hasn't changed, do not run handlers
|
|
96
|
+
const globalStatus = this.getGlobalStatus()
|
|
97
|
+
if (previousGlobal === globalStatus) return
|
|
98
|
+
this.runTransitions(this.globalTransitions, previousGlobal, globalStatus)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private runTransitions(
|
|
102
|
+
transitions: (TransitionHandler | GlobalTransitionHandler)[],
|
|
103
|
+
prev: CreatableStatus,
|
|
104
|
+
next: CreatableStatus,
|
|
105
|
+
name?: string,
|
|
106
|
+
) {
|
|
107
|
+
for (const {
|
|
108
|
+
from, to, name: matchName, handler,
|
|
109
|
+
} of transitions as TransitionHandler[]) {
|
|
110
|
+
if ((matchName === undefined || matchName === name)
|
|
111
|
+
&& (from === undefined || from === prev)
|
|
112
|
+
&& (to === undefined || to === next)) {
|
|
113
|
+
handler(prev, next)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CreatableName, CreatableStatus, CreatableStatusReporter,
|
|
3
|
+
} from '@xylabs/creatable'
|
|
4
|
+
import type { Logger } from '@xylabs/logger'
|
|
5
|
+
|
|
6
|
+
export class LoggerStatusReporter implements CreatableStatusReporter {
|
|
7
|
+
protected logger: Logger
|
|
8
|
+
|
|
9
|
+
protected statusMap: Record<CreatableName, CreatableStatus> = {}
|
|
10
|
+
|
|
11
|
+
constructor(logger: Logger) {
|
|
12
|
+
this.logger = logger
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
report(name: string, status: CreatableStatus, progress?: number | Error): void {
|
|
16
|
+
this.statusMap[name] = status
|
|
17
|
+
const starting = (Object.entries(this.statusMap).map(([, value]): number => value === 'starting' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
18
|
+
const started = (Object.entries(this.statusMap).map(([, value]): number => value === 'started' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
19
|
+
this.logger.info(`${started}/${starting + started} ${name} status: ${status}`, { progress })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type StoreKind = 'lmdb'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import type { StoreKind } from './StoreKind.ts'
|
|
4
|
+
|
|
5
|
+
const STORAGE_ROOT = process.env.STORAGE_ROOT ?? Path.join(process.cwd(), '.store')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a convention-based directory path for an archivist store
|
|
9
|
+
* @param name The name of the archivist
|
|
10
|
+
* @param kind The kind of the archivist (optional)
|
|
11
|
+
* @returns The directory path for the archivist store
|
|
12
|
+
*/
|
|
13
|
+
export const getStoreDirectory = (name: string, kind?: StoreKind): string => {
|
|
14
|
+
return (kind === undefined) ? Path.join(STORAGE_ROOT, name) : Path.join(STORAGE_ROOT, kind, name)
|
|
15
|
+
}
|
package/src/runCLI.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
|
|
3
|
+
import yargs from 'yargs'
|
|
4
|
+
import { hideBin } from 'yargs/helpers'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
runApi, runProducer, runValidator,
|
|
8
|
+
} from './commands/index.ts'
|
|
9
|
+
import type { Orchestrator } from './orchestration/index.ts'
|
|
10
|
+
|
|
11
|
+
function waitForPort(host: string, port: number): Promise<void> {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const tryConnect = () => {
|
|
14
|
+
const socket = new net.Socket()
|
|
15
|
+
|
|
16
|
+
socket
|
|
17
|
+
.setTimeout(1000)
|
|
18
|
+
.once('error', () => {
|
|
19
|
+
socket.destroy()
|
|
20
|
+
setTimeout(tryConnect, 500) // retry after 500ms
|
|
21
|
+
})
|
|
22
|
+
.once('timeout', () => {
|
|
23
|
+
socket.destroy()
|
|
24
|
+
setTimeout(tryConnect, 500)
|
|
25
|
+
})
|
|
26
|
+
.connect(port, host, () => {
|
|
27
|
+
socket.end()
|
|
28
|
+
resolve()
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
tryConnect()
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Main entry point
|
|
37
|
+
export async function runCLI(orchestrator: Orchestrator) {
|
|
38
|
+
async function validateTransaction() {
|
|
39
|
+
console.log('Validating transaction...')
|
|
40
|
+
await Promise.resolve()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function submitTransaction() {
|
|
44
|
+
console.log('Submitting transaction...')
|
|
45
|
+
await Promise.resolve()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function checkBalance() {
|
|
49
|
+
console.log('Checking account balance...')
|
|
50
|
+
await Promise.resolve()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Parse command-line arguments using Yargs
|
|
54
|
+
const argv = yargs(hideBin(process.argv))
|
|
55
|
+
// .commandDir('./command/commands', opts) // Not yet supported for ESM
|
|
56
|
+
// .wrap((yargs as Argv).terminalWidth())
|
|
57
|
+
.command('validator', 'Run the XL1 validator', (yargs) => {
|
|
58
|
+
return yargs
|
|
59
|
+
// Default command is to run
|
|
60
|
+
.command('$0', 'Run as a XL1 validator node', () => {}, () => runValidator(orchestrator))
|
|
61
|
+
})
|
|
62
|
+
.command('producer', 'Run the XL1 producer', (yargs) => {
|
|
63
|
+
return yargs
|
|
64
|
+
.command('$0', 'Run as a XL1 producer node', () => {}, () => runProducer(orchestrator))
|
|
65
|
+
})
|
|
66
|
+
.command('client', 'Client-related operations', (yargs) => {
|
|
67
|
+
return yargs
|
|
68
|
+
.command('transaction', 'Transaction-related operations', (yargs) => {
|
|
69
|
+
return yargs
|
|
70
|
+
.command('validate', 'Validate a transaction', () => {}, validateTransaction)
|
|
71
|
+
.command('submit', 'Submit a transaction', () => {}, submitTransaction)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
.command('api', 'Run as a api node', (yargs) => {
|
|
75
|
+
return yargs
|
|
76
|
+
.command('$0', 'Run as a api node', () => {}, () => runApi())
|
|
77
|
+
.command('run', 'Run as a api node', () => {}, () => runApi())
|
|
78
|
+
})
|
|
79
|
+
.command('$0', 'Run a full XL1 deployment', (yargs) => {
|
|
80
|
+
return yargs
|
|
81
|
+
.command('$0', 'Start the API and a producer', () => {}, async () => {
|
|
82
|
+
runApi()
|
|
83
|
+
await waitForPort('localhost', 8080)
|
|
84
|
+
await runProducer(orchestrator)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
.command('account', 'Account-related operations', (yargs) => {
|
|
88
|
+
return yargs.command('balance', 'Check account balance', () => {}, checkBalance)
|
|
89
|
+
})
|
|
90
|
+
.help()
|
|
91
|
+
.alias('help', 'h')
|
|
92
|
+
.env('XL1')
|
|
93
|
+
.argv
|
|
94
|
+
|
|
95
|
+
await argv
|
|
96
|
+
}
|