@xyo-network/chain-services 1.16.24 → 1.16.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +4 -2
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +6 -6
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +16 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts +2 -2
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts +2 -2
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +96 -89
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +27 -27
- package/src/AccountBalance/BaseAccountBalanceService.ts +12 -9
- package/src/BlockProducer/BaseBlockProducerService.ts +10 -16
- package/src/PendingTransactions/BasePendingTransactions.ts +11 -9
- package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +6 -6
- package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +3 -3
- package/src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts +2 -2
- package/src/blockViewerFromChainIteratorAndArchivist.ts +11 -11
- 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.
|
|
4
|
+
"version": "1.16.26",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -40,44 +40,44 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@opentelemetry/api": "~1.9.0",
|
|
43
|
-
"@xylabs/sdk-js": "~5.0.
|
|
44
|
-
"@xylabs/telemetry": "~5.0.
|
|
45
|
-
"@xyo-network/account-model": "~5.
|
|
46
|
-
"@xyo-network/archivist-memory": "~5.
|
|
47
|
-
"@xyo-network/archivist-model": "~5.
|
|
48
|
-
"@xyo-network/boundwitness-model": "~5.
|
|
49
|
-
"@xyo-network/boundwitness-validator": "~5.
|
|
50
|
-
"@xyo-network/boundwitness-wrapper": "~5.
|
|
51
|
-
"@xyo-network/chain-analyze": "~1.16.
|
|
52
|
-
"@xyo-network/chain-modules": "~1.16.
|
|
53
|
-
"@xyo-network/chain-protocol": "~1.16.
|
|
54
|
-
"@xyo-network/chain-utils": "~1.16.
|
|
55
|
-
"@xyo-network/payload-builder": "~5.
|
|
56
|
-
"@xyo-network/payload-model": "~5.
|
|
43
|
+
"@xylabs/sdk-js": "~5.0.46",
|
|
44
|
+
"@xylabs/telemetry": "~5.0.46",
|
|
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.26",
|
|
52
|
+
"@xyo-network/chain-modules": "~1.16.26",
|
|
53
|
+
"@xyo-network/chain-protocol": "~1.16.26",
|
|
54
|
+
"@xyo-network/chain-utils": "~1.16.26",
|
|
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.
|
|
59
|
-
"@xyo-network/xl1-protocol-sdk": "~1.16.
|
|
60
|
-
"@xyo-network/xl1-validation": "~1.16.
|
|
61
|
-
"@xyo-network/xl1-wrappers": "~1.16.
|
|
58
|
+
"@xyo-network/xl1-protocol": "~1.14.15",
|
|
59
|
+
"@xyo-network/xl1-protocol-sdk": "~1.16.26",
|
|
60
|
+
"@xyo-network/xl1-validation": "~1.16.26",
|
|
61
|
+
"@xyo-network/xl1-wrappers": "~1.16.26",
|
|
62
62
|
"async-mutex": "~0.5.0",
|
|
63
63
|
"ethers": "6.15.0",
|
|
64
64
|
"lru-cache": "~11.2.2",
|
|
65
|
-
"zod": "~4.1.
|
|
65
|
+
"zod": "~4.1.13"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "~24.10.1",
|
|
69
|
-
"@xylabs/sdk-js": "~5.0.
|
|
69
|
+
"@xylabs/sdk-js": "~5.0.46",
|
|
70
70
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
71
71
|
"@xylabs/tsconfig": "~7.2.8",
|
|
72
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
73
|
-
"@xyo-network/account": "~5.
|
|
74
|
-
"@xyo-network/account-model": "~5.
|
|
75
|
-
"@xyo-network/chain-validation": "~1.16.
|
|
76
|
-
"@xyo-network/wallet": "~5.
|
|
72
|
+
"@xylabs/vitest-extended": "~5.0.46",
|
|
73
|
+
"@xyo-network/account": "~5.2.10",
|
|
74
|
+
"@xyo-network/account-model": "~5.2.10",
|
|
75
|
+
"@xyo-network/chain-validation": "~1.16.26",
|
|
76
|
+
"@xyo-network/wallet": "~5.2.10",
|
|
77
77
|
"eslint": "^9.39.1",
|
|
78
78
|
"tslib": "~2.8.1",
|
|
79
79
|
"typescript": "~5.9.3",
|
|
80
|
-
"vitest": "~4.0.
|
|
80
|
+
"vitest": "~4.0.13",
|
|
81
81
|
"vitest-mock-extended": "~3.1.0",
|
|
82
82
|
"web3-types": "~1.10.0"
|
|
83
83
|
},
|
|
@@ -17,10 +17,10 @@ import {
|
|
|
17
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
|
|
|
23
22
|
export const BaseAccountBalanceServiceParamsZod = z.object({
|
|
23
|
+
blockViewer: z.object().loose(),
|
|
24
24
|
chainArchivist: z.object().loose(),
|
|
25
25
|
chainIterator: z.object().loose(),
|
|
26
26
|
context: z.object().loose(),
|
|
@@ -28,6 +28,7 @@ export const BaseAccountBalanceServiceParamsZod = z.object({
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
31
|
+
blockViewer: BlockViewer
|
|
31
32
|
chainArchivist: ReadArchivist
|
|
32
33
|
chainIterator: EventingChainBlockNumberIteratorService
|
|
33
34
|
context: BalanceStepSummaryContext
|
|
@@ -37,7 +38,10 @@ export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
|
37
38
|
@creatable()
|
|
38
39
|
export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceViewer {
|
|
39
40
|
protected accountBalanceViewer!: AccountBalanceViewer
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
protected get blockViewer() {
|
|
43
|
+
return assertEx(this.params.blockViewer, () => 'BlockViewer has not been initialized yet')
|
|
44
|
+
}
|
|
41
45
|
|
|
42
46
|
static override async paramsHandler(params?: Partial<BaseAccountBalanceServiceParams> | undefined): Promise<BaseAccountBalanceServiceParams> {
|
|
43
47
|
// TODO: Use a real zod and move the zod check to the AbstractCreatable class
|
|
@@ -86,12 +90,11 @@ export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceSer
|
|
|
86
90
|
throw new Error('Method not implemented.')
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
override createHandler() {
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
this.params.
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
)
|
|
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
|
+
})
|
|
96
99
|
}
|
|
97
100
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-statements */
|
|
2
2
|
import {
|
|
3
|
-
Address, AddressZod, 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,11 +8,10 @@ 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 {
|
|
11
|
+
import { WithHashMeta } from '@xyo-network/payload-model'
|
|
17
12
|
import {
|
|
18
|
-
AllowedBlockPayload,
|
|
19
|
-
|
|
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 {
|
|
@@ -146,7 +140,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
146
140
|
return { ...(await super.paramsHandler(params)), ...params } as BaseBlockProducerServiceParams
|
|
147
141
|
}
|
|
148
142
|
|
|
149
|
-
async next(head:
|
|
143
|
+
async next(head: WithHashMeta<BlockBoundWitness>): Promise<HydratedBlockWithHashMeta | undefined> {
|
|
150
144
|
// If the block is for another chain, ignore
|
|
151
145
|
if (head.chain !== this.chainId) return
|
|
152
146
|
const leadersStart = Date.now()
|
|
@@ -186,7 +180,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
186
180
|
* @param head The current head block
|
|
187
181
|
* @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
|
|
188
182
|
*/
|
|
189
|
-
protected async getProducerRedeclaration(head:
|
|
183
|
+
protected async getProducerRedeclaration(head: WithHashMeta<BlockBoundWitness>): Promise<ChainStakeIntent | undefined> {
|
|
190
184
|
// Decide if we should redeclare intent
|
|
191
185
|
if (this.params.config.producer.disableIntentRedeclaration) return
|
|
192
186
|
// Decide if we need to redeclare intent
|
|
@@ -203,7 +197,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
203
197
|
return createDeclarationIntent(this.address, 'producer', currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration)
|
|
204
198
|
}
|
|
205
199
|
|
|
206
|
-
protected async proposeNextValidBlock(head:
|
|
200
|
+
protected async proposeNextValidBlock(head: WithHashMeta<BlockBoundWitness>, validateBalances = false): Promise<HydratedBlockWithHashMeta | undefined> {
|
|
207
201
|
return await this.spanAsync('proposeNextValidBlock', async () => {
|
|
208
202
|
// Calculate the next block components
|
|
209
203
|
const { block: previousBlock } = assertEx(asBlockBoundWitness(head), () => 'Invalid head block')
|
|
@@ -267,7 +261,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
267
261
|
|
|
268
262
|
// remove unfunded transactions and block transfers
|
|
269
263
|
private async filterByFunded(
|
|
270
|
-
head:
|
|
264
|
+
head: WithHashMeta<BlockBoundWitness>,
|
|
271
265
|
txs: SignedHydratedTransaction[],
|
|
272
266
|
transfers: Transfer[],
|
|
273
267
|
validateBalances = false,
|
|
@@ -291,7 +285,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
291
285
|
return [fundedTransactions, fundedTransfers]
|
|
292
286
|
}
|
|
293
287
|
|
|
294
|
-
private async generateTimePayload(head:
|
|
288
|
+
private async generateTimePayload(head: WithHashMeta<BlockBoundWitness>) {
|
|
295
289
|
const [ethereum, ethHashOrNull] = await this.time.currentTimeAndHash('ethereum')
|
|
296
290
|
const ethereumHash = asHash(ethHashOrNull, () => 'No ethereum hash available from time sync service')
|
|
297
291
|
const timePayload: TimePayload = {
|
|
@@ -312,7 +306,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
312
306
|
* @param head The current head block
|
|
313
307
|
* @returns True if a heartbeat is required, false otherwise
|
|
314
308
|
*/
|
|
315
|
-
private heartbeatRequired(head:
|
|
309
|
+
private heartbeatRequired(head: WithHashMeta<BlockBoundWitness>): boolean {
|
|
316
310
|
const epoch = head.$epoch
|
|
317
311
|
if (isDefined(epoch)) {
|
|
318
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:
|
|
363
|
-
([txBw]:
|
|
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:
|
|
372
|
-
([txBw]:
|
|
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 {
|
|
4
|
-
import {
|
|
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<
|
|
9
|
-
const
|
|
10
|
-
const tx =
|
|
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,
|
|
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 {
|
|
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:
|
|
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:
|
|
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 {
|
|
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 =
|
|
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
|
-
|
|
6
|
+
SignedHydratedBlockWithHashMeta,
|
|
7
7
|
XL1BlockNumber,
|
|
8
8
|
} from '@xyo-network/xl1-protocol'
|
|
9
|
-
import {
|
|
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<
|
|
17
|
+
blockByHash: async function (hash: Hash): Promise<SignedHydratedBlockWithHashMeta | null> {
|
|
18
18
|
const [payload] = await chainArchivist.get([hash])
|
|
19
|
-
const block =
|
|
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<
|
|
27
|
-
const payload = await chainIterator.get(blockNumber)
|
|
28
|
-
const block = payload ? await PayloadBuilder.
|
|
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<
|
|
36
|
-
const results:
|
|
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<
|
|
47
|
+
currentBlock: async function (): Promise<SignedHydratedBlockWithHashMeta> {
|
|
48
48
|
const head = await chainIterator.head()
|
|
49
|
-
return this.blockByHash(head._hash) as Promise<
|
|
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'
|