@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.
Files changed (281) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +23 -0
  3. package/build/commands/api/index.d.ts +2 -0
  4. package/build/commands/api/index.d.ts.map +1 -0
  5. package/build/commands/api/runApi.d.ts +2 -0
  6. package/build/commands/api/runApi.d.ts.map +1 -0
  7. package/build/commands/index.d.ts +4 -0
  8. package/build/commands/index.d.ts.map +1 -0
  9. package/build/commands/producer/createDeclaration.d.ts +2 -0
  10. package/build/commands/producer/createDeclaration.d.ts.map +1 -0
  11. package/build/commands/producer/index.d.ts +3 -0
  12. package/build/commands/producer/index.d.ts.map +1 -0
  13. package/build/commands/producer/runProducer.d.ts +3 -0
  14. package/build/commands/producer/runProducer.d.ts.map +1 -0
  15. package/build/commands/validator/index.d.ts +2 -0
  16. package/build/commands/validator/index.d.ts.map +1 -0
  17. package/build/commands/validator/runValidator.d.ts +3 -0
  18. package/build/commands/validator/runValidator.d.ts.map +1 -0
  19. package/build/index.d.ts +4 -0
  20. package/build/index.d.ts.map +1 -0
  21. package/build/initEnv.d.ts +2 -0
  22. package/build/initEnv.d.ts.map +1 -0
  23. package/build/node/index.mjs +1502 -0
  24. package/build/node/index.mjs.map +1 -0
  25. package/build/node/xl1.mjs +1474 -0
  26. package/build/node/xl1.mjs.map +1 -0
  27. package/build/orchestration/actor/implementation/BalanceActor.d.ts +17 -0
  28. package/build/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -0
  29. package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +16 -0
  30. package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +1 -0
  31. package/build/orchestration/actor/implementation/ProducerActor.d.ts +25 -0
  32. package/build/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -0
  33. package/build/orchestration/actor/implementation/index.d.ts +4 -0
  34. package/build/orchestration/actor/implementation/index.d.ts.map +1 -0
  35. package/build/orchestration/actor/index.d.ts +3 -0
  36. package/build/orchestration/actor/index.d.ts.map +1 -0
  37. package/build/orchestration/actor/model/Actor.d.ts +38 -0
  38. package/build/orchestration/actor/model/Actor.d.ts.map +1 -0
  39. package/build/orchestration/actor/model/Orchestrator.d.ts +24 -0
  40. package/build/orchestration/actor/model/Orchestrator.d.ts.map +1 -0
  41. package/build/orchestration/actor/model/index.d.ts +3 -0
  42. package/build/orchestration/actor/model/index.d.ts.map +1 -0
  43. package/build/orchestration/archivists/ChainFinalized/archivist.d.ts +4 -0
  44. package/build/orchestration/archivists/ChainFinalized/archivist.d.ts.map +1 -0
  45. package/build/orchestration/archivists/ChainFinalized/index.d.ts +2 -0
  46. package/build/orchestration/archivists/ChainFinalized/index.d.ts.map +1 -0
  47. package/build/orchestration/archivists/ChainFinalized/local.d.ts +4 -0
  48. package/build/orchestration/archivists/ChainFinalized/local.d.ts.map +1 -0
  49. package/build/orchestration/archivists/ChainFinalized/remote.d.ts +4 -0
  50. package/build/orchestration/archivists/ChainFinalized/remote.d.ts.map +1 -0
  51. package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts +4 -0
  52. package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts.map +1 -0
  53. package/build/orchestration/archivists/ChainSubmissions/index.d.ts +2 -0
  54. package/build/orchestration/archivists/ChainSubmissions/index.d.ts.map +1 -0
  55. package/build/orchestration/archivists/ChainSubmissions/remote.d.ts +4 -0
  56. package/build/orchestration/archivists/ChainSubmissions/remote.d.ts.map +1 -0
  57. package/build/orchestration/archivists/PendingTransactions/archivist.d.ts +4 -0
  58. package/build/orchestration/archivists/PendingTransactions/archivist.d.ts.map +1 -0
  59. package/build/orchestration/archivists/PendingTransactions/index.d.ts +2 -0
  60. package/build/orchestration/archivists/PendingTransactions/index.d.ts.map +1 -0
  61. package/build/orchestration/archivists/PendingTransactions/local.d.ts +4 -0
  62. package/build/orchestration/archivists/PendingTransactions/local.d.ts.map +1 -0
  63. package/build/orchestration/archivists/PendingTransactions/remote.d.ts +4 -0
  64. package/build/orchestration/archivists/PendingTransactions/remote.d.ts.map +1 -0
  65. package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts +4 -0
  66. package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts.map +1 -0
  67. package/build/orchestration/archivists/RejectedTransactions/index.d.ts +2 -0
  68. package/build/orchestration/archivists/RejectedTransactions/index.d.ts.map +1 -0
  69. package/build/orchestration/archivists/RejectedTransactions/local.d.ts +4 -0
  70. package/build/orchestration/archivists/RejectedTransactions/local.d.ts.map +1 -0
  71. package/build/orchestration/archivists/StakeIntentState/archivist.d.ts +4 -0
  72. package/build/orchestration/archivists/StakeIntentState/archivist.d.ts.map +1 -0
  73. package/build/orchestration/archivists/StakeIntentState/index.d.ts +2 -0
  74. package/build/orchestration/archivists/StakeIntentState/index.d.ts.map +1 -0
  75. package/build/orchestration/archivists/StakeIntentState/local.d.ts +4 -0
  76. package/build/orchestration/archivists/StakeIntentState/local.d.ts.map +1 -0
  77. package/build/orchestration/archivists/index.d.ts +6 -0
  78. package/build/orchestration/archivists/index.d.ts.map +1 -0
  79. package/build/orchestration/archivists/lib/index.d.ts +2 -0
  80. package/build/orchestration/archivists/lib/index.d.ts.map +1 -0
  81. package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts +12 -0
  82. package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +1 -0
  83. package/build/orchestration/health/index.d.ts +2 -0
  84. package/build/orchestration/health/index.d.ts.map +1 -0
  85. package/build/orchestration/health/initHealthEndpoints.d.ts +7 -0
  86. package/build/orchestration/health/initHealthEndpoints.d.ts.map +1 -0
  87. package/build/orchestration/host/implementation/DefaultHost.d.ts +12 -0
  88. package/build/orchestration/host/implementation/DefaultHost.d.ts.map +1 -0
  89. package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts +24 -0
  90. package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts.map +1 -0
  91. package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts +7 -0
  92. package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts.map +1 -0
  93. package/build/orchestration/host/implementation/index.d.ts +3 -0
  94. package/build/orchestration/host/implementation/index.d.ts.map +1 -0
  95. package/build/orchestration/host/index.d.ts +3 -0
  96. package/build/orchestration/host/index.d.ts.map +1 -0
  97. package/build/orchestration/host/model/Host.d.ts +19 -0
  98. package/build/orchestration/host/model/Host.d.ts.map +1 -0
  99. package/build/orchestration/host/model/ServiceCollection.d.ts +20 -0
  100. package/build/orchestration/host/model/ServiceCollection.d.ts.map +1 -0
  101. package/build/orchestration/host/model/ServiceProvider.d.ts +4 -0
  102. package/build/orchestration/host/model/ServiceProvider.d.ts.map +1 -0
  103. package/build/orchestration/host/model/index.d.ts +4 -0
  104. package/build/orchestration/host/model/index.d.ts.map +1 -0
  105. package/build/orchestration/index.d.ts +6 -0
  106. package/build/orchestration/index.d.ts.map +1 -0
  107. package/build/orchestration/initServices.d.ts +4 -0
  108. package/build/orchestration/initServices.d.ts.map +1 -0
  109. package/build/orchestration/map/BalanceSummary/index.d.ts +2 -0
  110. package/build/orchestration/map/BalanceSummary/index.d.ts.map +1 -0
  111. package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts +7 -0
  112. package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts.map +1 -0
  113. package/build/orchestration/map/BalanceSummary/local.d.ts +6 -0
  114. package/build/orchestration/map/BalanceSummary/local.d.ts.map +1 -0
  115. package/build/orchestration/map/driver/index.d.ts +2 -0
  116. package/build/orchestration/map/driver/index.d.ts.map +1 -0
  117. package/build/orchestration/map/driver/lmdb/Params.d.ts +7 -0
  118. package/build/orchestration/map/driver/lmdb/Params.d.ts.map +1 -0
  119. package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts +32 -0
  120. package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts.map +1 -0
  121. package/build/orchestration/map/driver/lmdb/index.d.ts +2 -0
  122. package/build/orchestration/map/driver/lmdb/index.d.ts.map +1 -0
  123. package/build/orchestration/map/index.d.ts +3 -0
  124. package/build/orchestration/map/index.d.ts.map +1 -0
  125. package/build/orchestration/map/localPersistentMap.d.ts +12 -0
  126. package/build/orchestration/map/localPersistentMap.d.ts.map +1 -0
  127. package/build/orchestration/repository/index.d.ts +2 -0
  128. package/build/orchestration/repository/index.d.ts.map +1 -0
  129. package/build/orchestration/repository/lib/index.d.ts +2 -0
  130. package/build/orchestration/repository/lib/index.d.ts.map +1 -0
  131. package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts +6 -0
  132. package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts.map +1 -0
  133. package/build/orchestration/services/implementation/account.d.ts +4 -0
  134. package/build/orchestration/services/implementation/account.d.ts.map +1 -0
  135. package/build/orchestration/services/implementation/balance.d.ts +4 -0
  136. package/build/orchestration/services/implementation/balance.d.ts.map +1 -0
  137. package/build/orchestration/services/implementation/chain/evm.d.ts +6 -0
  138. package/build/orchestration/services/implementation/chain/evm.d.ts.map +1 -0
  139. package/build/orchestration/services/implementation/chain/index.d.ts +4 -0
  140. package/build/orchestration/services/implementation/chain/index.d.ts.map +1 -0
  141. package/build/orchestration/services/implementation/evm/index.d.ts +2 -0
  142. package/build/orchestration/services/implementation/evm/index.d.ts.map +1 -0
  143. package/build/orchestration/services/implementation/evm/initChainId.d.ts +3 -0
  144. package/build/orchestration/services/implementation/evm/initChainId.d.ts.map +1 -0
  145. package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts +4 -0
  146. package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +1 -0
  147. package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts +5 -0
  148. package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts.map +1 -0
  149. package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts +5 -0
  150. package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +1 -0
  151. package/build/orchestration/services/implementation/head.d.ts +10 -0
  152. package/build/orchestration/services/implementation/head.d.ts.map +1 -0
  153. package/build/orchestration/services/implementation/index.d.ts +11 -0
  154. package/build/orchestration/services/implementation/index.d.ts.map +1 -0
  155. package/build/orchestration/services/implementation/iterator.d.ts +6 -0
  156. package/build/orchestration/services/implementation/iterator.d.ts.map +1 -0
  157. package/build/orchestration/services/implementation/pendingTransactions.d.ts +4 -0
  158. package/build/orchestration/services/implementation/pendingTransactions.d.ts.map +1 -0
  159. package/build/orchestration/services/implementation/producer.d.ts +4 -0
  160. package/build/orchestration/services/implementation/producer.d.ts.map +1 -0
  161. package/build/orchestration/services/implementation/reward.d.ts +4 -0
  162. package/build/orchestration/services/implementation/reward.d.ts.map +1 -0
  163. package/build/orchestration/services/implementation/validator.d.ts +4 -0
  164. package/build/orchestration/services/implementation/validator.d.ts.map +1 -0
  165. package/build/orchestration/services/index.d.ts +2 -0
  166. package/build/orchestration/services/index.d.ts.map +1 -0
  167. package/build/orchestration/status/RuntimeStatusMonitor.d.ts +31 -0
  168. package/build/orchestration/status/RuntimeStatusMonitor.d.ts.map +1 -0
  169. package/build/orchestration/status/ServiceStatus.d.ts +9 -0
  170. package/build/orchestration/status/ServiceStatus.d.ts.map +1 -0
  171. package/build/orchestration/status/index.d.ts +3 -0
  172. package/build/orchestration/status/index.d.ts.map +1 -0
  173. package/build/orchestration/store/StoreKind.d.ts +2 -0
  174. package/build/orchestration/store/StoreKind.d.ts.map +1 -0
  175. package/build/orchestration/store/getStoreDirectory.d.ts +9 -0
  176. package/build/orchestration/store/getStoreDirectory.d.ts.map +1 -0
  177. package/build/orchestration/store/index.d.ts +3 -0
  178. package/build/orchestration/store/index.d.ts.map +1 -0
  179. package/build/runCLI.d.ts +3 -0
  180. package/build/runCLI.d.ts.map +1 -0
  181. package/build/start.d.ts +2 -0
  182. package/build/start.d.ts.map +1 -0
  183. package/build/xl1.d.ts +2 -0
  184. package/build/xl1.d.ts.map +1 -0
  185. package/dist/cli-min.mjs +400 -0
  186. package/nodemon.json +9 -0
  187. package/package.json +97 -0
  188. package/rollup.config.mjs +73 -0
  189. package/scripts/xl1.mjs +3 -0
  190. package/src/commands/api/index.ts +1 -0
  191. package/src/commands/api/runApi.ts +7 -0
  192. package/src/commands/index.ts +3 -0
  193. package/src/commands/producer/createDeclaration.ts +17 -0
  194. package/src/commands/producer/index.ts +2 -0
  195. package/src/commands/producer/runProducer.ts +25 -0
  196. package/src/commands/validator/index.ts +1 -0
  197. package/src/commands/validator/runValidator.ts +13 -0
  198. package/src/index.ts +3 -0
  199. package/src/initEnv.ts +8 -0
  200. package/src/orchestration/actor/implementation/BalanceActor.ts +51 -0
  201. package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +65 -0
  202. package/src/orchestration/actor/implementation/ProducerActor.ts +250 -0
  203. package/src/orchestration/actor/implementation/index.ts +3 -0
  204. package/src/orchestration/actor/index.ts +2 -0
  205. package/src/orchestration/actor/model/Actor.ts +113 -0
  206. package/src/orchestration/actor/model/Orchestrator.ts +65 -0
  207. package/src/orchestration/actor/model/index.ts +2 -0
  208. package/src/orchestration/archivists/ChainFinalized/archivist.ts +27 -0
  209. package/src/orchestration/archivists/ChainFinalized/index.ts +1 -0
  210. package/src/orchestration/archivists/ChainFinalized/local.ts +16 -0
  211. package/src/orchestration/archivists/ChainFinalized/remote.ts +18 -0
  212. package/src/orchestration/archivists/ChainSubmissions/archivist.ts +19 -0
  213. package/src/orchestration/archivists/ChainSubmissions/index.ts +1 -0
  214. package/src/orchestration/archivists/ChainSubmissions/remote.ts +18 -0
  215. package/src/orchestration/archivists/PendingTransactions/archivist.ts +29 -0
  216. package/src/orchestration/archivists/PendingTransactions/index.ts +1 -0
  217. package/src/orchestration/archivists/PendingTransactions/local.ts +20 -0
  218. package/src/orchestration/archivists/PendingTransactions/remote.ts +18 -0
  219. package/src/orchestration/archivists/RejectedTransactions/archivist.ts +18 -0
  220. package/src/orchestration/archivists/RejectedTransactions/index.ts +1 -0
  221. package/src/orchestration/archivists/RejectedTransactions/local.ts +20 -0
  222. package/src/orchestration/archivists/StakeIntentState/archivist.ts +19 -0
  223. package/src/orchestration/archivists/StakeIntentState/index.ts +1 -0
  224. package/src/orchestration/archivists/StakeIntentState/local.ts +19 -0
  225. package/src/orchestration/archivists/index.ts +5 -0
  226. package/src/orchestration/archivists/lib/index.ts +1 -0
  227. package/src/orchestration/archivists/lib/localPersistentArchivist.ts +44 -0
  228. package/src/orchestration/health/index.ts +1 -0
  229. package/src/orchestration/health/initHealthEndpoints.ts +70 -0
  230. package/src/orchestration/host/implementation/DefaultHost.ts +25 -0
  231. package/src/orchestration/host/implementation/DefaultServiceCollection.ts +60 -0
  232. package/src/orchestration/host/implementation/DefaultServiceProvider.ts +12 -0
  233. package/src/orchestration/host/implementation/index.ts +2 -0
  234. package/src/orchestration/host/index.ts +2 -0
  235. package/src/orchestration/host/model/Host.ts +21 -0
  236. package/src/orchestration/host/model/ServiceCollection.ts +22 -0
  237. package/src/orchestration/host/model/ServiceProvider.ts +3 -0
  238. package/src/orchestration/host/model/index.ts +3 -0
  239. package/src/orchestration/index.ts +5 -0
  240. package/src/orchestration/initServices.ts +237 -0
  241. package/src/orchestration/map/BalanceSummary/index.ts +1 -0
  242. package/src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts +22 -0
  243. package/src/orchestration/map/BalanceSummary/local.ts +19 -0
  244. package/src/orchestration/map/driver/index.ts +1 -0
  245. package/src/orchestration/map/driver/lmdb/Params.ts +7 -0
  246. package/src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts +67 -0
  247. package/src/orchestration/map/driver/lmdb/index.ts +1 -0
  248. package/src/orchestration/map/index.ts +2 -0
  249. package/src/orchestration/map/localPersistentMap.ts +39 -0
  250. package/src/orchestration/repository/index.ts +1 -0
  251. package/src/orchestration/repository/lib/index.ts +1 -0
  252. package/src/orchestration/repository/lib/repositoryFromArchivist.ts +27 -0
  253. package/src/orchestration/services/implementation/account.ts +23 -0
  254. package/src/orchestration/services/implementation/balance.ts +13 -0
  255. package/src/orchestration/services/implementation/chain/evm.ts +35 -0
  256. package/src/orchestration/services/implementation/chain/index.ts +27 -0
  257. package/src/orchestration/services/implementation/evm/index.ts +1 -0
  258. package/src/orchestration/services/implementation/evm/initChainId.ts +18 -0
  259. package/src/orchestration/services/implementation/evm/initEvmProvider.ts +21 -0
  260. package/src/orchestration/services/implementation/evm/initGanacheProvider.ts +19 -0
  261. package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +25 -0
  262. package/src/orchestration/services/implementation/head.ts +44 -0
  263. package/src/orchestration/services/implementation/index.ts +10 -0
  264. package/src/orchestration/services/implementation/iterator.ts +36 -0
  265. package/src/orchestration/services/implementation/pendingTransactions.ts +14 -0
  266. package/src/orchestration/services/implementation/producer.ts +13 -0
  267. package/src/orchestration/services/implementation/reward.ts +37 -0
  268. package/src/orchestration/services/implementation/validator.ts +14 -0
  269. package/src/orchestration/services/index.ts +1 -0
  270. package/src/orchestration/status/RuntimeStatusMonitor.ts +117 -0
  271. package/src/orchestration/status/ServiceStatus.ts +21 -0
  272. package/src/orchestration/status/index.ts +2 -0
  273. package/src/orchestration/store/StoreKind.ts +1 -0
  274. package/src/orchestration/store/getStoreDirectory.ts +15 -0
  275. package/src/orchestration/store/index.ts +2 -0
  276. package/src/runCLI.ts +96 -0
  277. package/src/spec/MultiProducer.ChainOutput.json +864 -0
  278. package/src/start.ts +26 -0
  279. package/src/xl1.ts +6 -0
  280. package/vitest.config.ts +11 -0
  281. 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,2 @@
1
+ export * from './DefaultHost.ts'
2
+ export * from './DefaultServiceProvider.ts'
@@ -0,0 +1,2 @@
1
+ export * from './implementation/index.ts'
2
+ export * from './model/index.ts'
@@ -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,3 @@
1
+ export interface ServiceProvider {
2
+ getService<T = unknown>(serviceIdentifier: string): T | undefined
3
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Host.ts'
2
+ export * from './ServiceCollection.ts'
3
+ export * from './ServiceProvider.ts'
@@ -0,0 +1,5 @@
1
+ export * from './actor/index.ts'
2
+ export * from './health/index.ts'
3
+ export * from './initServices.ts'
4
+ export * from './services/index.ts'
5
+ export * from './status/index.ts'
@@ -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,7 @@
1
+ import type { BaseServiceParams } from '@xyo-network/chain-services'
2
+
3
+ export interface LmdbMapParams extends BaseServiceParams {
4
+ dbName: string
5
+ location: string
6
+ storeName: string
7
+ }
@@ -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,2 @@
1
+ export * from './BalanceSummary/index.ts'
2
+ export * from './driver/index.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
+ }