@xyo-network/xl1-protocol-sdk 1.18.0-rc.1 → 1.18.1

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 (258) hide show
  1. package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts +57 -25
  2. package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
  3. package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +16 -11
  4. package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -1
  5. package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts +2 -4
  6. package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -1
  7. package/dist/neutral/CreatableProvider/ProviderFactory.d.ts +6 -4
  8. package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -1
  9. package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts +7 -7
  10. package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -1
  11. package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts +3 -2
  12. package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts.map +1 -1
  13. package/dist/neutral/actor/Actor.d.ts +176 -0
  14. package/dist/neutral/actor/Actor.d.ts.map +1 -0
  15. package/dist/neutral/actor/index.d.ts +2 -0
  16. package/dist/neutral/actor/index.d.ts.map +1 -0
  17. package/dist/neutral/block/hydrate/allHashesPresent.d.ts +2 -2
  18. package/dist/neutral/block/hydrate/allHashesPresent.d.ts.map +1 -1
  19. package/dist/neutral/block/hydrate/hydrateBlock.d.ts +2 -2
  20. package/dist/neutral/block/hydrate/hydrateBlock.d.ts.map +1 -1
  21. package/dist/neutral/config/Api.d.ts +1 -1
  22. package/dist/neutral/config/Api.d.ts.map +1 -1
  23. package/dist/neutral/config/Bridge.d.ts +41 -21
  24. package/dist/neutral/config/Bridge.d.ts.map +1 -1
  25. package/dist/neutral/config/Chain.d.ts +7 -3
  26. package/dist/neutral/config/Chain.d.ts.map +1 -1
  27. package/dist/neutral/config/Config.d.ts +50 -22
  28. package/dist/neutral/config/Config.d.ts.map +1 -1
  29. package/dist/neutral/config/Evm.d.ts +1 -1
  30. package/dist/neutral/config/Evm.d.ts.map +1 -1
  31. package/dist/neutral/config/Log.d.ts +2 -2
  32. package/dist/neutral/config/Log.d.ts.map +1 -1
  33. package/dist/neutral/config/Mempool.d.ts +1 -1
  34. package/dist/neutral/config/Mempool.d.ts.map +1 -1
  35. package/dist/neutral/config/Producer.d.ts +6 -2
  36. package/dist/neutral/config/Producer.d.ts.map +1 -1
  37. package/dist/neutral/config/RewardRedemptionApi.d.ts +1 -1
  38. package/dist/neutral/config/RewardRedemptionApi.d.ts.map +1 -1
  39. package/dist/neutral/config/Services.d.ts +3 -3
  40. package/dist/neutral/config/Services.d.ts.map +1 -1
  41. package/dist/neutral/config/Telemetry.d.ts +11 -4
  42. package/dist/neutral/config/Telemetry.d.ts.map +1 -1
  43. package/dist/neutral/config/UsageMeta.d.ts +1 -1
  44. package/dist/neutral/config/UsageMeta.d.ts.map +1 -1
  45. package/dist/neutral/config/Validation.d.ts +11 -3
  46. package/dist/neutral/config/Validation.d.ts.map +1 -1
  47. package/dist/neutral/config/index.d.ts +1 -0
  48. package/dist/neutral/config/index.d.ts.map +1 -1
  49. package/dist/neutral/config/storage/Storage.d.ts +1 -1
  50. package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
  51. package/dist/neutral/config/storage/driver/Mongo.d.ts +1 -1
  52. package/dist/neutral/config/storage/driver/Mongo.d.ts.map +1 -1
  53. package/dist/neutral/eip-712/Payloads/EIP712Data.d.ts +4 -4
  54. package/dist/neutral/eip-712/Payloads/EIP712Data.d.ts.map +1 -1
  55. package/dist/neutral/eip-712/Payloads/EIP712Signature.d.ts +3 -3
  56. package/dist/neutral/eip-712/Payloads/EIP712Signature.d.ts.map +1 -1
  57. package/dist/neutral/eip-712/Types.d.ts +4 -4
  58. package/dist/neutral/eip-712/Types.d.ts.map +1 -1
  59. package/dist/neutral/index.d.ts +1 -0
  60. package/dist/neutral/index.d.ts.map +1 -1
  61. package/dist/neutral/index.mjs +3440 -3089
  62. package/dist/neutral/index.mjs.map +1 -1
  63. package/dist/neutral/model/ChainQualification.d.ts +42 -0
  64. package/dist/neutral/model/ChainQualification.d.ts.map +1 -0
  65. package/dist/neutral/model/index.d.ts +1 -1
  66. package/dist/neutral/model/index.d.ts.map +1 -1
  67. package/dist/neutral/payloads/netBalancesForPayloads.d.ts +5 -2
  68. package/dist/neutral/payloads/netBalancesForPayloads.d.ts.map +1 -1
  69. package/dist/neutral/payloads/netSchemasForPayloads.d.ts +5 -2
  70. package/dist/neutral/payloads/netSchemasForPayloads.d.ts.map +1 -1
  71. package/dist/neutral/primitives/chain/getWindowedChain.d.ts +11 -0
  72. package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -0
  73. package/dist/neutral/primitives/chain/index.d.ts +1 -0
  74. package/dist/neutral/primitives/chain/index.d.ts.map +1 -1
  75. package/dist/neutral/primitives/index.d.ts +1 -0
  76. package/dist/neutral/primitives/index.d.ts.map +1 -1
  77. package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts +1 -1
  78. package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts.map +1 -1
  79. package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts +2 -1
  80. package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts.map +1 -1
  81. package/dist/neutral/primitives/uncle/findBestUncle.d.ts +32 -0
  82. package/dist/neutral/primitives/uncle/findBestUncle.d.ts.map +1 -0
  83. package/dist/neutral/primitives/uncle/findUncles.d.ts +33 -0
  84. package/dist/neutral/primitives/uncle/findUncles.d.ts.map +1 -0
  85. package/dist/neutral/primitives/uncle/index.d.ts +4 -0
  86. package/dist/neutral/primitives/uncle/index.d.ts.map +1 -0
  87. package/dist/neutral/primitives/uncle/scoreUncle.d.ts +3 -0
  88. package/dist/neutral/primitives/uncle/scoreUncle.d.ts.map +1 -0
  89. package/dist/neutral/provider/signer/XyoSigner.d.ts +2 -0
  90. package/dist/neutral/provider/signer/XyoSigner.d.ts.map +1 -1
  91. package/dist/neutral/provider/viewer/XyoViewer.d.ts +7 -5
  92. package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
  93. package/dist/neutral/runners/Finalization.d.ts +12 -0
  94. package/dist/neutral/runners/Finalization.d.ts.map +1 -0
  95. package/dist/neutral/runners/index.d.ts +1 -0
  96. package/dist/neutral/runners/index.d.ts.map +1 -1
  97. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +96 -12
  98. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
  99. package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +9 -25
  100. package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
  101. package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts +1 -0
  102. package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts.map +1 -1
  103. package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts +32 -0
  104. package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -0
  105. package/dist/neutral/simple/blockValidation/index.d.ts +2 -0
  106. package/dist/neutral/simple/blockValidation/index.d.ts.map +1 -0
  107. package/dist/neutral/simple/chainStake/SimpleStakeViewer.d.ts +1 -0
  108. package/dist/neutral/simple/chainStake/SimpleStakeViewer.d.ts.map +1 -1
  109. package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts +1 -1
  110. package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts.map +1 -1
  111. package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -0
  112. package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts.map +1 -1
  113. package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts +1 -0
  114. package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
  115. package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts +21 -0
  116. package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts.map +1 -0
  117. package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +61 -0
  118. package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts.map +1 -0
  119. package/dist/neutral/simple/finalization/index.d.ts +3 -0
  120. package/dist/neutral/simple/finalization/index.d.ts.map +1 -0
  121. package/dist/neutral/simple/index.d.ts +3 -0
  122. package/dist/neutral/simple/index.d.ts.map +1 -1
  123. package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts +2 -0
  124. package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
  125. package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts +7 -2
  126. package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
  127. package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts +1 -0
  128. package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts.map +1 -1
  129. package/dist/neutral/simple/signer/SimpleXyoSigner.d.ts +19 -3
  130. package/dist/neutral/simple/signer/SimpleXyoSigner.d.ts.map +1 -1
  131. package/dist/neutral/simple/stakeEvents/SimpleStakeEventsViewer.d.ts +1 -0
  132. package/dist/neutral/simple/stakeEvents/SimpleStakeEventsViewer.d.ts.map +1 -1
  133. package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts +2 -1
  134. package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
  135. package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +191 -0
  136. package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts.map +1 -0
  137. package/dist/neutral/simple/windowedBlock/index.d.ts +2 -0
  138. package/dist/neutral/simple/windowedBlock/index.d.ts.map +1 -0
  139. package/dist/neutral/summary/model/summary.d.ts +3 -2
  140. package/dist/neutral/summary/model/summary.d.ts.map +1 -1
  141. package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts +2 -2
  142. package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
  143. package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts +2 -2
  144. package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
  145. package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +3 -3
  146. package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
  147. package/dist/neutral/transaction/TransactionBuilder.d.ts +56 -33
  148. package/dist/neutral/transaction/TransactionBuilder.d.ts.map +1 -1
  149. package/dist/neutral/transaction/signTransaction.d.ts +24 -12
  150. package/dist/neutral/transaction/signTransaction.d.ts.map +1 -1
  151. package/dist/neutral/utils/isZodError.d.ts +1 -1
  152. package/dist/neutral/utils/isZodError.d.ts.map +1 -1
  153. package/dist/neutral/validation/schema/Mnemonic.d.ts +1 -1
  154. package/dist/neutral/validation/schema/Mnemonic.d.ts.map +1 -1
  155. package/dist/neutral/viewers/AccountBalance.d.ts +92 -44
  156. package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
  157. package/dist/neutral/viewers/Block.d.ts +2 -2
  158. package/dist/neutral/viewers/Block.d.ts.map +1 -1
  159. package/dist/neutral/viewers/BlockValidation.d.ts +54 -0
  160. package/dist/neutral/viewers/BlockValidation.d.ts.map +1 -0
  161. package/dist/neutral/viewers/Finalization.d.ts +14 -0
  162. package/dist/neutral/viewers/Finalization.d.ts.map +1 -0
  163. package/dist/neutral/viewers/Mempool.d.ts +5 -5
  164. package/dist/neutral/viewers/Mempool.d.ts.map +1 -1
  165. package/dist/neutral/viewers/StakeIntent.d.ts +2 -2
  166. package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -1
  167. package/dist/neutral/viewers/TransactionValidation.d.ts +35 -0
  168. package/dist/neutral/viewers/TransactionValidation.d.ts.map +1 -0
  169. package/dist/neutral/viewers/WindowedBlock.d.ts +14 -0
  170. package/dist/neutral/viewers/WindowedBlock.d.ts.map +1 -0
  171. package/dist/neutral/viewers/index.d.ts +4 -0
  172. package/dist/neutral/viewers/index.d.ts.map +1 -1
  173. package/package.json +25 -23
  174. package/src/CreatableProvider/AbstractCreatableProvider.ts +34 -12
  175. package/src/CreatableProvider/CreatableProvider.ts +24 -12
  176. package/src/CreatableProvider/CreatableProviderRegistry.ts +4 -3
  177. package/src/CreatableProvider/ProviderFactory.ts +21 -12
  178. package/src/CreatableProvider/ProviderFactoryLocator.ts +8 -6
  179. package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +6 -2
  180. package/src/actor/Actor.ts +209 -0
  181. package/src/actor/index.ts +1 -0
  182. package/src/block/hydrate/allHashesPresent.ts +2 -2
  183. package/src/block/hydrate/hydrateBlock.ts +2 -2
  184. package/src/config/Api.ts +1 -2
  185. package/src/config/Bridge.ts +1 -2
  186. package/src/config/Chain.ts +1 -2
  187. package/src/config/Config.ts +1 -1
  188. package/src/config/Evm.ts +1 -2
  189. package/src/config/Log.ts +1 -2
  190. package/src/config/Mempool.ts +1 -2
  191. package/src/config/Producer.ts +1 -2
  192. package/src/config/RewardRedemptionApi.ts +1 -2
  193. package/src/config/Services.ts +5 -4
  194. package/src/config/Telemetry.ts +10 -4
  195. package/src/config/UsageMeta.ts +1 -1
  196. package/src/config/Validation.ts +1 -2
  197. package/src/config/index.ts +1 -0
  198. package/src/config/storage/Storage.ts +1 -2
  199. package/src/config/storage/driver/Mongo.ts +1 -2
  200. package/src/eip-712/Payloads/EIP712Data.ts +1 -1
  201. package/src/eip-712/Payloads/EIP712Signature.ts +1 -1
  202. package/src/eip-712/Types.ts +1 -1
  203. package/src/index.ts +1 -0
  204. package/src/model/ChainQualification.ts +33 -0
  205. package/src/model/index.ts +1 -1
  206. package/src/primitives/chain/getWindowedChain.ts +42 -0
  207. package/src/primitives/chain/index.ts +1 -0
  208. package/src/primitives/index.ts +1 -0
  209. package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +4 -3
  210. package/src/primitives/stake/allStakersForStep.ts +1 -1
  211. package/src/primitives/stake/weightedStakeForRangeByPosition.ts +10 -2
  212. package/src/primitives/uncle/findBestUncle.ts +8 -0
  213. package/src/primitives/uncle/findUncles.ts +75 -0
  214. package/src/primitives/uncle/index.ts +3 -0
  215. package/src/primitives/uncle/scoreUncle.ts +6 -0
  216. package/src/provider/signer/XyoSigner.ts +3 -0
  217. package/src/provider/viewer/XyoViewer.ts +7 -7
  218. package/src/runners/Finalization.ts +15 -0
  219. package/src/runners/index.ts +1 -0
  220. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +47 -30
  221. package/src/simple/block/SimpleBlockViewer.ts +23 -37
  222. package/src/simple/blockReward/SimpleBlockRewardViewer.ts +1 -0
  223. package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +129 -0
  224. package/src/simple/blockValidation/index.ts +1 -0
  225. package/src/simple/chainStake/SimpleStakeViewer.ts +1 -0
  226. package/src/simple/datalake/AbstractSimpleDataLake.ts +2 -1
  227. package/src/simple/datalake/SimpleDataLakeRunner.ts +1 -0
  228. package/src/simple/datalake/SimpleDataLakeViewer.ts +1 -1
  229. package/src/simple/finalization/SimpleFinalizationRunner.ts +45 -0
  230. package/src/simple/finalization/SimpleFinalizationViewer.ts +101 -0
  231. package/src/simple/finalization/index.ts +2 -0
  232. package/src/simple/index.ts +3 -0
  233. package/src/simple/mempool/SimpleMempoolRunner.ts +11 -1
  234. package/src/simple/mempool/SimpleMempoolViewer.ts +41 -8
  235. package/src/simple/runner/SimpleXyoRunner.ts +3 -1
  236. package/src/simple/signer/SimpleXyoSigner.ts +26 -5
  237. package/src/simple/stakeEvents/SimpleStakeEventsViewer.ts +1 -0
  238. package/src/simple/timesync/SimpleTimeSyncViewer.ts +4 -2
  239. package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +208 -0
  240. package/src/simple/windowedBlock/index.ts +1 -0
  241. package/src/summary/model/summary.ts +3 -4
  242. package/src/summary/primitives/balances/balancesSummary.ts +12 -12
  243. package/src/summary/primitives/schemas/schemasSummary.ts +12 -10
  244. package/src/summary/primitives/transfers/transfersSummary.ts +15 -17
  245. package/src/utils/isZodError.ts +1 -1
  246. package/src/validation/schema/Mnemonic.ts +1 -1
  247. package/src/viewers/AccountBalance.ts +23 -15
  248. package/src/viewers/Block.ts +2 -2
  249. package/src/viewers/BlockValidation.ts +47 -0
  250. package/src/viewers/Finalization.ts +19 -0
  251. package/src/viewers/Mempool.ts +1 -1
  252. package/src/viewers/StakeIntent.ts +2 -2
  253. package/src/viewers/TransactionValidation.ts +35 -0
  254. package/src/viewers/WindowedBlock.ts +17 -0
  255. package/src/viewers/index.ts +4 -0
  256. package/dist/neutral/model/Qualified.d.ts +0 -6
  257. package/dist/neutral/model/Qualified.d.ts.map +0 -1
  258. package/src/model/Qualified.ts +0 -9
@@ -0,0 +1,75 @@
1
+ import {
2
+ assertEx,
3
+ exists, type Hash,
4
+ } from '@xylabs/sdk-js'
5
+ import { isTransactionBoundWitness, type SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
6
+
7
+ import type { BaseContext } from '../../model/index.ts'
8
+
9
+ function blocksToChains(blocks: SignedHydratedBlockWithHashMeta[]) {
10
+ const chains: SignedHydratedBlockWithHashMeta[][] = []
11
+ const map = new Map<Hash, SignedHydratedBlockWithHashMeta>()
12
+ for (const block of blocks) {
13
+ map.set(block[0]._hash, block)
14
+ }
15
+ for (const block of blocks) {
16
+ let uncle: SignedHydratedBlockWithHashMeta[] = [block]
17
+ let previous = block[0].previous ? map.get(block[0].previous) : undefined
18
+ while (previous) {
19
+ if (previous[0].block === (uncle[0][0].block - 1)) {
20
+ uncle.unshift(previous)
21
+ previous = previous[0].previous ? map.get(previous[0].previous) : undefined
22
+ } else {
23
+ // block number sequence is off
24
+ uncle = []
25
+ break
26
+ }
27
+ }
28
+ if (uncle.length > 0) {
29
+ chains.push(uncle)
30
+ }
31
+ }
32
+ return chains
33
+ }
34
+
35
+ function toValidUncle(
36
+ _context: BaseContext,
37
+ finalizedWindowedChain: SignedHydratedBlockWithHashMeta[],
38
+ possibleUncle: SignedHydratedBlockWithHashMeta[],
39
+ ) {
40
+ const finalizedWindowStartBlockNumber = finalizedWindowedChain.at(0)?.[0].block ?? -1
41
+ const finalizedHead = assertEx(finalizedWindowedChain.at(-1), () => 'finalizedWindowedChain is empty')
42
+ // prune the chain to match the finalized head
43
+
44
+ const prunedPossibleUncle = possibleUncle.filter(b => b[0].block > finalizedHead[0].block)
45
+
46
+ if (prunedPossibleUncle.length === 0) {
47
+ return
48
+ }
49
+
50
+ if (prunedPossibleUncle[0][0].block !== finalizedHead[0].block + 1) {
51
+ // uncle does not build on finalized head (block number mismatch)
52
+ return
53
+ }
54
+ if (prunedPossibleUncle[0][0].previous !== finalizedHead[0]._hash) {
55
+ // uncle does not build on finalized head (previous hash mismatch)
56
+ return
57
+ }
58
+ const allUncleTransactions = prunedPossibleUncle.flatMap(b => b[1]).filter(isTransactionBoundWitness)
59
+ const allFinalizedTransactions = finalizedWindowedChain.flatMap(b => b[1]).filter(isTransactionBoundWitness)
60
+ const txPossiblyBeforeWindow = allUncleTransactions.find(tx => tx.nbf < finalizedWindowStartBlockNumber)
61
+ if (txPossiblyBeforeWindow) {
62
+ // uncle has a transaction that is valid before the finalized window
63
+ return
64
+ }
65
+ const txExistsInWindow = allUncleTransactions.find(tx => allFinalizedTransactions.find(finalTx => finalTx._hash === tx._hash))
66
+ if (txExistsInWindow) {
67
+ // uncle has a transaction that is already in the finalized window
68
+ return
69
+ }
70
+ return prunedPossibleUncle
71
+ }
72
+
73
+ export function findUncles(context: BaseContext, finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
74
+ return blocksToChains(blocks).map(chain => toValidUncle(context, finalizedWindowedChain, chain)).filter(exists)
75
+ }
@@ -0,0 +1,3 @@
1
+ export * from './findBestUncle.ts'
2
+ export * from './findUncles.ts'
3
+ export * from './scoreUncle.ts'
@@ -0,0 +1,6 @@
1
+ import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
2
+
3
+ export function scoreUncle(finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
4
+ // TODO: More than length check
5
+ return blocks.length
6
+ }
@@ -7,6 +7,9 @@ import type {
7
7
  TransactionFeesBigInt,
8
8
  } from '@xyo-network/xl1-protocol'
9
9
 
10
+ export const XyoSignerMoniker = 'XyoSigner' as const
11
+ export type XyoSignerMoniker = typeof XyoSignerMoniker
12
+
10
13
  export interface XyoSigner {
11
14
  address(): Promisable<Address>
12
15
  // The tx passed in must have all the payloads (on and off chain) in the payloads array
@@ -1,9 +1,7 @@
1
- import type {
2
- Address, Hash, Promisable,
3
- } from '@xylabs/sdk-js'
4
- import type { AttoXL1, XL1BlockRange } from '@xyo-network/xl1-protocol'
1
+ import type { Address, Promisable } from '@xylabs/sdk-js'
2
+ import type { AttoXL1 } from '@xyo-network/xl1-protocol'
5
3
 
6
- import type { Provider } from '../../model/index.ts'
4
+ import type { ChainQualifiedConfig, Provider } from '../../model/index.ts'
7
5
  import type {
8
6
  AccountBalanceHistoryItem,
9
7
  AccountBalanceViewer,
@@ -22,8 +20,10 @@ import type { NetworkStakeViewer } from './NetworkStake/index.ts'
22
20
  export interface XyoViewerMethods extends
23
21
  NetworkStakeStepRewardViewerMethods, BlockViewerMethods,
24
22
  TransactionViewerMethods, StakeViewerMethods, ForkViewerMethods {
25
- accountBalance(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<AttoXL1>
26
- accountBalanceHistory(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<AccountBalanceHistoryItem[]>
23
+ /** @deprecated Use .account.balance.accountBalance instead */
24
+ accountBalance(address: Address, config?: ChainQualifiedConfig): Promisable<AttoXL1>
25
+ /** @deprecated Use .account.balance.accountBalanceHistory instead */
26
+ accountBalanceHistory(address: Address, config?: ChainQualifiedConfig): Promisable<AccountBalanceHistoryItem[]>
27
27
  }
28
28
 
29
29
  export const XyoViewerMoniker = 'XyoViewer' as const
@@ -0,0 +1,15 @@
1
+ import type { Hash } from '@xylabs/sdk-js'
2
+ import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
3
+
4
+ import type { Provider } from '../model/index.ts'
5
+
6
+ export interface FinalizationRunnerMethods {
7
+ finalizeBlocks(blocks: SignedHydratedBlockWithHashMeta[]): Promise<Hash[]>
8
+ }
9
+
10
+ export const FinalizationRunnerMoniker = 'FinalizationRunner' as const
11
+ export type FinalizationRunnerMoniker = typeof FinalizationRunnerMoniker
12
+
13
+ export interface FinalizationRunner extends FinalizationRunnerMethods, Provider<FinalizationRunnerMoniker> {
14
+ finalizeBlock(block: SignedHydratedBlockWithHashMeta): Promise<Hash>
15
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './Block.ts'
2
+ export * from './Finalization.ts'
2
3
  export * from './Mempool.ts'
@@ -2,6 +2,7 @@ import type { Address, Hash } from '@xylabs/sdk-js'
2
2
  import {
3
3
  asHash,
4
4
  assertEx, exists, isDefined, spanRootAsync,
5
+ ZERO_ADDRESS,
5
6
  } from '@xylabs/sdk-js'
6
7
  import type { WithHashMeta, WithStorageMeta } from '@xyo-network/payload-model'
7
8
  import type {
@@ -16,7 +17,9 @@ import {
16
17
  import { deepCalculateFramesFromRange } from '../../block/index.ts'
17
18
  import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
18
19
  import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
19
- import type { Qualified } from '../../model/index.ts'
20
+ import {
21
+ ChainQualification, type ChainQualified, isChainQualifiedHeadConfig, isChainQualifiedRangeConfig,
22
+ } from '../../model/index.ts'
20
23
  import type {
21
24
  BalanceStepSummaryContext,
22
25
  TransfersStepSummary,
@@ -27,6 +30,7 @@ import {
27
30
  transfersStepSummaryFromRange,
28
31
  } from '../../summary/index.ts'
29
32
  import {
33
+ AccountBalanceConfig,
30
34
  type AccountBalanceHistoryItem, type AccountBalanceViewer, AccountBalanceViewerMoniker,
31
35
  type BlockViewer,
32
36
  BlockViewerMoniker,
@@ -40,6 +44,7 @@ export interface SimpleAccountBalanceViewerParams extends CreatableProviderParam
40
44
  @creatableProvider()
41
45
  export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<SimpleAccountBalanceViewerParams> implements AccountBalanceViewer {
42
46
  static readonly defaultMoniker = AccountBalanceViewerMoniker
47
+ static readonly dependencies = [BlockViewerMoniker]
43
48
  static readonly monikers = [AccountBalanceViewerMoniker]
44
49
  moniker = SimpleAccountBalanceViewer.defaultMoniker
45
50
 
@@ -64,17 +69,17 @@ export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<Simple
64
69
  return await super.paramsHandler({ ...params })
65
70
  }
66
71
 
67
- async accountBalance(address: Address, headOrRange?: XL1BlockRange | Hash): Promise<AttoXL1> {
68
- const balances = await this.accountBalances([address], headOrRange)
72
+ async accountBalance(address: Address, config?: AccountBalanceConfig) {
73
+ const balances = await this.accountBalances([address], config)
69
74
  return balances[address] ?? AttoXL1(0n)
70
75
  }
71
76
 
72
- accountBalanceHistories(_addresses: Address[], _rangeOrHash?: XL1BlockRange | Hash): Promise<Record<Address, AccountBalanceHistoryItem[]>> {
73
- throw new Error('Method [accountBalanceHistories] not implemented.')
77
+ async accountBalanceHistories(addresses: Address[], config: AccountBalanceConfig = {}) {
78
+ return (await this.qualifiedAccountBalanceHistories(addresses, config))[0]
74
79
  }
75
80
 
76
- async accountBalanceHistory(address: Address, headOrRange?: XL1BlockRange | Hash): Promise<AccountBalanceHistoryItem[]> {
77
- const range = asRange(headOrRange)
81
+ async accountBalanceHistory(address: Address, config?: AccountBalanceConfig) {
82
+ const range = isChainQualifiedRangeConfig(config) ? config.range : undefined
78
83
  const startingRange = asXL1BlockRange(range ?? [0, await this.blockViewer.currentBlockNumber()], true)
79
84
  const blockNumbers = await this.distillTransferHistory(address, startingRange)
80
85
  const blocks = (await Promise.all(blockNumbers.map(async bn => await this.blockViewer.blockByNumber(bn)))).filter(exists)
@@ -101,8 +106,8 @@ export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<Simple
101
106
  return result
102
107
  }
103
108
 
104
- async accountBalances(address: Address[], _headOrRange?: XL1BlockRange | Hash): Promise<Record<Address, AttoXL1>> {
105
- const [result] = (await this.qualifiedAccountBalances(address, _headOrRange))
109
+ async accountBalances(address: Address[], config?: AccountBalanceConfig) {
110
+ const [result] = (await this.qualifiedAccountBalances(address, config ?? {}))
106
111
  return result
107
112
  }
108
113
 
@@ -113,57 +118,69 @@ export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<Simple
113
118
 
114
119
  async qualifiedAccountBalanceHistories(
115
120
  addresses: Address[],
116
- headOrRange?: Hash | XL1BlockRange,
117
- ): Promise<Qualified<Record<Address, AccountBalanceHistoryItem[]>>> {
118
- const head = asHash(headOrRange) ?? await this.blockViewer.currentBlockHash()
119
- const range = asXL1BlockRange(headOrRange) ?? asXL1BlockRange([0,
120
- assertEx(
121
- await this.blockViewer.blockByHash(head),
122
- () => `Error: Could not find block with hash ${head}`,
123
- )[0].block])
124
- const qualifiedEntries: [Address, Qualified<AccountBalanceHistoryItem[]>][] = await Promise.all(addresses.map(async address => ([
121
+ config: AccountBalanceConfig,
122
+ ) {
123
+ const head = isChainQualifiedHeadConfig(config) ? config.head : await this.blockViewer.currentBlockHash()
124
+ const range = isChainQualifiedRangeConfig(config)
125
+ ? config.range
126
+ : asXL1BlockRange([0,
127
+ assertEx(
128
+ await this.blockViewer.blockByHash(head),
129
+ () => `Error: Could not find block with hash ${head}`,
130
+ )[0].block])
131
+ const qualifiedEntries = await Promise.all(addresses.map(async address => ([
125
132
  address,
126
133
  await this.qualifiedAccountBalanceHistory(address, range),
127
- ])))
134
+ ]))) satisfies [Address, ChainQualified<AccountBalanceHistoryItem[]>][]
128
135
 
129
136
  const entries = qualifiedEntries.map(([address, [history]]) => {
130
137
  return [address, history]
131
138
  })
132
- const qualifiedRange = qualifiedEntries[0][1][1]
133
- const qualifiedHeadHash = qualifiedEntries[0][1][2]
139
+ const qualifiedRange = qualifiedEntries[0][1][1].range
140
+ const qualifiedHeadHash = qualifiedEntries[0][1][1].head
134
141
 
135
142
  // check for drift
136
- for (const [_, [__, range, headHash]] of qualifiedEntries) {
143
+ for (const [_, [__, { range, head }]] of qualifiedEntries) {
137
144
  assertEx(
138
145
  range[0] === qualifiedRange[0] && range[1] === qualifiedRange[1],
139
146
  () => 'Inconsistent ranges in qualifiedAccountBalanceHistories',
140
147
  )
141
148
  assertEx(
142
- headHash === qualifiedHeadHash,
149
+ head === qualifiedHeadHash,
143
150
  () => 'Inconsistent head hashes in qualifiedAccountBalanceHistories',
144
151
  )
145
152
  }
146
153
 
147
- return [Object.fromEntries(entries), qualifiedRange, qualifiedHeadHash]
154
+ return [Object.fromEntries(entries), { range: qualifiedRange, head: qualifiedHeadHash }] satisfies
155
+ [Record<Address, AccountBalanceHistoryItem[]>, ChainQualification]
148
156
  }
149
157
 
150
158
  async qualifiedAccountBalances(
151
159
  address: Address[],
152
- _headOrRange?: Hash | XL1BlockRange,
153
- ): Promise<Qualified<Record<Address, AttoXL1>>> {
160
+ config: AccountBalanceConfig,
161
+ ): Promise<ChainQualified<Record<Address, AttoXL1>>> {
154
162
  return await spanRootAsync('qualifiedAccountsBalances', async () => {
155
163
  const qualifiedSummary = await balancesSummary(
156
- this.balanceSummaryContext,
164
+ { ...this.balanceSummaryContext },
165
+ config,
157
166
  )
158
167
  const result: Record<Address, AttoXL1> = {}
159
168
  for (const addr of address) {
160
169
  const summaryBalance = qualifiedSummary[0][addr] ?? 0n
161
170
  result[addr] = AttoXL1(summaryBalance < 0n ? 0n : summaryBalance)
162
171
  }
163
- return [result, qualifiedSummary[1], qualifiedSummary[2]]
172
+ return [result, qualifiedSummary[1]]
164
173
  })
165
174
  }
166
175
 
176
+ override async startHandler() {
177
+ await super.startHandler()
178
+ await Promise.all([
179
+ this.accountBalance(ZERO_ADDRESS),
180
+ this.accountBalanceHistory(ZERO_ADDRESS),
181
+ ])
182
+ }
183
+
167
184
  private async distillTransferHistory(address: Address, range: XL1BlockRange, max: number = 50): Promise<XL1BlockNumber[]> {
168
185
  if ((range[1] - range[0]) <= StepSizes[0] || max <= 1) {
169
186
  return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map(n => asXL1BlockNumber(n, true))
@@ -205,7 +222,7 @@ export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<Simple
205
222
  private async qualifiedAccountBalanceHistory(
206
223
  address: Address,
207
224
  headOrRange?: Hash | XL1BlockRange,
208
- ): Promise<Qualified<AccountBalanceHistoryItem[]>> {
225
+ ): Promise<ChainQualified<AccountBalanceHistoryItem[]>> {
209
226
  const range = asRange(headOrRange)
210
227
  const headHash = asHash(headOrRange)
211
228
  const [head] = assertEx(isDefined(headHash)
@@ -234,6 +251,6 @@ export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<Simple
234
251
  null,
235
252
  transfer] satisfies AccountBalanceHistoryItem))
236
253
  }
237
- return [result, startingRange, head._hash]
254
+ return [result, { range: startingRange, head: head._hash }]
238
255
  }
239
256
  }
@@ -7,12 +7,14 @@ import {
7
7
  spanRootAsync,
8
8
  } from '@xylabs/sdk-js'
9
9
  import type { ReadArchivist } from '@xyo-network/archivist-model'
10
- import type { Payload, WithHashMeta } from '@xyo-network/payload-model'
10
+ import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
11
11
  import {
12
12
  asSignedHydratedBlockWithHashMeta,
13
+ asSignedHydratedBlockWithStorageMeta,
13
14
  asXL1BlockNumber,
14
15
  ChainId,
15
16
  type SignedHydratedBlockWithHashMeta,
17
+ SignedHydratedBlockWithStorageMeta,
16
18
  type XL1BlockNumber,
17
19
  } from '@xyo-network/xl1-protocol'
18
20
 
@@ -24,11 +26,11 @@ import type {
24
26
  ChainContextRead,
25
27
  ChainStoreRead, PayloadMap,
26
28
  } from '../../model/index.ts'
27
- import {
28
- findMostRecentBlock, hydratedBlockByNumber, readPayloadMapFromStore,
29
- } from '../../primitives/index.ts'
29
+ import { hydratedBlockByNumber, readPayloadMapFromStore } from '../../primitives/index.ts'
30
30
  import { HydratedCache } from '../../utils/index.ts'
31
- import { type BlockViewer, BlockViewerMoniker } from '../../viewers/index.ts'
31
+ import {
32
+ type BlockViewer, BlockViewerMoniker, FinalizationViewer, FinalizationViewerMoniker,
33
+ } from '../../viewers/index.ts'
32
34
 
33
35
  export interface SimpleBlockViewerParams extends CreatableProviderParams {
34
36
  finalizedArchivist: ReadArchivist
@@ -37,36 +39,38 @@ export interface SimpleBlockViewerParams extends CreatableProviderParams {
37
39
  @creatableProvider()
38
40
  export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockViewerParams> implements BlockViewer {
39
41
  static readonly defaultMoniker = BlockViewerMoniker
42
+ static readonly dependencies = [FinalizationViewerMoniker]
40
43
  static readonly monikers = [BlockViewerMoniker]
41
44
  moniker = SimpleBlockViewer.defaultMoniker
42
45
 
43
46
  protected _store: ChainStoreRead | undefined
47
+ protected finalizationViewer!: FinalizationViewer
44
48
 
45
- private _payloadCache: PayloadMap<WithHashMeta<Payload>> | undefined
46
- private _signedHydratedBlockCache: HydratedCache<SignedHydratedBlockWithHashMeta> | undefined
49
+ private _payloadCache: PayloadMap<WithStorageMeta<Payload>> | undefined
50
+ private _signedHydratedBlockCache: HydratedCache<SignedHydratedBlockWithStorageMeta> | undefined
47
51
 
48
52
  get finalizedArchivist(): ReadArchivist {
49
53
  return this.params.finalizedArchivist!
50
54
  }
51
55
 
52
- protected get hydratedBlockCache(): HydratedCache<SignedHydratedBlockWithHashMeta> {
56
+ protected get hydratedBlockCache(): HydratedCache<SignedHydratedBlockWithStorageMeta> {
53
57
  if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache
54
58
  const chainMap = this.store.chainMap
55
- this._signedHydratedBlockCache = new HydratedCache<SignedHydratedBlockWithHashMeta>(chainMap, async (
59
+ this._signedHydratedBlockCache = new HydratedCache<SignedHydratedBlockWithStorageMeta>(chainMap, async (
56
60
  store: ChainStoreRead,
57
61
  hash: Hash,
58
62
  maxDepth?: number,
59
63
  minDepth?: number,
60
64
  ) => {
61
65
  const result = await hydrateBlock(store, hash, maxDepth, minDepth)
62
- return asSignedHydratedBlockWithHashMeta(result, true)
66
+ return asSignedHydratedBlockWithStorageMeta(result, true)
63
67
  }, 200)
64
68
  return this._signedHydratedBlockCache
65
69
  }
66
70
 
67
- protected get payloadCache(): PayloadMap<WithHashMeta<Payload>> {
71
+ protected get payloadCache(): PayloadMap<WithStorageMeta<Payload>> {
68
72
  if (this._payloadCache) return this._payloadCache
69
- this._payloadCache = new LruCacheMap<Hash, WithHashMeta<Payload>>({ max: 10_000 })
73
+ this._payloadCache = new LruCacheMap<Hash, WithStorageMeta<Payload>>({ max: 10_000 })
70
74
  return this._payloadCache
71
75
  }
72
76
 
@@ -89,7 +93,7 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
89
93
 
90
94
  async blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {
91
95
  return await spanRootAsync('blockByNumber', async () => {
92
- const head = await this.getCurrentHead()
96
+ const [head] = await this.currentBlock()
93
97
  if (isUndefined(head)) {
94
98
  return null
95
99
  }
@@ -151,36 +155,23 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
151
155
 
152
156
  override async createHandler() {
153
157
  await super.createHandler()
158
+ this.finalizationViewer = await this.locator.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
154
159
  this._store = { chainMap: readPayloadMapFromStore(this.params.finalizedArchivist) }
155
160
  }
156
161
 
157
162
  async currentBlock(): Promise<SignedHydratedBlockWithHashMeta> {
158
- return await spanRootAsync('currentBlock', async () => {
159
- const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlock]')
160
- const cache = this.hydratedBlockCache
161
- const block = await cache.get(currentHead._hash)
162
- if (!block) {
163
- console.log(`Could not find current block with hash ${currentHead!._hash}`)
164
- }
165
- return assertEx(block, () => 'Could not find current block')
166
- }, this.tracer)
163
+ return await this.finalizationViewer.head()
167
164
  }
168
165
 
169
166
  async currentBlockHash(): Promise<Hash> {
170
- return await spanRootAsync('currentBlockHash', async () => {
171
- const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlockHash]')
172
- return currentHead._hash
173
- }, this.tracer)
167
+ return await this.finalizationViewer.headHash()
174
168
  }
175
169
 
176
170
  async currentBlockNumber(): Promise<XL1BlockNumber> {
177
- return await spanRootAsync('currentBlockNumber', async () => {
178
- const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlockNumber]')
179
- return asXL1BlockNumber(currentHead.block, { name: 'currentBlockNumber' })
180
- }, this.tracer)
171
+ return await this.finalizationViewer.headNumber()
181
172
  }
182
173
 
183
- async payloadByHash(hash: Hash): Promise<WithHashMeta<Payload> | null> {
174
+ async payloadByHash(hash: Hash): Promise<WithStorageMeta<Payload> | null> {
184
175
  const cachedPayload = await this.payloadCache.get(hash)
185
176
  if (cachedPayload) {
186
177
  return cachedPayload
@@ -193,7 +184,7 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
193
184
  }
194
185
  }
195
186
 
196
- async payloadsByHash(hashes: Hash[]): Promise<WithHashMeta<Payload>[]> {
187
+ async payloadsByHash(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {
197
188
  let remainingHashes = [...hashes]
198
189
  const cachedPayloads = await this.payloadCache.getMany(remainingHashes)
199
190
  const cachedHashes = new Set(cachedPayloads.map(p => p._hash))
@@ -203,9 +194,4 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
203
194
  : []
204
195
  return [...cachedPayloads, ...remainingPayloads.filter(exists)]
205
196
  }
206
-
207
- protected async getCurrentHead() {
208
- const chainArchivist = this.finalizedArchivist
209
- return await findMostRecentBlock(chainArchivist)
210
- }
211
197
  }
@@ -19,6 +19,7 @@ export interface SimpleBlockRewardViewerParams extends CreatableProviderParams {
19
19
  @creatableProvider()
20
20
  export class SimpleBlockRewardViewer extends AbstractCreatableProvider<SimpleBlockRewardViewerParams> implements BlockRewardViewer {
21
21
  static readonly defaultMoniker = BlockRewardViewerMoniker
22
+ static readonly dependencies = []
22
23
  static readonly monikers = [BlockRewardViewerMoniker]
23
24
  moniker = SimpleBlockRewardViewer.defaultMoniker
24
25
 
@@ -0,0 +1,129 @@
1
+ import { exists } from '@xylabs/sdk-js'
2
+ import {
3
+ asXL1BlockRange,
4
+ ChainId,
5
+ type SignedHydratedBlockWithHashMeta,
6
+ } from '@xyo-network/xl1-protocol'
7
+
8
+ import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
9
+ import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
10
+ import { findUncles, getWindowedChain } from '../../primitives/index.ts'
11
+ import type {
12
+ HydratedBlockStateValidationFunction, HydratedBlockValidationError, HydratedBlockValidationFunction,
13
+ } from '../../validation/index.ts'
14
+ import type {
15
+ AccountBalanceViewer,
16
+ BlockValidationConfig,
17
+ BlockValidationQualification,
18
+ BlockValidationViewer,
19
+ } from '../../viewers/index.ts'
20
+ import {
21
+ AccountBalanceViewerMoniker,
22
+ BlockValidationViewerMoniker, BlockViewer, BlockViewerMoniker,
23
+ } from '../../viewers/index.ts'
24
+
25
+ export interface SimpleBlockValidationViewerParams extends CreatableProviderParams {
26
+ maxUncleWindowSize: number
27
+ protocol?: HydratedBlockValidationFunction
28
+ state?: HydratedBlockStateValidationFunction
29
+ }
30
+
31
+ @creatableProvider()
32
+ export class SimpleBlockValidationViewer extends AbstractCreatableProvider<SimpleBlockValidationViewerParams> implements BlockValidationViewer {
33
+ static readonly defaultMoniker = BlockValidationViewerMoniker
34
+ static readonly dependencies = [AccountBalanceViewerMoniker, BlockViewerMoniker]
35
+ static readonly monikers = [BlockValidationViewerMoniker]
36
+ moniker = SimpleBlockValidationViewer.defaultMoniker
37
+
38
+ private _accountBalanceViewer!: AccountBalanceViewer
39
+ private _blockViewer!: BlockViewer
40
+ private _uncleWindowedChainCache: SignedHydratedBlockWithHashMeta[] | null = null
41
+
42
+ protected get blockViewer() {
43
+ return this._blockViewer
44
+ }
45
+
46
+ protected get maxUncleWindowSize() {
47
+ return this.params.maxUncleWindowSize
48
+ }
49
+
50
+ static override async paramsHandler(params: Partial<SimpleBlockValidationViewerParams>): Promise<SimpleBlockValidationViewerParams> {
51
+ return {
52
+ ...await super.paramsHandler(params),
53
+ maxUncleWindowSize: params.maxUncleWindowSize ?? 100,
54
+ } satisfies SimpleBlockValidationViewerParams
55
+ }
56
+
57
+ override async createHandler() {
58
+ await super.createHandler()
59
+ this._accountBalanceViewer = await this.locator.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker)
60
+ this._blockViewer = await this.locator.getInstance<BlockViewer>(BlockViewerMoniker)
61
+ }
62
+
63
+ async qualifiedValidateBlock(
64
+ block: SignedHydratedBlockWithHashMeta,
65
+ config?: BlockValidationConfig,
66
+ ): Promise<[HydratedBlockValidationError[], BlockValidationQualification]> {
67
+ return (await this.qualifiedValidateBlocks([block], config))
68
+ }
69
+
70
+ async qualifiedValidateBlocks(
71
+ blocks: SignedHydratedBlockWithHashMeta[],
72
+ config?: BlockValidationConfig,
73
+ ): Promise<[HydratedBlockValidationError[], BlockValidationQualification]> {
74
+ const { value, state } = config ?? {
75
+ shape: true, links: true, state: true,
76
+ }
77
+
78
+ const [headBlock] = await this.blockViewer.currentBlock()
79
+ const chainId = headBlock.chain
80
+
81
+ const validateProtocol = value ? this.doValidateProtocol.bind(this) : undefined
82
+ const validateState = state ? this.doValidateState.bind(this) : undefined
83
+
84
+ return [(await Promise.all([
85
+ validateProtocol?.(blocks, chainId), validateState?.(blocks, chainId),
86
+ ].filter(exists))).flat(), { head: headBlock._hash, range: asXL1BlockRange([0, headBlock.block], true) }]
87
+ }
88
+
89
+ async validateBlock(block: SignedHydratedBlockWithHashMeta, config?: BlockValidationConfig): Promise<HydratedBlockValidationError[]> {
90
+ return (await this.validateBlocks([block], config))
91
+ }
92
+
93
+ async validateBlocks(blocks: SignedHydratedBlockWithHashMeta[], config?: BlockValidationConfig): Promise<HydratedBlockValidationError[]> {
94
+ return (await this.qualifiedValidateBlocks(blocks, config))[0]
95
+ }
96
+
97
+ private async doValidateProtocol(blocks: SignedHydratedBlockWithHashMeta[], chainId: ChainId): Promise<HydratedBlockValidationError[]> {
98
+ return (await Promise.all(blocks.map(async (block) => {
99
+ return await this.params.protocol!(
100
+ block,
101
+ chainId,
102
+ )
103
+ }))).flat()
104
+ }
105
+
106
+ private async doValidateState(blocks: SignedHydratedBlockWithHashMeta[], chainId: ChainId): Promise<HydratedBlockValidationError[]> {
107
+ const windowedUncleChain = await this.updateWindowedChainCache()
108
+
109
+ const uncles = findUncles(this.context, windowedUncleChain, blocks)
110
+
111
+ if (uncles.length !== 1) {
112
+ this.logger?.warn(JSON.stringify({ uncles, blocks }, null, 2))
113
+ this.logger?.warn(JSON.stringify(windowedUncleChain, null, 2))
114
+ throw new Error(`No uncles or greater than one uncle found in block validation, which is not supported [${uncles.length}, ${blocks.length}]`)
115
+ }
116
+ return (await Promise.all(uncles[0].map(async (block) => {
117
+ return await this.params.state!(
118
+ block,
119
+ chainId,
120
+ { accountBalance: this._accountBalanceViewer },
121
+ )
122
+ }))).flat()
123
+ }
124
+
125
+ private async updateWindowedChainCache() {
126
+ this._uncleWindowedChainCache = await getWindowedChain(this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? [])
127
+ return [...this._uncleWindowedChainCache]
128
+ }
129
+ }
@@ -0,0 +1 @@
1
+ export * from './SimpleBlockValidationViewer.ts'
@@ -21,6 +21,7 @@ export interface SimpleChainStakeParams extends CreatableProviderParams {
21
21
  @creatableProvider()
22
22
  export class SimpleStakeViewer extends AbstractCreatableProvider<SimpleChainStakeParams> implements StakeViewer {
23
23
  static readonly defaultMoniker = StakeViewerMoniker
24
+ static readonly dependencies = [StakeEventsViewerMoniker]
24
25
  static readonly monikers = [StakeViewerMoniker]
25
26
  moniker = SimpleStakeViewer.defaultMoniker
26
27
 
@@ -14,7 +14,8 @@ MapTypeRead<Hash, DataLakeData> = MapTypeRead<Hash, DataLakeData>> extends
14
14
  map: TMap
15
15
  }
16
16
 
17
- export class AbstractSimpleDataLake<TParams extends AbstractSimpleDataLakeParams = AbstractSimpleDataLakeParams> extends AbstractCreatableProvider<TParams> {
17
+ export abstract class AbstractSimpleDataLake<TParams extends AbstractSimpleDataLakeParams = AbstractSimpleDataLakeParams> extends
18
+ AbstractCreatableProvider<TParams> {
18
19
  get allowedSchemas(): Schema[] | undefined {
19
20
  return this.params.allowedSchemas
20
21
  }
@@ -16,6 +16,7 @@ export interface DataLakeRunnerParams extends DataLakeViewerParams<MapType<Hash,
16
16
  export class SimpleDataLakeRunner<TParams extends DataLakeRunnerParams> extends
17
17
  AbstractSimpleDataLake<TParams> implements DataLakeRunner {
18
18
  static readonly defaultMoniker = DataLakeRunnerMoniker
19
+ static readonly dependencies = []
19
20
  static readonly monikers = [DataLakeRunnerMoniker]
20
21
  moniker = SimpleDataLakeRunner.defaultMoniker
21
22
 
@@ -1,5 +1,4 @@
1
1
  import type { Hash } from '@xylabs/sdk-js'
2
- import { isAnyPayload } from '@xyo-network/payload-model'
3
2
 
4
3
  import { creatableProvider } from '../../CreatableProvider/index.ts'
5
4
  import type { MapTypeRead } from '../../map/index.ts'
@@ -18,6 +17,7 @@ export interface DataLakeViewerParams<TMap extends MapTypeRead<Hash, DataLakeDat
18
17
  export class SimpleDataLakeViewer<TParams extends DataLakeViewerParams = DataLakeViewerParams>
19
18
  extends AbstractSimpleDataLake<TParams> implements DataLakeViewer {
20
19
  static readonly defaultMoniker = DataLakeViewerMoniker
20
+ static readonly dependencies = []
21
21
  static readonly monikers = [DataLakeViewerMoniker]
22
22
  moniker = SimpleDataLakeViewer.defaultMoniker
23
23
  }