@xyo-network/chain-services 1.16.8 → 1.16.10

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 (64) hide show
  1. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +14 -4
  2. package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
  3. package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
  4. package/dist/neutral/AccountTransfers/index.d.ts +0 -1
  5. package/dist/neutral/AccountTransfers/index.d.ts.map +1 -1
  6. package/dist/neutral/BaseService.d.ts +2 -5
  7. package/dist/neutral/BaseService.d.ts.map +1 -1
  8. package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +4 -8
  9. package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
  10. package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
  11. package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts +2 -1
  12. package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts.map +1 -1
  13. package/dist/neutral/BlockReward/EvmBlockRewardService.d.ts +2 -2
  14. package/dist/neutral/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
  15. package/dist/neutral/ChainService/Memory/Memory.d.ts +2 -2
  16. package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
  17. package/dist/neutral/ChainValidator/XyoValidator.d.ts +4 -7
  18. package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
  19. package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +3 -5
  20. package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
  21. package/dist/neutral/StepStake/BaseStepStakeService.d.ts +2 -2
  22. package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
  23. package/dist/neutral/Time/BaseTimeSyncService.d.ts +11 -13
  24. package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +1 -1
  25. package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts +4 -0
  26. package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts.map +1 -0
  27. package/dist/neutral/index.mjs +187 -235
  28. package/dist/neutral/index.mjs.map +1 -1
  29. package/dist/neutral/model/Params.d.ts +4 -4
  30. package/dist/neutral/model/Params.d.ts.map +1 -1
  31. package/package.json +25 -24
  32. package/src/AccountBalance/BaseAccountBalanceService.ts +31 -5
  33. package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +1 -0
  34. package/src/AccountTransfers/index.ts +0 -1
  35. package/src/BaseService.ts +2 -8
  36. package/src/BlockProducer/BaseBlockProducerService.ts +4 -4
  37. package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +2 -5
  38. package/src/BlockReward/BaseBlockRewardService.ts +2 -1
  39. package/src/BlockReward/EvmBlockRewardService.ts +4 -2
  40. package/src/ChainService/Memory/Memory.ts +2 -2
  41. package/src/ChainValidator/XyoValidator.ts +2 -1
  42. package/src/StakeIntent/XyoStakeIntentService.ts +4 -3
  43. package/src/StepStake/BaseStepStakeService.ts +2 -2
  44. package/src/Time/BaseTimeSyncService.ts +27 -80
  45. package/src/blockViewerFromChainIteratorAndArchivist.ts +61 -0
  46. package/src/model/Params.ts +4 -4
  47. package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +0 -6
  48. package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +0 -1
  49. package/dist/neutral/ChainBlockIteration/ChainBlockNumberIterationService.d.ts +0 -21
  50. package/dist/neutral/ChainBlockIteration/ChainBlockNumberIterationService.d.ts.map +0 -1
  51. package/dist/neutral/ChainBlockIteration/index.d.ts +0 -3
  52. package/dist/neutral/ChainBlockIteration/index.d.ts.map +0 -1
  53. package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts +0 -7
  54. package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts.map +0 -1
  55. package/dist/neutral/ChainBlockIteration/model/Params.d.ts +0 -8
  56. package/dist/neutral/ChainBlockIteration/model/Params.d.ts.map +0 -1
  57. package/dist/neutral/ChainBlockIteration/model/index.d.ts +0 -3
  58. package/dist/neutral/ChainBlockIteration/model/index.d.ts.map +0 -1
  59. package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +0 -39
  60. package/src/ChainBlockIteration/ChainBlockNumberIterationService.ts +0 -105
  61. package/src/ChainBlockIteration/index.ts +0 -2
  62. package/src/ChainBlockIteration/model/BlockNumberIteration.ts +0 -7
  63. package/src/ChainBlockIteration/model/Params.ts +0 -9
  64. package/src/ChainBlockIteration/model/index.ts +0 -2
@@ -1,21 +0,0 @@
1
- import type { Hex } from '@xylabs/hex';
2
- import type { ArchivistInstance } from '@xyo-network/archivist-model';
3
- import type { WithStorageMeta } from '@xyo-network/payload-model';
4
- import type { BlockBoundWitness } from '@xyo-network/xl1-protocol';
5
- import type { ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk';
6
- import { LRUCache } from 'lru-cache';
7
- import { BaseService } from '../BaseService.ts';
8
- import type { XyoChainIteratorParams } from './model/index.ts';
9
- export declare class ChainBlockNumberIterationService extends BaseService<XyoChainIteratorParams, ChainIteratorServiceEventData> implements EventingChainBlockNumberIteratorService {
10
- protected _blocksByBlockNumber: LRUCache<number, WithStorageMeta<BlockBoundWitness>, unknown>;
11
- protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined;
12
- get chainArchivist(): ArchivistInstance;
13
- get chainId(): Hex;
14
- get(block: number): Promise<WithStorageMeta<BlockBoundWitness>>;
15
- head(): Promise<WithStorageMeta<BlockBoundWitness>>;
16
- next(block: number): Promise<WithStorageMeta<BlockBoundWitness> | undefined>;
17
- previous(block?: number | undefined, count?: number): Promise<WithStorageMeta<BlockBoundWitness>[]>;
18
- updateHead(head: BlockBoundWitness): Promise<void>;
19
- private getBoundWitnessAsBlockBoundWitnessWithStorageMeta;
20
- }
21
- //# sourceMappingURL=ChainBlockNumberIterationService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChainBlockNumberIterationService.d.ts","sourceRoot":"","sources":["../../../src/ChainBlockIteration/ChainBlockNumberIterationService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAMlE,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAuC,EAAE,MAAM,+BAA+B,CAAA;AAC3H,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAE9D,qBAAa,gCAAiC,SAAQ,WAAW,CAAC,sBAAsB,EAAE,6BAA6B,CACrH,YAAW,uCAAuC;IAClD,SAAS,CAAC,oBAAoB,gEAA4E;IAC1G,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAA;IAEtE,IAAI,cAAc,IAAI,iBAAiB,CAAgD;IAEvF,IAAI,OAAO,IAAI,GAAG,CAA2G;IAEvH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IA0B/D,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAUnD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IAQ5E,QAAQ,CAAC,KAAK,GAAE,MAAM,GAAG,SAAqB,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAkBjH,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAM1C,iDAAiD;CAOhE"}
@@ -1,3 +0,0 @@
1
- export * from './ChainBlockNumberIterationService.ts';
2
- export * from './model/index.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ChainBlockIteration/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,kBAAkB,CAAA"}
@@ -1,7 +0,0 @@
1
- import type { Promisable } from '@xylabs/promise';
2
- import type { BlockBoundWitness, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
3
- export interface BlockNumberIteration {
4
- validatePendingBlock(block: BlockBoundWitness): Promisable<Error[]>;
5
- validatePendingTransaction(tx: SignedHydratedTransactionWithStorageMeta): Promise<boolean>;
6
- }
7
- //# sourceMappingURL=BlockNumberIteration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockNumberIteration.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/BlockNumberIteration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAA;AAE5G,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IACnE,0BAA0B,CAAC,EAAE,EAAE,wCAAwC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC3F"}
@@ -1,8 +0,0 @@
1
- import type { ArchivistInstance } from '@xyo-network/archivist-model';
2
- import type { BlockBoundWitness } from '@xyo-network/xl1-protocol';
3
- import type { BaseServiceParams } from '../../model/index.ts';
4
- export interface XyoChainIteratorParams extends BaseServiceParams {
5
- chainArchivist: ArchivistInstance;
6
- head: BlockBoundWitness;
7
- }
8
- //# sourceMappingURL=Params.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,cAAc,EAAE,iBAAiB,CAAA;IACjC,IAAI,EAAE,iBAAiB,CAAA;CACxB"}
@@ -1,3 +0,0 @@
1
- export * from './BlockNumberIteration.ts';
2
- export * from './Params.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA"}
@@ -1,39 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { Hash } from '@xylabs/hex'
3
- import type { ReadArchivist } from '@xyo-network/archivist-model'
4
- import { findMostRecentBlock } from '@xyo-network/chain-protocol'
5
- import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
6
- import type { ChainId } from '@xyo-network/xl1-protocol'
7
- import { StepSizes } from '@xyo-network/xl1-protocol'
8
- import type { AccountTransfersService, TransfersStepSummary } from '@xyo-network/xl1-protocol-sdk'
9
- import { LruCacheMap, readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
10
- import { Semaphore } from 'async-mutex'
11
-
12
- import { BaseAccountTransfersService } from './BaseAccountTransfersService.ts'
13
-
14
- export const accountTransfersServiceFromArchivist = async (
15
- chainId: ChainId,
16
- archivist: ReadArchivist<WithStorageMeta<Payload>>,
17
- ): Promise<AccountTransfersService> => {
18
- const summaryMap = new LruCacheMap<string, TransfersStepSummary>({
19
- max: 100_000,
20
- allowStale: true,
21
- noDisposeOnSet: false,
22
- updateAgeOnGet: true,
23
- })
24
- const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(archivist)
25
- const headFunc = async (): Promise<[Hash, number]> => {
26
- const head = await findMostRecentBlock(archivist)
27
- return [assertEx(head?._hash, () => 'No head found in chainArchivist'), assertEx(head?.block, () => 'No head found in chainArchivist')]
28
- }
29
- const service = await BaseAccountTransfersService.create({
30
- context: {
31
- chainId,
32
- store: { chainMap },
33
- stepSemaphores: StepSizes.map(() => new Semaphore(20)),
34
- summaryMap,
35
- head: headFunc,
36
- },
37
- })
38
- return service
39
- }
@@ -1,105 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { Hex } from '@xylabs/hex'
3
- import {
4
- isDefined, isNull, isUndefined,
5
- } from '@xylabs/typeof'
6
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
7
- import { PayloadBuilder } from '@xyo-network/payload-builder'
8
- import type { WithStorageMeta } from '@xyo-network/payload-model'
9
- import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
10
- import {
11
- asBlockBoundWitness,
12
- asBlockBoundWitnessWithStorageMeta,
13
- isBlockBoundWitness,
14
- } from '@xyo-network/xl1-protocol'
15
- import type { ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk'
16
- import { LRUCache } from 'lru-cache'
17
-
18
- import { BaseService } from '../BaseService.ts'
19
- import type { XyoChainIteratorParams } from './model/index.ts'
20
-
21
- export class ChainBlockNumberIterationService extends BaseService<XyoChainIteratorParams, ChainIteratorServiceEventData>
22
- implements EventingChainBlockNumberIteratorService {
23
- protected _blocksByBlockNumber = new LRUCache<number, WithStorageMeta<BlockBoundWitness>>({ max: 10_000 })
24
- protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined
25
-
26
- get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
27
-
28
- get chainId(): Hex { return assertEx(this._currentHead?.chain ?? this.params?.head?.chain, () => 'Current head is not set') }
29
-
30
- async get(block: number): Promise<WithStorageMeta<BlockBoundWitness>> {
31
- const head = await this.head()
32
- // if(isUndefined(head)) return undefined
33
- // Bail early if the block requested is newer than the current head
34
- assertEx(head.block >= block, () => `Block requested is newer than the current head [${block}]`)
35
- const cached = this._blocksByBlockNumber.get(block)
36
- if (cached) return cached
37
- // Start at the current head and traverse backwards until the requested block is found
38
- const startingBlock = head
39
- const currentBlockHash = await PayloadBuilder.hash(startingBlock)
40
- let currentBlock = (await this.chainArchivist.get([currentBlockHash])).at(0)
41
- while (isDefined(currentBlock)) {
42
- assertEx(asBlockBoundWitness(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`)
43
- if (isBlockBoundWitness(currentBlock)) {
44
- this._blocksByBlockNumber.set(currentBlock.block, currentBlock)
45
- if (currentBlock.block === block) {
46
- return currentBlock
47
- }
48
- const { previous } = currentBlock
49
- if (isNull(previous)) break
50
- currentBlock = (await this.chainArchivist.get([previous])).at(0)
51
- }
52
- }
53
- throw new Error(`Block not found: ${block}`)
54
- }
55
-
56
- async head(): Promise<WithStorageMeta<BlockBoundWitness>> {
57
- if (isDefined(this._currentHead)) return this._currentHead
58
- if (isDefined(this.params.head)) {
59
- const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head)
60
- this._currentHead = newHead
61
- return newHead
62
- }
63
- throw new Error('Head is not set')
64
- }
65
-
66
- async next(block: number): Promise<WithStorageMeta<BlockBoundWitness> | undefined> {
67
- const currentBlock = block
68
- const nextBlockNumber = currentBlock + 1
69
- return await this.get(nextBlockNumber)
70
- }
71
-
72
- // TODO: Decide on inclusive/exclusive (probably need inclusive to account for chain head)
73
- // and then communicate via method name and documentation
74
- async previous(block: number | undefined = undefined, count: number = 1): Promise<WithStorageMeta<BlockBoundWitness>[]> {
75
- const results: WithStorageMeta<BlockBoundWitness>[] = []
76
- let currentBlock: WithStorageMeta<BlockBoundWitness> | undefined = isDefined(block) ? (await this.get(block)) : await this.head()
77
- while (currentBlock && results.length < count) {
78
- if (isBlockBoundWitness(currentBlock)) {
79
- results.push(currentBlock)
80
- const { previous } = currentBlock
81
- if (isNull(previous)) break
82
- const nextBlock = await this.chainArchivist.get([previous])
83
- currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0])
84
- } else {
85
- const hash = PayloadBuilder.hash(currentBlock)
86
- assertEx(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`)
87
- }
88
- }
89
- return results
90
- }
91
-
92
- async updateHead(head: BlockBoundWitness): Promise<void> {
93
- const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head)
94
- this._currentHead = newHead
95
- void this.emit('headUpdated', { blocks: [newHead] })
96
- }
97
-
98
- private async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head: BlockBoundWitness): Promise<WithStorageMeta<BlockBoundWitness>> {
99
- const hash = await PayloadBuilder.hash(head)
100
- const stored = (await this.chainArchivist.get([hash])).at(-1)
101
- const newHead = asBlockBoundWitnessWithStorageMeta(stored)
102
- if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`)
103
- return newHead
104
- }
105
- }
@@ -1,2 +0,0 @@
1
- export * from './ChainBlockNumberIterationService.ts'
2
- export * from './model/index.ts'
@@ -1,7 +0,0 @@
1
- import type { Promisable } from '@xylabs/promise'
2
- import type { BlockBoundWitness, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol'
3
-
4
- export interface BlockNumberIteration {
5
- validatePendingBlock(block: BlockBoundWitness): Promisable<Error[]>
6
- validatePendingTransaction(tx: SignedHydratedTransactionWithStorageMeta): Promise<boolean>
7
- }
@@ -1,9 +0,0 @@
1
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
2
- import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
3
-
4
- import type { BaseServiceParams } from '../../model/index.ts'
5
-
6
- export interface XyoChainIteratorParams extends BaseServiceParams {
7
- chainArchivist: ArchivistInstance
8
- head: BlockBoundWitness
9
- }
@@ -1,2 +0,0 @@
1
- export * from './BlockNumberIteration.ts'
2
- export * from './Params.ts'