@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,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ServiceCollection, ServiceDescriptor, ServiceProvider,
|
|
3
|
+
} from '../model/index.ts'
|
|
4
|
+
import { ServiceLifetime } from '../model/index.ts'
|
|
5
|
+
import { DefaultServiceProvider } from './DefaultServiceProvider.ts'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A collection of service descriptors, allowing adding/removing services before building.
|
|
9
|
+
*/
|
|
10
|
+
export class DefaultServiceCollection implements ServiceCollection {
|
|
11
|
+
private readonly descriptors: ServiceDescriptor[] = []
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Register a service as Singleton: a single instance is created and shared.
|
|
15
|
+
*/
|
|
16
|
+
addSingleton<T>(
|
|
17
|
+
identifier: string | symbol,
|
|
18
|
+
implementationFactory: () => T,
|
|
19
|
+
): void {
|
|
20
|
+
this.descriptors.push({
|
|
21
|
+
identifier,
|
|
22
|
+
lifetime: ServiceLifetime.Singleton,
|
|
23
|
+
implementationFactory,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register a service as Transient: a new instance is created on each request.
|
|
29
|
+
*/
|
|
30
|
+
addTransient<T>(
|
|
31
|
+
_identifier: string | symbol,
|
|
32
|
+
_implementationFactory: () => T,
|
|
33
|
+
): void {
|
|
34
|
+
throw new Error('Not implemented')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Build a concrete, immutable service provider from the current descriptors.
|
|
39
|
+
*/
|
|
40
|
+
build(): ServiceProvider {
|
|
41
|
+
const services: Record<string, unknown> = {}
|
|
42
|
+
for (const descriptor of this.descriptors) {
|
|
43
|
+
if (descriptor.lifetime === ServiceLifetime.Singleton) {
|
|
44
|
+
services[descriptor.identifier.toString()] = descriptor.implementationFactory()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return new DefaultServiceProvider(services)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Removes all registrations matching the given identifier.
|
|
52
|
+
*/
|
|
53
|
+
remove(identifier: string | symbol): void {
|
|
54
|
+
for (let i = this.descriptors.length - 1; i >= 0; i--) {
|
|
55
|
+
if (this.descriptors[i].identifier === identifier) {
|
|
56
|
+
this.descriptors.splice(i, 1)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ServiceProvider } from '../model/index.ts'
|
|
2
|
+
|
|
3
|
+
export class DefaultServiceProvider implements ServiceProvider {
|
|
4
|
+
protected _services: Record<string, unknown>
|
|
5
|
+
constructor(services: Record<string, unknown>) {
|
|
6
|
+
this._services = services
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getService<T>(serviceIdentifier: string): T | undefined {
|
|
10
|
+
return this._services[serviceIdentifier] as T
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServiceProvider } from './ServiceProvider.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the host for an application.
|
|
5
|
+
*/
|
|
6
|
+
export interface Host {
|
|
7
|
+
/**
|
|
8
|
+
* Provides access to the application's services (for dependency injection).
|
|
9
|
+
*/
|
|
10
|
+
services: ServiceProvider
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Starts the host and any underlying services (e.g., background tasks).
|
|
14
|
+
*/
|
|
15
|
+
start(): Promise<void>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Stops the host and attempts to gracefully shut down services.
|
|
19
|
+
*/
|
|
20
|
+
stop(): Promise<void>
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServiceProvider } from './ServiceProvider.ts'
|
|
2
|
+
|
|
3
|
+
export interface ServiceCollection {
|
|
4
|
+
build(): ServiceProvider
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the lifetime of a service
|
|
9
|
+
*/
|
|
10
|
+
export const ServiceLifetime = {
|
|
11
|
+
Singleton: 'Singleton',
|
|
12
|
+
Transient: 'Transient',
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Describes a single service registration
|
|
17
|
+
*/
|
|
18
|
+
export interface ServiceDescriptor<T = unknown> {
|
|
19
|
+
identifier: string | symbol
|
|
20
|
+
implementationFactory: () => T
|
|
21
|
+
lifetime: keyof typeof ServiceLifetime
|
|
22
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Base } from '@xylabs/base'
|
|
3
|
+
import { asAddress } from '@xylabs/hex'
|
|
4
|
+
import type { Logger } from '@xylabs/logger'
|
|
5
|
+
import { isDefined } from '@xylabs/typeof'
|
|
6
|
+
import { balanceSummaryRepositoryFromMap } from '@xyo-network/chain-modules'
|
|
7
|
+
import type {
|
|
8
|
+
BaseBlockProducerServiceParams, BaseService, XyoValidatorParams,
|
|
9
|
+
} from '@xyo-network/chain-services'
|
|
10
|
+
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
11
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
12
|
+
import { validateHydratedBlockState } from '@xyo-network/chain-validation'
|
|
13
|
+
import type { ChainServiceCollectionV2 } from '@xyo-network/xl1-protocol-sdk'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
initChainFinalizedArchivist, initChainSubmissionsArchivist, initPendingBundledTransactionsArchivist, initRejectedTransactionsArchivist,
|
|
17
|
+
initStakeIntentStateArchivist,
|
|
18
|
+
} from './archivists/index.ts'
|
|
19
|
+
import { initHealthEndpoints } from './health/initHealthEndpoints.ts'
|
|
20
|
+
import { initBalanceSummaryMap } from './map/index.ts'
|
|
21
|
+
import {
|
|
22
|
+
initAccount, initBalanceService, initBlockProducer, initBlockRewardService, initChainIterator, initChainService, initElectionService, initHead,
|
|
23
|
+
initPendingTransactions, initStakeIntentService,
|
|
24
|
+
} from './services/index.ts'
|
|
25
|
+
import { RuntimeStatusMonitor } from './status/index.ts'
|
|
26
|
+
|
|
27
|
+
const telemetryConfig = {
|
|
28
|
+
attributes: {
|
|
29
|
+
serviceName: 'xl1-producer',
|
|
30
|
+
serviceVersion: '1.0.0',
|
|
31
|
+
},
|
|
32
|
+
metricsConfig: {
|
|
33
|
+
endpoint: '/metrics',
|
|
34
|
+
port: 9464,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Startable {
|
|
39
|
+
start: () => Promise<void>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isStartable = (value: unknown): value is Startable => {
|
|
43
|
+
return isDefined((value as Startable).start) && typeof (value as Startable).start === 'function'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const initServices = async (logger?: Logger): Promise<ChainServiceCollectionV2> => {
|
|
47
|
+
Base.defaultLogger = logger ?? console
|
|
48
|
+
|
|
49
|
+
const statusReporter = new RuntimeStatusMonitor(logger ?? console)
|
|
50
|
+
statusReporter.onGlobalTransition({ to: 'started' }, () => {
|
|
51
|
+
Base.defaultLogger?.log('All services started.')
|
|
52
|
+
})
|
|
53
|
+
statusReporter.onGlobalTransition({ to: 'error' }, () => {
|
|
54
|
+
Base.defaultLogger?.error('Producer encountered an unhandled error!')
|
|
55
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
56
|
+
process.exit(1)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
await startupSpanAsync('initHealthEndpoints', () => initHealthEndpoints({ statusReporter }))
|
|
60
|
+
|
|
61
|
+
const [
|
|
62
|
+
{ traceProvider, meterProvider },
|
|
63
|
+
account,
|
|
64
|
+
] = await Promise.all([
|
|
65
|
+
startupSpanAsync('initTelemetry', () => initTelemetry(telemetryConfig)),
|
|
66
|
+
startupSpanAsync('initAccount', () => initAccount()),
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
// Archivists
|
|
70
|
+
const [
|
|
71
|
+
chainArchivist,
|
|
72
|
+
[pendingBundledTransactionsArchivist, pendingBundledTransactionsArchivistWrite],
|
|
73
|
+
rejectedTransactionsArchivist,
|
|
74
|
+
chainSubmissionsArchivistWrite,
|
|
75
|
+
stakeIntentStateArchivist,
|
|
76
|
+
chainService,
|
|
77
|
+
balanceSummaryMap,
|
|
78
|
+
] = await Promise.all([
|
|
79
|
+
startupSpanAsync(
|
|
80
|
+
'ChainFinalizedArchivist',
|
|
81
|
+
() => initChainFinalizedArchivist(traceProvider),
|
|
82
|
+
),
|
|
83
|
+
startupSpanAsync(
|
|
84
|
+
'PendingBundledTransactionsArchivist',
|
|
85
|
+
() => initPendingBundledTransactionsArchivist(traceProvider),
|
|
86
|
+
),
|
|
87
|
+
startupSpanAsync(
|
|
88
|
+
'RejectedTransactionsArchivist',
|
|
89
|
+
() => initRejectedTransactionsArchivist(traceProvider),
|
|
90
|
+
),
|
|
91
|
+
startupSpanAsync(
|
|
92
|
+
'ChainSubmissionsArchivist',
|
|
93
|
+
() => initChainSubmissionsArchivist(),
|
|
94
|
+
),
|
|
95
|
+
startupSpanAsync(
|
|
96
|
+
'StakeIntentStateArchivist',
|
|
97
|
+
() => initStakeIntentStateArchivist(),
|
|
98
|
+
),
|
|
99
|
+
startupSpanAsync(
|
|
100
|
+
'ChainService',
|
|
101
|
+
() => initChainService({ account, name: 'ChainService' }),
|
|
102
|
+
),
|
|
103
|
+
startupSpanAsync(
|
|
104
|
+
'BalanceSummaryMap',
|
|
105
|
+
() => initBalanceSummaryMap(traceProvider),
|
|
106
|
+
),
|
|
107
|
+
])
|
|
108
|
+
|
|
109
|
+
const chainId = chainService.chainId
|
|
110
|
+
const chainContractViewer = chainService
|
|
111
|
+
const chainStakeViewer = chainService
|
|
112
|
+
const chainStaker = chainService
|
|
113
|
+
const head = await startupSpanAsync('initHead', () => initHead({
|
|
114
|
+
account, chainArchivist, chainSubmissionsArchivistWrite,
|
|
115
|
+
}))
|
|
116
|
+
const [
|
|
117
|
+
pendingTransactionsService,
|
|
118
|
+
rewardService,
|
|
119
|
+
chainIterator,
|
|
120
|
+
balanceService,
|
|
121
|
+
] = await Promise.all([
|
|
122
|
+
startupSpanAsync('PendingTransactions', () => initPendingTransactions({
|
|
123
|
+
name: 'PendingTransactionsService',
|
|
124
|
+
chainArchivist,
|
|
125
|
+
chainId,
|
|
126
|
+
meterProvider,
|
|
127
|
+
pendingBundledTransactionsArchivist,
|
|
128
|
+
rejectedTransactionsArchivist,
|
|
129
|
+
traceProvider,
|
|
130
|
+
statusReporter,
|
|
131
|
+
})),
|
|
132
|
+
startupSpanAsync(
|
|
133
|
+
'RewardService',
|
|
134
|
+
() => initBlockRewardService({
|
|
135
|
+
name: 'RewardService',
|
|
136
|
+
account,
|
|
137
|
+
chainService,
|
|
138
|
+
traceProvider,
|
|
139
|
+
statusReporter,
|
|
140
|
+
}),
|
|
141
|
+
),
|
|
142
|
+
startupSpanAsync(
|
|
143
|
+
'ChainIterator',
|
|
144
|
+
() => initChainIterator({
|
|
145
|
+
name: 'ChainIterator',
|
|
146
|
+
traceProvider,
|
|
147
|
+
chainArchivist,
|
|
148
|
+
head,
|
|
149
|
+
statusReporter,
|
|
150
|
+
}),
|
|
151
|
+
),
|
|
152
|
+
startupSpanAsync(
|
|
153
|
+
'BalanceService',
|
|
154
|
+
() => initBalanceService({
|
|
155
|
+
name: 'BalanceService',
|
|
156
|
+
chainArchivist,
|
|
157
|
+
summaryRepository: balanceSummaryRepositoryFromMap(balanceSummaryMap),
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
const stakeIntentService = await startupSpanAsync(
|
|
163
|
+
'StakeIntentService',
|
|
164
|
+
() => initStakeIntentService({
|
|
165
|
+
name: 'StakeIntentService',
|
|
166
|
+
chainArchivist,
|
|
167
|
+
chainIterator,
|
|
168
|
+
chainStakeViewer,
|
|
169
|
+
logger: console,
|
|
170
|
+
stakeIntentStateArchivist,
|
|
171
|
+
traceProvider,
|
|
172
|
+
statusReporter,
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
const electionService = await startupSpanAsync(
|
|
177
|
+
'ElectionService',
|
|
178
|
+
() => initElectionService({
|
|
179
|
+
name: 'ElectionService',
|
|
180
|
+
traceProvider,
|
|
181
|
+
chainIterator,
|
|
182
|
+
chainStakeViewer,
|
|
183
|
+
stakeIntentService,
|
|
184
|
+
statusReporter,
|
|
185
|
+
}),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
const validatorParams: XyoValidatorParams = {
|
|
189
|
+
name: 'Validator',
|
|
190
|
+
account,
|
|
191
|
+
chainId,
|
|
192
|
+
pendingBundledTransactionsArchivist,
|
|
193
|
+
chainArchivist,
|
|
194
|
+
electionService,
|
|
195
|
+
rewardService,
|
|
196
|
+
stakeIntentService,
|
|
197
|
+
traceProvider,
|
|
198
|
+
validateHydratedBlockState,
|
|
199
|
+
}
|
|
200
|
+
const rewardAddress = isDefined(process.env.XYO_BLOCK_REWARD_ADDRESS)
|
|
201
|
+
? assertEx(asAddress(process.env.XYO_BLOCK_REWARD_ADDRESS), () => 'Invalid block reward address provided')
|
|
202
|
+
: account.address
|
|
203
|
+
const producerParams: BaseBlockProducerServiceParams = {
|
|
204
|
+
...validatorParams,
|
|
205
|
+
name: 'Producer',
|
|
206
|
+
balanceService,
|
|
207
|
+
chainArchivist,
|
|
208
|
+
pendingBundledTransactionsArchivist,
|
|
209
|
+
pendingTransactionsService,
|
|
210
|
+
rejectedTransactionsArchivist,
|
|
211
|
+
rewardAddress,
|
|
212
|
+
}
|
|
213
|
+
const producer = await startupSpanAsync('Producer', () => initBlockProducer(producerParams))
|
|
214
|
+
// TODO: Add to base service collection
|
|
215
|
+
const result: ChainServiceCollectionV2 = {
|
|
216
|
+
account,
|
|
217
|
+
balanceService,
|
|
218
|
+
chainArchivist,
|
|
219
|
+
chainContractViewer,
|
|
220
|
+
chainIterator,
|
|
221
|
+
chainStaker,
|
|
222
|
+
chainStakeViewer,
|
|
223
|
+
chainSubmissionsArchivistWrite,
|
|
224
|
+
electionService,
|
|
225
|
+
pendingBundledTransactionsArchivistWrite,
|
|
226
|
+
pendingTransactionsService,
|
|
227
|
+
producer,
|
|
228
|
+
rewardService,
|
|
229
|
+
stakeIntentService,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
Base.defaultLogger?.log('All services created. Starting...')
|
|
233
|
+
const startableServices = [balanceSummaryMap, ...Object.values(result)].filter(isStartable)
|
|
234
|
+
// Start all services that have a start method
|
|
235
|
+
await Promise.all(startableServices.map(service => service.start()))
|
|
236
|
+
return result
|
|
237
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './initBalanceSummaryMap.ts'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TracerProvider } from '@opentelemetry/api'
|
|
2
|
+
import type { Hash } from '@xylabs/hex'
|
|
3
|
+
import { isDefined } from '@xylabs/typeof'
|
|
4
|
+
import type { MapType } from '@xyo-network/chain-protocol'
|
|
5
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
6
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
+
import type { BalancesStepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
+
import { Mutex } from 'async-mutex'
|
|
9
|
+
|
|
10
|
+
import { initLocalBalanceSummaryMap } from './local.ts'
|
|
11
|
+
|
|
12
|
+
const mutex = new Mutex()
|
|
13
|
+
let singleton: MapType<Hash, WithStorageMeta<BalancesStepSummary>> | undefined
|
|
14
|
+
|
|
15
|
+
export async function initBalanceSummaryMap(_traceProvider: TracerProvider): Promise<MapType<Hash, WithStorageMeta<BalancesStepSummary>>> {
|
|
16
|
+
return await mutex.runExclusive(async () => {
|
|
17
|
+
if (isDefined(singleton)) return singleton
|
|
18
|
+
const local = await startupSpanAsync('BalanceSummaryMap:initLocal', () => initLocalBalanceSummaryMap())
|
|
19
|
+
singleton = local
|
|
20
|
+
return singleton
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/hex'
|
|
2
|
+
import { isDefined } from '@xylabs/typeof'
|
|
3
|
+
import type { MapType } from '@xyo-network/chain-protocol'
|
|
4
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
+
import type { BalancesStepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
+
import { Mutex } from 'async-mutex'
|
|
7
|
+
|
|
8
|
+
import { getLocalPersistentMap } from '../localPersistentMap.ts'
|
|
9
|
+
|
|
10
|
+
const mutex = new Mutex()
|
|
11
|
+
let singleton: MapType<Hash, WithStorageMeta<BalancesStepSummary>> | undefined
|
|
12
|
+
|
|
13
|
+
export const initLocalBalanceSummaryMap = async (): Promise<MapType<Hash, WithStorageMeta<BalancesStepSummary>>> => {
|
|
14
|
+
return await mutex.runExclusive(async () => {
|
|
15
|
+
if (isDefined(singleton)) return singleton
|
|
16
|
+
singleton = await getLocalPersistentMap<Hash, WithStorageMeta<BalancesStepSummary>>('balance', 'summary')
|
|
17
|
+
return singleton
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lmdb/index.ts'
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { creatable } from '@xylabs/creatable'
|
|
2
|
+
import { SynchronousMap } from '@xyo-network/chain-protocol'
|
|
3
|
+
import { BaseService } from '@xyo-network/chain-services'
|
|
4
|
+
import {
|
|
5
|
+
Database, Key, open, RootDatabase,
|
|
6
|
+
} from 'lmdb'
|
|
7
|
+
|
|
8
|
+
import { LmdbMapParams } from './Params.ts'
|
|
9
|
+
|
|
10
|
+
// TODO: Abstract creatable instead of service?
|
|
11
|
+
/**
|
|
12
|
+
* A synchronous LMDB-backed Map implementation.
|
|
13
|
+
* This class provides a synchronous interface to an LMDB database, allowing for key-value storage.
|
|
14
|
+
* It allows for multi-tenancy within a single LMDB environment by using a root database (located
|
|
15
|
+
* at this.folderPath) and a specific DB within the environment (specified by this.params.storeName).
|
|
16
|
+
* @template K - The type of keys in the map.
|
|
17
|
+
* @template V - The type of values in the map.
|
|
18
|
+
*/
|
|
19
|
+
@creatable()
|
|
20
|
+
export class SynchronousLmdbMap<K extends Key, V> extends BaseService<LmdbMapParams> implements SynchronousMap<K, V> {
|
|
21
|
+
protected db!: Database<V, K>
|
|
22
|
+
protected rootDatabase!: RootDatabase
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The path to the LMDB folder where the database is stored.
|
|
26
|
+
* This is constructed from the location and dbName parameters
|
|
27
|
+
* allowing for multiple DBs within the root (by specifying a
|
|
28
|
+
* different storeName).
|
|
29
|
+
* @returns The folder path for the LMDB database.
|
|
30
|
+
*/
|
|
31
|
+
get folderPath() {
|
|
32
|
+
return `${this.params.location}/${this.params.dbName}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
all(): V[] {
|
|
36
|
+
return [...this.db.getRange({})].map(entry => entry.value)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clear(): void {
|
|
40
|
+
this.db.clearSync()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
delete(id: K): boolean {
|
|
44
|
+
return this.db.removeSync(id)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get(id: K): V | undefined {
|
|
48
|
+
return this.db.get(id)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
has(id: K): boolean {
|
|
52
|
+
return this.db.doesExist(id)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set(id: K, data: V): this {
|
|
56
|
+
this.db.putSync(id, data)
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override async startHandler(): Promise<void> {
|
|
61
|
+
await super.startHandler()
|
|
62
|
+
// Initialize the DB Environment (opens the default LMDB database)
|
|
63
|
+
this.rootDatabase = open({ path: this.folderPath })
|
|
64
|
+
// Open the desired DB (using the store name)
|
|
65
|
+
this.db = this.rootDatabase.openDB<V, K>({ name: this.params.storeName })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SynchronousLmdbMap.ts'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import type { MapType } from '@xyo-network/chain-protocol'
|
|
4
|
+
|
|
5
|
+
import type { StoreKind } from '../store/index.ts'
|
|
6
|
+
import { getStoreDirectory } from '../store/index.ts'
|
|
7
|
+
import { SynchronousLmdbMap } from './driver/index.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a local persistent map
|
|
11
|
+
* @param dbName The name of the database
|
|
12
|
+
* @param storeName The name of the store
|
|
13
|
+
* @param kind The kind of the map
|
|
14
|
+
* @returns a map
|
|
15
|
+
*/
|
|
16
|
+
export const getLocalPersistentMap = async <TId, TData>(dbName: string, storeName: string, kind: StoreKind = 'lmdb'): Promise<MapType<TId, TData>> => {
|
|
17
|
+
switch (kind) {
|
|
18
|
+
case 'lmdb': {
|
|
19
|
+
const location = getStoreDirectory(dbName, 'lmdb')
|
|
20
|
+
const store = await SynchronousLmdbMap.create({
|
|
21
|
+
location, dbName, storeName,
|
|
22
|
+
})
|
|
23
|
+
return store as unknown as MapType<TId, TData>
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const deleteLocalPersistentMap = async (dbName: string, _storeName: string, kind: StoreKind = 'lmdb'): Promise<void> => {
|
|
29
|
+
await Promise.resolve()
|
|
30
|
+
console.warn(`Deleting local persistent map for ${dbName} of kind ${kind}.`)
|
|
31
|
+
let location = ''
|
|
32
|
+
switch (kind) {
|
|
33
|
+
case 'lmdb': {
|
|
34
|
+
location = getStoreDirectory(dbName, 'lmdb')
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
await rm(location, { recursive: true, force: true })
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/index.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './repositoryFromArchivist.ts'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { filterAs } from '@xylabs/array'
|
|
2
|
+
import type { Hash } from '@xylabs/hex'
|
|
3
|
+
import type { AnyNonPromise } from '@xylabs/promise'
|
|
4
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
5
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
|
+
import type { PayloadRepository } from '@xyo-network/xl1-protocol'
|
|
7
|
+
|
|
8
|
+
export const repositoryFromArchivist = <T extends Payload = Payload>(
|
|
9
|
+
archivist: ArchivistInstance,
|
|
10
|
+
predicate: (value: AnyNonPromise) => WithStorageMeta<T>) => {
|
|
11
|
+
const repository: PayloadRepository<Hash, WithStorageMeta<T>> = {
|
|
12
|
+
get: async (hashes: Hash[]) => {
|
|
13
|
+
const payloads = await archivist.get(hashes)
|
|
14
|
+
const filtered = filterAs(payloads, predicate)
|
|
15
|
+
return filtered
|
|
16
|
+
},
|
|
17
|
+
insert: async (payloads: T[]) => {
|
|
18
|
+
const filtered = filterAs(payloads, predicate)
|
|
19
|
+
await archivist.insert(filtered)
|
|
20
|
+
return filtered
|
|
21
|
+
},
|
|
22
|
+
next: () => {
|
|
23
|
+
throw new Error('Not implemented')
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
return repository
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import { isUndefined } from '@xylabs/typeof'
|
|
3
|
+
import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from '@xyo-network/chain-protocol'
|
|
4
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
5
|
+
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
6
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
7
|
+
|
|
8
|
+
let accountServiceSingleton: Promisable<WalletInstance> | undefined
|
|
9
|
+
|
|
10
|
+
export const initAccount: Initializable<void, WalletInstance> = async (): Promise<WalletInstance> => {
|
|
11
|
+
if (accountServiceSingleton) return accountServiceSingleton
|
|
12
|
+
let walletPhrase = process.env.XYO_WALLET_MNEMONIC
|
|
13
|
+
if (isUndefined(walletPhrase)) {
|
|
14
|
+
console.log('No wallet mnemonic specified!')
|
|
15
|
+
const randomMnemonic = HDWallet.generateMnemonic()
|
|
16
|
+
console.log(`Using randomly generated mnemonic: ${randomMnemonic}`)
|
|
17
|
+
walletPhrase = randomMnemonic
|
|
18
|
+
}
|
|
19
|
+
const wallet = await generateXyoBaseWalletFromPhrase(walletPhrase)
|
|
20
|
+
const account = await wallet.derivePath(ADDRESS_INDEX.XYO)
|
|
21
|
+
accountServiceSingleton = account
|
|
22
|
+
return accountServiceSingleton
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise'
|
|
2
|
+
import type { BaseAccountBalanceServiceParams } from '@xyo-network/chain-services'
|
|
3
|
+
import { BaseAccountBalanceService } from '@xyo-network/chain-services'
|
|
4
|
+
import type { AccountBalanceServiceV2, Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
let balanceServiceSingleton: Promisable<AccountBalanceServiceV2> | undefined
|
|
7
|
+
|
|
8
|
+
export const initBalanceService: Initializable<BaseAccountBalanceServiceParams, AccountBalanceServiceV2>
|
|
9
|
+
= async (params): Promise<AccountBalanceServiceV2> => {
|
|
10
|
+
if (balanceServiceSingleton) return balanceServiceSingleton
|
|
11
|
+
balanceServiceSingleton = await BaseAccountBalanceService.create(params)
|
|
12
|
+
return balanceServiceSingleton
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { Address } from '@xylabs/hex'
|
|
3
|
+
import { asAddress } from '@xylabs/hex'
|
|
4
|
+
import type { Promisable } from '@xylabs/promise'
|
|
5
|
+
import type { BaseAccountableServiceParams } from '@xyo-network/chain-services'
|
|
6
|
+
import { EvmChainService } from '@xyo-network/chain-services'
|
|
7
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
8
|
+
import type { ContractRunner } from 'ethers'
|
|
9
|
+
import { Wallet } from 'ethers/wallet'
|
|
10
|
+
|
|
11
|
+
import { canUseEvmProvider, initEvmProvider } from '../evm/index.ts'
|
|
12
|
+
|
|
13
|
+
let chainStakeServiceSingleton: Promisable<EvmChainService> | undefined
|
|
14
|
+
|
|
15
|
+
export const canUseEvmContractChainService = () => {
|
|
16
|
+
return process.env.XYO_EVM_STAKING_CONTRACT_ADDRESS !== undefined && canUseEvmProvider()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const initEvmContractChainService: Initializable<BaseAccountableServiceParams, EvmChainService> = async ({
|
|
20
|
+
account, traceProvider, meterProvider, logger,
|
|
21
|
+
}) => {
|
|
22
|
+
if (chainStakeServiceSingleton) return chainStakeServiceSingleton
|
|
23
|
+
// Parse ENV
|
|
24
|
+
const emvStakingContractAddress = assertEx(process.env.XYO_EVM_STAKING_CONTRACT_ADDRESS, () => 'Error: XYO_EVM_STAKING_CONTRACT_ADDRESS is required')
|
|
25
|
+
// Configure wallet
|
|
26
|
+
const id: Address = assertEx(asAddress(emvStakingContractAddress), () => 'Error: XYO_EVM_STAKING_CONTRACT_ADDRESS is invalid')
|
|
27
|
+
const provider = assertEx(await initEvmProvider())
|
|
28
|
+
const privateKey = assertEx(account.private?.hex, () => 'Error: Account does not have a private key')
|
|
29
|
+
const runner: ContractRunner = new Wallet(privateKey, provider)
|
|
30
|
+
// Create service
|
|
31
|
+
chainStakeServiceSingleton = EvmChainService.create({
|
|
32
|
+
id, runner, traceProvider, meterProvider, logger,
|
|
33
|
+
})
|
|
34
|
+
return await chainStakeServiceSingleton
|
|
35
|
+
}
|