@xyo-network/chain-services 1.16.23 → 1.16.25

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 (26) hide show
  1. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +14 -5
  2. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
  3. package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +15 -6
  4. package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
  5. package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +16 -1
  6. package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
  7. package/dist/neutral/ChainValidator/XyoValidator.d.ts +1 -1
  8. package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
  9. package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
  10. package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts +2 -2
  11. package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
  12. package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts +2 -2
  13. package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +1 -1
  14. package/dist/neutral/index.d.ts +1 -0
  15. package/dist/neutral/index.d.ts.map +1 -1
  16. package/dist/neutral/index.mjs +208 -165
  17. package/dist/neutral/index.mjs.map +1 -1
  18. package/package.json +28 -27
  19. package/src/AccountBalance/BaseAccountBalanceService.ts +42 -22
  20. package/src/BlockProducer/BaseBlockProducerService.ts +25 -16
  21. package/src/PendingTransactions/BasePendingTransactions.ts +11 -9
  22. package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +6 -6
  23. package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +3 -3
  24. package/src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts +2 -2
  25. package/src/blockViewerFromChainIteratorAndArchivist.ts +11 -11
  26. package/src/index.ts +1 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/chain-services",
4
- "version": "1.16.23",
4
+ "version": "1.16.25",
5
5
  "description": "XYO Layer One SDK Services",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -40,43 +40,44 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@opentelemetry/api": "~1.9.0",
43
- "@xylabs/sdk-js": "~5.0.39",
44
- "@xylabs/telemetry": "~5.0.39",
45
- "@xyo-network/account-model": "~5.1.24",
46
- "@xyo-network/archivist-memory": "~5.1.24",
47
- "@xyo-network/archivist-model": "~5.1.24",
48
- "@xyo-network/boundwitness-model": "~5.1.24",
49
- "@xyo-network/boundwitness-validator": "~5.1.24",
50
- "@xyo-network/boundwitness-wrapper": "~5.1.24",
51
- "@xyo-network/chain-analyze": "~1.16.23",
52
- "@xyo-network/chain-modules": "~1.16.23",
53
- "@xyo-network/chain-protocol": "~1.16.23",
54
- "@xyo-network/chain-utils": "~1.16.23",
55
- "@xyo-network/payload-builder": "~5.1.24",
56
- "@xyo-network/payload-model": "~5.1.24",
43
+ "@xylabs/sdk-js": "~5.0.42",
44
+ "@xylabs/telemetry": "~5.0.42",
45
+ "@xyo-network/account-model": "~5.2.10",
46
+ "@xyo-network/archivist-memory": "~5.2.10",
47
+ "@xyo-network/archivist-model": "~5.2.10",
48
+ "@xyo-network/boundwitness-model": "~5.2.10",
49
+ "@xyo-network/boundwitness-validator": "~5.2.10",
50
+ "@xyo-network/boundwitness-wrapper": "~5.2.10",
51
+ "@xyo-network/chain-analyze": "~1.16.25",
52
+ "@xyo-network/chain-modules": "~1.16.25",
53
+ "@xyo-network/chain-protocol": "~1.16.25",
54
+ "@xyo-network/chain-utils": "~1.16.25",
55
+ "@xyo-network/payload-builder": "~5.2.10",
56
+ "@xyo-network/payload-model": "~5.2.10",
57
57
  "@xyo-network/typechain": "~4.0.10",
58
- "@xyo-network/xl1-protocol": "~1.13.13",
59
- "@xyo-network/xl1-protocol-sdk": "~1.16.23",
60
- "@xyo-network/xl1-validation": "~1.16.23",
61
- "@xyo-network/xl1-wrappers": "~1.16.23",
58
+ "@xyo-network/xl1-protocol": "~1.14.13",
59
+ "@xyo-network/xl1-protocol-sdk": "~1.16.25",
60
+ "@xyo-network/xl1-validation": "~1.16.25",
61
+ "@xyo-network/xl1-wrappers": "~1.16.25",
62
62
  "async-mutex": "~0.5.0",
63
63
  "ethers": "6.15.0",
64
- "lru-cache": "~11.2.2"
64
+ "lru-cache": "~11.2.2",
65
+ "zod": "~4.1.12"
65
66
  },
66
67
  "devDependencies": {
67
68
  "@types/node": "~24.10.1",
68
- "@xylabs/sdk-js": "~5.0.39",
69
+ "@xylabs/sdk-js": "~5.0.42",
69
70
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
70
71
  "@xylabs/tsconfig": "~7.2.8",
71
- "@xylabs/vitest-extended": "~5.0.39",
72
- "@xyo-network/account": "~5.1.24",
73
- "@xyo-network/account-model": "~5.1.24",
74
- "@xyo-network/chain-validation": "~1.16.23",
75
- "@xyo-network/wallet": "~5.1.24",
72
+ "@xylabs/vitest-extended": "~5.0.42",
73
+ "@xyo-network/account": "~5.2.10",
74
+ "@xyo-network/account-model": "~5.2.10",
75
+ "@xyo-network/chain-validation": "~1.16.25",
76
+ "@xyo-network/wallet": "~5.2.10",
76
77
  "eslint": "^9.39.1",
77
78
  "tslib": "~2.8.1",
78
79
  "typescript": "~5.9.3",
79
- "vitest": "~4.0.10",
80
+ "vitest": "~4.0.13",
80
81
  "vitest-mock-extended": "~3.1.0",
81
82
  "web3-types": "~1.10.0"
82
83
  },
@@ -1,6 +1,5 @@
1
1
  import {
2
- Address, creatable, Hash,
3
- Promisable,
2
+ Address, assertEx, creatable, Hash,
4
3
  } from '@xylabs/sdk-js'
5
4
  import { spanRootAsync } from '@xylabs/telemetry'
6
5
  import { ReadArchivist } from '@xyo-network/archivist-model'
@@ -15,12 +14,21 @@ import {
15
14
  SimpleAccountBalanceViewer,
16
15
  TransfersStepSummaryContext,
17
16
  } from '@xyo-network/xl1-protocol-sdk'
17
+ import z from 'zod'
18
18
 
19
19
  import { BaseService } from '../BaseService.ts'
20
- import { blockViewerFromChainIteratorAndArchivist } from '../blockViewerFromChainIteratorAndArchivist.ts'
21
20
  import { BaseServiceParams } from '../model/index.ts'
22
21
 
22
+ export const BaseAccountBalanceServiceParamsZod = z.object({
23
+ blockViewer: z.object().loose(),
24
+ chainArchivist: z.object().loose(),
25
+ chainIterator: z.object().loose(),
26
+ context: z.object().loose(),
27
+ transferContext: z.object().loose(),
28
+ })
29
+
23
30
  export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
31
+ blockViewer: BlockViewer
24
32
  chainArchivist: ReadArchivist
25
33
  chainIterator: EventingChainBlockNumberIteratorService
26
34
  context: BalanceStepSummaryContext
@@ -30,24 +38,41 @@ export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
30
38
  @creatable()
31
39
  export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceViewer {
32
40
  protected accountBalanceViewer!: AccountBalanceViewer
33
- protected blockViewer!: BlockViewer
41
+
42
+ protected get blockViewer() {
43
+ return assertEx(this.params.blockViewer, () => 'BlockViewer has not been initialized yet')
44
+ }
45
+
46
+ static override async paramsHandler(params?: Partial<BaseAccountBalanceServiceParams> | undefined): Promise<BaseAccountBalanceServiceParams> {
47
+ // TODO: Use a real zod and move the zod check to the AbstractCreatable class
48
+ BaseAccountBalanceServiceParamsZod.parse(params)
49
+ assertEx(params?.context?.head, () => 'BalanceStepSummaryContext is required in BaseAccountBalanceServiceParams')
50
+ return { ...(await super.paramsHandler(params)), ...params } as BaseAccountBalanceServiceParams
51
+ }
34
52
 
35
53
  async accountBalance(address: Address, headOrRange?: XL1BlockRange | Hash): Promise<AttoXL1> {
36
- const balances = await this.accountBalances([address], headOrRange)
54
+ const balances = await this.accountsBalances([address], headOrRange)
37
55
  return balances[address] ?? AttoXL1(0n)
38
56
  }
39
57
 
40
58
  async accountBalanceHistory(address: Address): Promise<AccountBalanceHistoryItem[]>
41
59
  async accountBalanceHistory(address: Address, head: Hash): Promise<AccountBalanceHistoryItem[]>
42
60
  async accountBalanceHistory(address: Address, range: XL1BlockRange): Promise<AccountBalanceHistoryItem[]>
43
- async accountBalanceHistory(address: Address, headOrRange?: Hash | XL1BlockRange): Promise<AccountBalanceHistoryItem[]> {
44
- return await this.accountBalanceViewer.accountBalanceHistory(address, headOrRange)
61
+ accountBalanceHistory(_address: Address, _headOrRange?: Hash | XL1BlockRange): Promise<AccountBalanceHistoryItem[]> {
62
+ throw new Error('Method not implemented.')
45
63
  }
46
64
 
47
- async accountBalances(address: Address[], _headOrRange?: XL1BlockRange | Hash): Promise<Partial<Record<Address, AttoXL1>>> {
65
+ async accountsBalances(address: Address[], _headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AttoXL1>>> {
48
66
  return await spanRootAsync('balances', async () => {
67
+ const context = {
68
+ head: this.params.context.head,
69
+ stepSemaphores: this.params.context.stepSemaphores,
70
+ store: this.params.context.store,
71
+ chainId: this.params.context.chainId,
72
+ summaryMap: this.params.context.summaryMap,
73
+ } satisfies BalanceStepSummaryContext
49
74
  const summary = await balancesSummary(
50
- this.params.context,
75
+ context,
51
76
  )
52
77
  const result: Record<Address, AttoXL1> = {}
53
78
  for (const addr of address) {
@@ -58,23 +83,18 @@ export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceSer
58
83
  })
59
84
  }
60
85
 
61
- accountsBalances(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AttoXL1>>> {
62
- throw new Error('Method not implemented.')
63
- }
64
-
65
86
  async accountsBalancesHistory(addresses: Address[]): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
66
87
  async accountsBalancesHistory(addresses: Address[], head: Hash): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
67
88
  async accountsBalancesHistory(addresses: Address[], range: XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
68
- async accountsBalancesHistory(addresses: Address[], headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>> {
69
- return await this.accountBalanceViewer.accountsBalancesHistory(addresses, headOrRange)
89
+ accountsBalancesHistory(_addresses: Address[], _headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>> {
90
+ throw new Error('Method not implemented.')
70
91
  }
71
92
 
72
- override createHandler() {
73
- this.blockViewer = blockViewerFromChainIteratorAndArchivist(this.params.chainIterator, this.params.chainArchivist)
74
- this.accountBalanceViewer = new SimpleAccountBalanceViewer(
75
- this.params.context,
76
- this.params.transferContext,
77
- this.blockViewer,
78
- )
93
+ override async createHandler() {
94
+ this.accountBalanceViewer = await SimpleAccountBalanceViewer.create({
95
+ context: this.params.context,
96
+ transferContext: this.params.transferContext,
97
+ blockViewer: this.blockViewer,
98
+ })
79
99
  }
80
100
  }
@@ -1,11 +1,6 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
- Address, asHash, assertEx, creatable,
4
- exists,
5
- Hex,
6
- hexToBigInt,
7
- isDefined,
8
- toHex,
3
+ Address, AddressZod, asHash, assertEx, creatable, exists, Hex, hexToBigInt, isDefined, toHex,
9
4
  } from '@xylabs/sdk-js'
10
5
  import { ArchivistInstance } from '@xyo-network/archivist-model'
11
6
  import {
@@ -13,16 +8,16 @@ import {
13
8
  } from '@xyo-network/chain-modules'
14
9
  import { buildNextBlock, createDeclarationIntent } from '@xyo-network/chain-protocol'
15
10
  import { PayloadBuilder } from '@xyo-network/payload-builder'
16
- import { WithStorageMeta } from '@xyo-network/payload-model'
11
+ import { WithHashMeta } from '@xyo-network/payload-model'
17
12
  import {
18
- AllowedBlockPayload,
19
- asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumberPayload, BlockNumberSchema,
20
- ChainStakeIntent, defaultRewardRatio, HydratedBlock, SignedHydratedTransaction, TimePayload, TimeSchema,
13
+ AllowedBlockPayload, asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumberPayload, BlockNumberSchema,
14
+ ChainStakeIntent, defaultRewardRatio, HydratedBlockWithHashMeta, SignedHydratedTransaction, TimePayload, TimeSchema,
21
15
  Transfer, XYO_STEP_REWARD_ADDRESS,
22
16
  } from '@xyo-network/xl1-protocol'
23
17
  import {
24
18
  AccountBalanceViewer, BlockProducerService, Config, PendingTransactionsService, StakeIntentService, TimeSyncViewer,
25
19
  } from '@xyo-network/xl1-protocol-sdk'
20
+ import z from 'zod'
26
21
 
27
22
  import { BaseService } from '../BaseService.ts'
28
23
  import { XyoValidatorParams } from '../ChainValidator/index.ts'
@@ -44,6 +39,14 @@ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
44
39
  */
45
40
  export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
46
41
 
42
+ export const BaseBlockProducerServiceParamsZod = z.object({
43
+ balanceService: z.object().loose(),
44
+ pendingTransactionsService: z.object().loose(),
45
+ rejectedTransactionsArchivist: z.object().loose(),
46
+ rewardAddress: AddressZod,
47
+ time: z.object().loose(),
48
+ })
49
+
47
50
  export interface BaseBlockProducerServiceParams extends XyoValidatorParams<Pick<Config, 'producer'>> {
48
51
  balanceService: AccountBalanceViewer
49
52
  pendingTransactionsService: PendingTransactionsService
@@ -131,7 +134,13 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
131
134
  return assertEx(this.params.validateHydratedBlockState, () => 'validateHydratedBlockState is required')
132
135
  }
133
136
 
134
- async next(head: WithStorageMeta<BlockBoundWitness>): Promise<HydratedBlock | undefined> {
137
+ static override async paramsHandler(params?: Partial<BaseBlockProducerServiceParams> | undefined): Promise<BaseBlockProducerServiceParams> {
138
+ // TODO: Use a real zod and move the zod check to the AbstractCreatable class
139
+ BaseBlockProducerServiceParamsZod.parse(params)
140
+ return { ...(await super.paramsHandler(params)), ...params } as BaseBlockProducerServiceParams
141
+ }
142
+
143
+ async next(head: WithHashMeta<BlockBoundWitness>): Promise<HydratedBlockWithHashMeta | undefined> {
135
144
  // If the block is for another chain, ignore
136
145
  if (head.chain !== this.chainId) return
137
146
  const leadersStart = Date.now()
@@ -171,7 +180,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
171
180
  * @param head The current head block
172
181
  * @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
173
182
  */
174
- protected async getProducerRedeclaration(head: WithStorageMeta<BlockBoundWitness>): Promise<ChainStakeIntent | undefined> {
183
+ protected async getProducerRedeclaration(head: WithHashMeta<BlockBoundWitness>): Promise<ChainStakeIntent | undefined> {
175
184
  // Decide if we should redeclare intent
176
185
  if (this.params.config.producer.disableIntentRedeclaration) return
177
186
  // Decide if we need to redeclare intent
@@ -188,7 +197,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
188
197
  return createDeclarationIntent(this.address, 'producer', currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration)
189
198
  }
190
199
 
191
- protected async proposeNextValidBlock(head: WithStorageMeta<BlockBoundWitness>, validateBalances = false): Promise<HydratedBlock | undefined> {
200
+ protected async proposeNextValidBlock(head: WithHashMeta<BlockBoundWitness>, validateBalances = false): Promise<HydratedBlockWithHashMeta | undefined> {
192
201
  return await this.spanAsync('proposeNextValidBlock', async () => {
193
202
  // Calculate the next block components
194
203
  const { block: previousBlock } = assertEx(asBlockBoundWitness(head), () => 'Invalid head block')
@@ -252,7 +261,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
252
261
 
253
262
  // remove unfunded transactions and block transfers
254
263
  private async filterByFunded(
255
- head: WithStorageMeta<BlockBoundWitness>,
264
+ head: WithHashMeta<BlockBoundWitness>,
256
265
  txs: SignedHydratedTransaction[],
257
266
  transfers: Transfer[],
258
267
  validateBalances = false,
@@ -276,7 +285,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
276
285
  return [fundedTransactions, fundedTransfers]
277
286
  }
278
287
 
279
- private async generateTimePayload(head: WithStorageMeta<BlockBoundWitness>) {
288
+ private async generateTimePayload(head: WithHashMeta<BlockBoundWitness>) {
280
289
  const [ethereum, ethHashOrNull] = await this.time.currentTimeAndHash('ethereum')
281
290
  const ethereumHash = asHash(ethHashOrNull, () => 'No ethereum hash available from time sync service')
282
291
  const timePayload: TimePayload = {
@@ -297,7 +306,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
297
306
  * @param head The current head block
298
307
  * @returns True if a heartbeat is required, false otherwise
299
308
  */
300
- private heartbeatRequired(head: WithStorageMeta<BlockBoundWitness>): boolean {
309
+ private heartbeatRequired(head: WithHashMeta<BlockBoundWitness>): boolean {
301
310
  const epoch = head.$epoch
302
311
  if (isDefined(epoch)) {
303
312
  const { heartbeatInterval } = this.params.config.producer
@@ -12,8 +12,10 @@ import {
12
12
  Payload, PayloadBundle, Sequence, WithStorageMeta,
13
13
  } from '@xyo-network/payload-model'
14
14
  import {
15
- asBlockBoundWitnessWithHashMeta, ChainId, HydratedTransactionValidationFunction, isTransactionBoundWitnessWithStorageMeta,
15
+ asBlockBoundWitnessWithHashMeta, asXL1BlockNumber, ChainId, HydratedTransactionValidationFunction, isTransactionBoundWitnessWithStorageMeta,
16
+ SignedHydratedTransactionWithHashMeta,
16
17
  SignedHydratedTransactionWithStorageMeta,
18
+ XL1BlockNumber,
17
19
  } from '@xyo-network/xl1-protocol'
18
20
  import { PendingTransactionsService } from '@xyo-network/xl1-protocol-sdk'
19
21
  import { TransactionJsonSchemaValidator, validateTransaction } from '@xyo-network/xl1-validation'
@@ -145,7 +147,7 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
145
147
  // Acquires an exclusive mutex to ensure no race conditions while accessing pending transactions.
146
148
  return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
147
149
  // Find the supplied head
148
- let [lastHead] = filterAs(await this.chainArchivist.get([head]), asBlockBoundWitnessWithHashMeta)
150
+ let [lastHead] = filterAs(await this.chainArchivist.get([head]), x => asBlockBoundWitnessWithHashMeta(x))
149
151
  if (isUndefined(lastHead)) return []
150
152
 
151
153
  await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash)
@@ -179,7 +181,7 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
179
181
 
180
182
  // Filter transactions to only include those that are active for the next
181
183
  // potential block based on the last supplied head.
182
- const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1))
184
+ const activeTransactions = transactions.filter(isTransactionActive(asXL1BlockNumber(lastHead.block + 1, true)))
183
185
 
184
186
  const txValidationResults = await Promise.all(activeTransactions.map(async tx => ([tx, await validateTransaction(
185
187
  tx,
@@ -287,7 +289,7 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
287
289
  const foundPendingTransactionsToDeleteHashes: Hash[] = []
288
290
 
289
291
  let cursor: Sequence | undefined
290
- let [lastHead] = filterAs(await this.chainArchivist.get([head]), asBlockBoundWitnessWithHashMeta)
292
+ let [lastHead] = filterAs(await this.chainArchivist.get([head]), x => asBlockBoundWitnessWithHashMeta(x))
291
293
 
292
294
  // Continue fetching until the desired number of transactions is reached.
293
295
  while (isDefined(lastHead)) {
@@ -325,7 +327,7 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
325
327
  )).filter(exists)
326
328
 
327
329
  // Find expired transactions based on the last supplied head
328
- const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1))
330
+ const expiredTransactions = transactions.filter(isTransactionExpired(asXL1BlockNumber(lastHead.block + 1, true)))
329
331
  // Find the corresponding bundle hashes for the expired transactions
330
332
  const expiredBundleHashes = expiredTransactions
331
333
  .map(expiredHydratedTx =>
@@ -359,8 +361,8 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
359
361
  * @param block The block number to check against the transaction's validity period.
360
362
  * @returns True if the transaction is expired for the given block, false otherwise.
361
363
  */
362
- const isTransactionExpired = (block: number) =>
363
- ([txBw]: SignedHydratedTransactionWithStorageMeta): boolean =>
364
+ const isTransactionExpired = (block: XL1BlockNumber) =>
365
+ ([txBw]: SignedHydratedTransactionWithHashMeta): boolean =>
364
366
  txBw.exp < block
365
367
 
366
368
  /**
@@ -368,6 +370,6 @@ const isTransactionExpired = (block: number) =>
368
370
  * @param block The block number to check against the transaction's validity period.
369
371
  * @returns True if the transaction is active for the given block, false otherwise.
370
372
  */
371
- const isTransactionActive = (block: number) =>
372
- ([txBw]: SignedHydratedTransactionWithStorageMeta): boolean =>
373
+ const isTransactionActive = (block: XL1BlockNumber) =>
374
+ ([txBw]: SignedHydratedTransactionWithHashMeta): boolean =>
373
375
  txBw.nbf <= block && txBw.exp >= block
@@ -1,14 +1,14 @@
1
1
  import { PayloadBuilder } from '@xyo-network/payload-builder'
2
2
  import type { PayloadBundle, WithStorageMeta } from '@xyo-network/payload-model'
3
- import type { SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol'
4
- import { asTransactionBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
3
+ import type { SignedHydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol'
4
+ import { asSignedTransactionBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol'
5
5
 
6
6
  export const bundledPayloadToHydratedTransaction = async (
7
7
  payload: WithStorageMeta<PayloadBundle>,
8
- ): Promise<SignedHydratedTransactionWithStorageMeta | undefined> => {
9
- const withStorageMeta = await PayloadBuilder.addStorageMeta(payload.payloads)
10
- const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find(p => p._hash === payload.root))
8
+ ): Promise<SignedHydratedTransactionWithHashMeta | undefined> => {
9
+ const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads)
10
+ const tx = asSignedTransactionBoundWitnessWithHashMeta(withHashMeta.find(p => p._hash === payload.root))
11
11
  if (tx) {
12
- return [tx, withStorageMeta.filter(p => p._hash !== payload.root)]
12
+ return [tx, withHashMeta.filter(p => p._hash !== payload.root)]
13
13
  }
14
14
  }
@@ -2,15 +2,15 @@ import type { Hash } from '@xylabs/sdk-js'
2
2
  import { PayloadBuilder } from '@xyo-network/payload-builder'
3
3
  import type { PayloadBundle } from '@xyo-network/payload-model'
4
4
  import { PayloadBundleSchema } from '@xyo-network/payload-model'
5
- import type { SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol'
5
+ import type { SignedHydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol'
6
6
  import { flattenHydratedTransaction } from '@xyo-network/xl1-protocol-sdk'
7
7
 
8
- export const hydratedTransactionToPayloadBundle = (transaction: SignedHydratedTransactionWithStorageMeta): PayloadBundle => {
8
+ export const hydratedTransactionToPayloadBundle = (transaction: SignedHydratedTransactionWithHashMeta): PayloadBundle => {
9
9
  const root = transaction[0]._hash
10
10
  return bundle(root, transaction)
11
11
  }
12
12
 
13
- const bundle = (root: Hash, transaction: SignedHydratedTransactionWithStorageMeta) => {
13
+ const bundle = (root: Hash, transaction: SignedHydratedTransactionWithHashMeta) => {
14
14
  const payloads = flattenHydratedTransaction(transaction).flatMap(p => PayloadBuilder.omitStorageMeta(p))
15
15
  return new PayloadBuilder<PayloadBundle>({ schema: PayloadBundleSchema })
16
16
  .fields({ payloads, root })
@@ -2,7 +2,7 @@ import type { Hash } from '@xylabs/sdk-js'
2
2
  import { exists, filterAs } from '@xylabs/sdk-js'
3
3
  import type { ArchivistInstance } from '@xyo-network/archivist-model'
4
4
  import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import { asOptionalBoundWitness } from '@xyo-network/boundwitness-model'
5
+ import { isBoundWitness } from '@xyo-network/boundwitness-model'
6
6
  import { payloadSchemasContains } from '@xyo-network/boundwitness-validator'
7
7
  import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
8
8
  import type {
@@ -14,7 +14,7 @@ export const getBlockSignedStakeDeclarations = async (block: BlockBoundWitness,
14
14
  // Get payloads in block
15
15
  const blockData = await archivist.get(block.payload_hashes)
16
16
  // Filter Payloads in block to BoundWitnesses
17
- const bwsFromBlock = filterAs(blockData, asOptionalBoundWitness)
17
+ const bwsFromBlock = blockData.filter(x => isBoundWitness(x))
18
18
  // Filter to BoundWitnesses with StakeIntent payloads
19
19
  const bwsFromBlockWithDeclarations = bwsFromBlock.filter(bw => payloadSchemasContains(bw, ChainStakeIntentSchema))
20
20
  // Filter to only valid signed BWs
@@ -3,10 +3,10 @@ import { isDefined } from '@xylabs/sdk-js'
3
3
  import type { ReadArchivist } from '@xyo-network/archivist-model'
4
4
  import { PayloadBuilder } from '@xyo-network/payload-builder'
5
5
  import type {
6
- HydratedBlock,
6
+ SignedHydratedBlockWithHashMeta,
7
7
  XL1BlockNumber,
8
8
  } from '@xyo-network/xl1-protocol'
9
- import { asBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
9
+ import { asSignedBlockBoundWitness, asSignedBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
10
10
  import type { BlockViewer, EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk'
11
11
 
12
12
  export function blockViewerFromChainIteratorAndArchivist(
@@ -14,26 +14,26 @@ export function blockViewerFromChainIteratorAndArchivist(
14
14
  chainArchivist: ReadArchivist,
15
15
  ): BlockViewer {
16
16
  const result = {
17
- blockByHash: async function (hash: Hash): Promise<HydratedBlock | null> {
17
+ blockByHash: async function (hash: Hash): Promise<SignedHydratedBlockWithHashMeta | null> {
18
18
  const [payload] = await chainArchivist.get([hash])
19
- const block = asBlockBoundWitnessWithStorageMeta(payload)
19
+ const block = asSignedBlockBoundWitnessWithStorageMeta(payload)
20
20
  if (isDefined(block)) {
21
21
  const payloads = await chainArchivist.get(block.payload_hashes)
22
22
  return [block, payloads]
23
23
  }
24
24
  return null
25
25
  },
26
- blockByNumber: async function (blockNumber: XL1BlockNumber): Promise<HydratedBlock | null> {
27
- const payload = await chainIterator.get(blockNumber)
28
- const block = payload ? await PayloadBuilder.addStorageMeta(payload) : undefined
26
+ blockByNumber: async function (blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {
27
+ const payload = asSignedBlockBoundWitness(await chainIterator.get(blockNumber))
28
+ const block = payload ? await PayloadBuilder.addHashMeta(payload) : undefined
29
29
  if (isDefined(block)) {
30
30
  const payloads = await chainArchivist.get(block.payload_hashes)
31
31
  return [block, payloads]
32
32
  }
33
33
  return null
34
34
  },
35
- blocksByHash: async function (hash: Hash, limit = 10): Promise<HydratedBlock[]> {
36
- const results: HydratedBlock[] = []
35
+ blocksByHash: async function (hash: Hash, limit = 10): Promise<SignedHydratedBlockWithHashMeta[]> {
36
+ const results: SignedHydratedBlockWithHashMeta[] = []
37
37
  for (let i = 0; i < limit; i++) {
38
38
  const block = await this.blockByHash(hash)
39
39
  if (block) {
@@ -44,9 +44,9 @@ export function blockViewerFromChainIteratorAndArchivist(
44
44
  }
45
45
  return results
46
46
  },
47
- currentBlock: async function (): Promise<HydratedBlock> {
47
+ currentBlock: async function (): Promise<SignedHydratedBlockWithHashMeta> {
48
48
  const head = await chainIterator.head()
49
- return this.blockByHash(head._hash) as Promise<HydratedBlock>
49
+ return this.blockByHash(head._hash) as Promise<SignedHydratedBlockWithHashMeta>
50
50
  },
51
51
  currentBlockHash: async function (): Promise<Hash> {
52
52
  const head = await chainIterator.head()
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export * from './AccountTransfers/index.ts'
3
3
  export * from './BaseService.ts'
4
4
  export * from './BlockProducer/index.ts'
5
5
  export * from './BlockReward/index.ts'
6
+ export * from './blockViewerFromChainIteratorAndArchivist.ts'
6
7
  export * from './ChainBlockNumberIteration/index.ts'
7
8
  export * from './ChainService/index.ts'
8
9
  export * from './ChainValidator/index.ts'