@xyo-network/chain-services 1.16.9 → 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.
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +14 -4
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/index.d.ts +0 -1
- package/dist/neutral/AccountTransfers/index.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +2 -6
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -6
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +1 -3
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +7 -10
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +1 -1
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts +4 -0
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts.map +1 -0
- package/dist/neutral/index.mjs +187 -232
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +25 -25
- package/src/AccountBalance/BaseAccountBalanceService.ts +31 -5
- package/src/AccountTransfers/index.ts +0 -1
- package/src/BlockProducer/BaseBlockProducerService.ts +2 -2
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +2 -5
- package/src/StakeIntent/XyoStakeIntentService.ts +2 -2
- package/src/Time/BaseTimeSyncService.ts +24 -78
- package/src/blockViewerFromChainIteratorAndArchivist.ts +61 -0
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +0 -6
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +0 -1
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +0 -39
package/dist/neutral/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { Semaphore } from "async-mutex";
|
|
|
12
12
|
import { creatable as creatable2 } from "@xylabs/creatable";
|
|
13
13
|
import { spanRootAsync as spanRootAsync2 } from "@xylabs/telemetry";
|
|
14
14
|
import { AttoXL1 } from "@xyo-network/xl1-protocol";
|
|
15
|
-
import { balancesSummary } from "@xyo-network/xl1-protocol-sdk";
|
|
15
|
+
import { balancesSummary, SimpleAccountBalanceViewer } from "@xyo-network/xl1-protocol-sdk";
|
|
16
16
|
|
|
17
17
|
// src/BaseService.ts
|
|
18
18
|
import { AbstractCreatable, creatable } from "@xylabs/creatable";
|
|
@@ -64,6 +64,67 @@ function creatableService() {
|
|
|
64
64
|
}
|
|
65
65
|
__name(creatableService, "creatableService");
|
|
66
66
|
|
|
67
|
+
// src/blockViewerFromChainIteratorAndArchivist.ts
|
|
68
|
+
import { isDefined } from "@xylabs/typeof";
|
|
69
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
70
|
+
import { asBlockBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
71
|
+
function blockViewerFromChainIteratorAndArchivist(chainIterator, chainArchivist) {
|
|
72
|
+
const result = {
|
|
73
|
+
blockByHash: /* @__PURE__ */ __name(async function(hash) {
|
|
74
|
+
const [payload] = await chainArchivist.get([
|
|
75
|
+
hash
|
|
76
|
+
]);
|
|
77
|
+
const block = asBlockBoundWitnessWithStorageMeta(payload);
|
|
78
|
+
if (isDefined(block)) {
|
|
79
|
+
const payloads = await chainArchivist.get(block.payload_hashes);
|
|
80
|
+
return [
|
|
81
|
+
block,
|
|
82
|
+
payloads
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}, "blockByHash"),
|
|
87
|
+
blockByNumber: /* @__PURE__ */ __name(async function(blockNumber) {
|
|
88
|
+
const payload = await chainIterator.get(blockNumber);
|
|
89
|
+
const block = payload ? await PayloadBuilder.addStorageMeta(payload) : void 0;
|
|
90
|
+
if (isDefined(block)) {
|
|
91
|
+
const payloads = await chainArchivist.get(block.payload_hashes);
|
|
92
|
+
return [
|
|
93
|
+
block,
|
|
94
|
+
payloads
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}, "blockByNumber"),
|
|
99
|
+
blocksByHash: /* @__PURE__ */ __name(async function(hash, limit = 10) {
|
|
100
|
+
const results = [];
|
|
101
|
+
for (let i = 0; i < limit; i++) {
|
|
102
|
+
const block = await this.blockByHash(hash);
|
|
103
|
+
if (block) {
|
|
104
|
+
results.push(block);
|
|
105
|
+
} else {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
}, "blocksByHash"),
|
|
111
|
+
currentBlock: /* @__PURE__ */ __name(async function() {
|
|
112
|
+
const head = await chainIterator.head();
|
|
113
|
+
return this.blockByHash(head._hash);
|
|
114
|
+
}, "currentBlock"),
|
|
115
|
+
currentBlockHash: /* @__PURE__ */ __name(async function() {
|
|
116
|
+
const head = await chainIterator.head();
|
|
117
|
+
return head._hash;
|
|
118
|
+
}, "currentBlockHash"),
|
|
119
|
+
currentBlockNumber: /* @__PURE__ */ __name(async function() {
|
|
120
|
+
const head = await chainIterator.head();
|
|
121
|
+
return head.block;
|
|
122
|
+
}, "currentBlockNumber")
|
|
123
|
+
};
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
__name(blockViewerFromChainIteratorAndArchivist, "blockViewerFromChainIteratorAndArchivist");
|
|
127
|
+
|
|
67
128
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
68
129
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
69
130
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -76,14 +137,16 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
76
137
|
static {
|
|
77
138
|
__name(this, "BaseAccountBalanceService");
|
|
78
139
|
}
|
|
140
|
+
accountBalanceViewer;
|
|
141
|
+
blockViewer;
|
|
79
142
|
async accountBalance(address, headOrRange) {
|
|
80
143
|
const balances = await this.accountBalances([
|
|
81
144
|
address
|
|
82
145
|
], headOrRange);
|
|
83
146
|
return balances[address] ?? AttoXL1(0n);
|
|
84
147
|
}
|
|
85
|
-
accountBalanceHistory(
|
|
86
|
-
|
|
148
|
+
async accountBalanceHistory(address, headOrRange) {
|
|
149
|
+
return await this.accountBalanceViewer.accountBalanceHistory(address, headOrRange);
|
|
87
150
|
}
|
|
88
151
|
async accountBalances(address, _headOrRange) {
|
|
89
152
|
return await spanRootAsync2("balances", async () => {
|
|
@@ -96,8 +159,12 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
96
159
|
return result;
|
|
97
160
|
});
|
|
98
161
|
}
|
|
99
|
-
accountBalancesHistories(
|
|
100
|
-
|
|
162
|
+
async accountBalancesHistories(addresses, headOrRange) {
|
|
163
|
+
return await this.accountBalanceViewer.accountBalancesHistories(addresses, headOrRange);
|
|
164
|
+
}
|
|
165
|
+
createHandler() {
|
|
166
|
+
this.blockViewer = blockViewerFromChainIteratorAndArchivist(this.params.chainIterator, this.params.chainArchivist);
|
|
167
|
+
this.accountBalanceViewer = new SimpleAccountBalanceViewer(this.params.context, this.params.transferContext, this.blockViewer);
|
|
101
168
|
}
|
|
102
169
|
};
|
|
103
170
|
BaseAccountBalanceService = _ts_decorate2([
|
|
@@ -134,13 +201,6 @@ var accountBalancesServiceFromArchivist = /* @__PURE__ */ __name(async (chainId,
|
|
|
134
201
|
return service;
|
|
135
202
|
}, "accountBalancesServiceFromArchivist");
|
|
136
203
|
|
|
137
|
-
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
138
|
-
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
139
|
-
import { findMostRecentBlock as findMostRecentBlock2 } from "@xyo-network/chain-protocol";
|
|
140
|
-
import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
141
|
-
import { LruCacheMap as LruCacheMap2, readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
142
|
-
import { Semaphore as Semaphore2 } from "async-mutex";
|
|
143
|
-
|
|
144
204
|
// src/AccountTransfers/BaseAccountTransfersService.ts
|
|
145
205
|
import { creatable as creatable3 } from "@xylabs/creatable";
|
|
146
206
|
import { spanRootAsync as spanRootAsync3 } from "@xylabs/telemetry";
|
|
@@ -178,59 +238,29 @@ BaseAccountTransfersService = _ts_decorate3([
|
|
|
178
238
|
creatable3()
|
|
179
239
|
], BaseAccountTransfersService);
|
|
180
240
|
|
|
181
|
-
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
182
|
-
var accountTransfersServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
183
|
-
const summaryMap = new LruCacheMap2({
|
|
184
|
-
max: 1e5,
|
|
185
|
-
allowStale: true,
|
|
186
|
-
noDisposeOnSet: false,
|
|
187
|
-
updateAgeOnGet: true
|
|
188
|
-
});
|
|
189
|
-
const chainMap = readPayloadMapFromStore2(archivist);
|
|
190
|
-
const headFunc = /* @__PURE__ */ __name(async () => {
|
|
191
|
-
const head = await findMostRecentBlock2(archivist);
|
|
192
|
-
return [
|
|
193
|
-
assertEx2(head?._hash, () => "No head found in chainArchivist"),
|
|
194
|
-
assertEx2(head?.block, () => "No head found in chainArchivist")
|
|
195
|
-
];
|
|
196
|
-
}, "headFunc");
|
|
197
|
-
const service = await BaseAccountTransfersService.create({
|
|
198
|
-
context: {
|
|
199
|
-
chainId,
|
|
200
|
-
store: {
|
|
201
|
-
chainMap
|
|
202
|
-
},
|
|
203
|
-
stepSemaphores: StepSizes2.map(() => new Semaphore2(20)),
|
|
204
|
-
summaryMap,
|
|
205
|
-
head: headFunc
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
return service;
|
|
209
|
-
}, "accountTransfersServiceFromArchivist");
|
|
210
|
-
|
|
211
241
|
// src/BlockProducer/BaseBlockProducerService.ts
|
|
212
|
-
import { assertEx as
|
|
242
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
213
243
|
import { creatable as creatable4 } from "@xylabs/creatable";
|
|
214
244
|
import { exists } from "@xylabs/exists";
|
|
215
|
-
import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
216
|
-
import { isDefined } from "@xylabs/typeof";
|
|
245
|
+
import { asHash, hexToBigInt, toHex } from "@xylabs/hex";
|
|
246
|
+
import { isDefined as isDefined2 } from "@xylabs/typeof";
|
|
217
247
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
218
248
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
219
|
-
import { PayloadBuilder as
|
|
249
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
220
250
|
import { asBlockBoundWitness, AttoXL1 as AttoXL13, BlockNumberSchema, defaultRewardRatio, TimeSchema, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
221
251
|
|
|
222
252
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
223
|
-
import { assertEx as
|
|
253
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
224
254
|
import { hexFromBigInt } from "@xylabs/hex";
|
|
225
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
255
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
226
256
|
import { TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
227
257
|
import { transactionRequiredGas } from "@xyo-network/xl1-protocol-sdk";
|
|
228
258
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
229
259
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
230
260
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
231
261
|
return HydratedTransactionWrapper.parse([
|
|
232
|
-
await
|
|
233
|
-
await
|
|
262
|
+
await PayloadBuilder2.addStorageMeta(tx[0]),
|
|
263
|
+
await PayloadBuilder2.addStorageMeta(tx[1])
|
|
234
264
|
]);
|
|
235
265
|
}));
|
|
236
266
|
const txBaseFeeCosts = {};
|
|
@@ -256,7 +286,7 @@ async function generateTransactionFeeTransfers(address, transactions) {
|
|
|
256
286
|
return payload;
|
|
257
287
|
});
|
|
258
288
|
for (const [from, amount] of Object.entries(txGasCosts)) {
|
|
259
|
-
const fromPayload =
|
|
289
|
+
const fromPayload = assertEx2(payloads.find((p) => p.from === from), () => "from payload not found");
|
|
260
290
|
fromPayload.transfers[address] = hexFromBigInt(amount);
|
|
261
291
|
}
|
|
262
292
|
return payloads;
|
|
@@ -303,40 +333,40 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
303
333
|
return this.account.address;
|
|
304
334
|
}
|
|
305
335
|
get account() {
|
|
306
|
-
return
|
|
336
|
+
return assertEx3(this.params.account, () => "account is required");
|
|
307
337
|
}
|
|
308
338
|
get balanceService() {
|
|
309
|
-
return
|
|
339
|
+
return assertEx3(this.params.balanceService, () => "balanceService is required");
|
|
310
340
|
}
|
|
311
341
|
get chainArchivist() {
|
|
312
|
-
return
|
|
342
|
+
return assertEx3(this.params.chainArchivist, () => "chainArchivist is required");
|
|
313
343
|
}
|
|
314
344
|
get chainId() {
|
|
315
|
-
return
|
|
345
|
+
return assertEx3(this.params.chainId, () => "chainId is required");
|
|
316
346
|
}
|
|
317
347
|
get electionService() {
|
|
318
|
-
return
|
|
348
|
+
return assertEx3(this.params.electionService, () => "electionService is required");
|
|
319
349
|
}
|
|
320
350
|
get pendingTransactionsService() {
|
|
321
|
-
return
|
|
351
|
+
return assertEx3(this.params.pendingTransactionsService, () => "Missing pendingTransactionsService");
|
|
322
352
|
}
|
|
323
353
|
get rejectedTransactionsArchivist() {
|
|
324
|
-
return
|
|
354
|
+
return assertEx3(this.params.rejectedTransactionsArchivist, () => "No rejected bundled transactions archivist");
|
|
325
355
|
}
|
|
326
356
|
get rewardAddress() {
|
|
327
|
-
return
|
|
357
|
+
return assertEx3(this.params.rewardAddress, () => "No reward address provided");
|
|
328
358
|
}
|
|
329
359
|
get rewardService() {
|
|
330
|
-
return
|
|
360
|
+
return assertEx3(this.params.rewardService, () => "rewardService is required");
|
|
331
361
|
}
|
|
332
362
|
get stakeIntentService() {
|
|
333
|
-
return
|
|
363
|
+
return assertEx3(this.params.stakeIntentService, () => "No StakeIntentService provided");
|
|
334
364
|
}
|
|
335
365
|
get time() {
|
|
336
|
-
return
|
|
366
|
+
return assertEx3(this.params.time, () => "No TimeSyncViewer provided");
|
|
337
367
|
}
|
|
338
368
|
get validateHydratedBlockState() {
|
|
339
|
-
return
|
|
369
|
+
return assertEx3(this.params.validateHydratedBlockState, () => "validateHydratedBlockState is required");
|
|
340
370
|
}
|
|
341
371
|
async next(head) {
|
|
342
372
|
if (head.chain !== this.chainId) return;
|
|
@@ -361,8 +391,8 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
361
391
|
}
|
|
362
392
|
});
|
|
363
393
|
}
|
|
364
|
-
const blockHex =
|
|
365
|
-
const blockId = new
|
|
394
|
+
const blockHex = assertEx3(toHex(block), () => "Failed to convert block to hex");
|
|
395
|
+
const blockId = new PayloadBuilder3({
|
|
366
396
|
schema: BlockNumberSchema
|
|
367
397
|
}).fields({
|
|
368
398
|
block: blockHex
|
|
@@ -390,7 +420,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
390
420
|
}
|
|
391
421
|
async proposeNextValidBlock(head, validateBalances = false) {
|
|
392
422
|
return await this.spanAsync("proposeNextValidBlock", async () => {
|
|
393
|
-
const { block: previousBlock } =
|
|
423
|
+
const { block: previousBlock } = assertEx3(asBlockBoundWitness(head), () => "Invalid head block");
|
|
394
424
|
const nextBlock = previousBlock + 1;
|
|
395
425
|
const nextBlockTransactionsStart = Date.now();
|
|
396
426
|
const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash, _BaseBlockProducerService.DefaultBlockSize);
|
|
@@ -464,7 +494,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
464
494
|
}
|
|
465
495
|
async generateTimePayload(head) {
|
|
466
496
|
const [ethereum, ethHashOrNull] = await this.time.currentTimeAndHash("ethereum");
|
|
467
|
-
const ethereumHash =
|
|
497
|
+
const ethereumHash = asHash(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
468
498
|
const timePayload = {
|
|
469
499
|
schema: TimeSchema,
|
|
470
500
|
// note, this is for the previous block
|
|
@@ -484,7 +514,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
484
514
|
*/
|
|
485
515
|
heartbeatRequired(head) {
|
|
486
516
|
const epoch = head.$epoch;
|
|
487
|
-
if (
|
|
517
|
+
if (isDefined2(epoch)) {
|
|
488
518
|
const { heartbeatInterval } = this.params.config.producer;
|
|
489
519
|
if (Date.now() - epoch > heartbeatInterval) {
|
|
490
520
|
return true;
|
|
@@ -519,7 +549,7 @@ BaseBlockRewardService = _ts_decorate5([
|
|
|
519
549
|
], BaseBlockRewardService);
|
|
520
550
|
|
|
521
551
|
// src/BlockReward/EvmBlockRewardService.ts
|
|
522
|
-
import { assertEx as
|
|
552
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
523
553
|
import { creatable as creatable6 } from "@xylabs/creatable";
|
|
524
554
|
import { toEthAddress } from "@xylabs/hex";
|
|
525
555
|
import { XyoChainRewards__factory as XyoChainRewardsFactory } from "@xyo-network/typechain";
|
|
@@ -536,13 +566,13 @@ var EvmBlockRewardService = class extends BaseBlockRewardService {
|
|
|
536
566
|
}
|
|
537
567
|
_contractAddress;
|
|
538
568
|
get chainService() {
|
|
539
|
-
return
|
|
569
|
+
return assertEx4(this.params.chainService, () => "chainService is required");
|
|
540
570
|
}
|
|
541
571
|
get contractAddress() {
|
|
542
|
-
return
|
|
572
|
+
return assertEx4(this._contractAddress, () => "contractAddress is required");
|
|
543
573
|
}
|
|
544
574
|
get provider() {
|
|
545
|
-
return
|
|
575
|
+
return assertEx4(this.params.provider, () => "provider is required");
|
|
546
576
|
}
|
|
547
577
|
async createHandler() {
|
|
548
578
|
await super.createHandler();
|
|
@@ -563,7 +593,7 @@ EvmBlockRewardService = _ts_decorate6([
|
|
|
563
593
|
], EvmBlockRewardService);
|
|
564
594
|
|
|
565
595
|
// src/BlockReward/MemoryBlockRewardService.ts
|
|
566
|
-
import { assertEx as
|
|
596
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
567
597
|
import { creatable as creatable7 } from "@xylabs/creatable";
|
|
568
598
|
import { toFixedPoint } from "@xylabs/decimal-precision";
|
|
569
599
|
import { rewardFromBlockNumber } from "@xyo-network/chain-protocol";
|
|
@@ -580,22 +610,22 @@ var MemoryBlockRewardService = class extends BaseBlockRewardService {
|
|
|
580
610
|
}
|
|
581
611
|
rewardFromBlockNumber = rewardFromBlockNumber(18);
|
|
582
612
|
get creatorReward() {
|
|
583
|
-
return
|
|
613
|
+
return assertEx5(this.params.creatorReward, () => "creatorReward is required");
|
|
584
614
|
}
|
|
585
615
|
get initialReward() {
|
|
586
|
-
return
|
|
616
|
+
return assertEx5(this.params.initialStepReward, () => "initialStepReward is required");
|
|
587
617
|
}
|
|
588
618
|
get minRewardPerBlock() {
|
|
589
|
-
return
|
|
619
|
+
return assertEx5(this.params.minRewardPerBlock, () => "minRewardPerBlock is required");
|
|
590
620
|
}
|
|
591
621
|
get stepFactorDenominator() {
|
|
592
|
-
return
|
|
622
|
+
return assertEx5(this.params.stepFactorDenominator, () => "stepFactorDenominator is required");
|
|
593
623
|
}
|
|
594
624
|
get stepFactorNumerator() {
|
|
595
|
-
return
|
|
625
|
+
return assertEx5(this.params.stepFactorNumerator, () => "stepFactorNumerator is required");
|
|
596
626
|
}
|
|
597
627
|
get stepSize() {
|
|
598
|
-
return
|
|
628
|
+
return assertEx5(this.params.stepSize, () => "stepSize is required");
|
|
599
629
|
}
|
|
600
630
|
static async paramsHandler(inParams) {
|
|
601
631
|
return {
|
|
@@ -617,10 +647,10 @@ MemoryBlockRewardService = _ts_decorate7([
|
|
|
617
647
|
], MemoryBlockRewardService);
|
|
618
648
|
|
|
619
649
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
620
|
-
import { assertEx as
|
|
621
|
-
import { isDefined as
|
|
622
|
-
import { PayloadBuilder as
|
|
623
|
-
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
650
|
+
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
651
|
+
import { isDefined as isDefined3, isNull, isUndefined } from "@xylabs/typeof";
|
|
652
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
653
|
+
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, isBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
624
654
|
import { LRUCache } from "lru-cache";
|
|
625
655
|
var ChainBlockNumberIterationService = class extends BaseService {
|
|
626
656
|
static {
|
|
@@ -631,21 +661,21 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
631
661
|
});
|
|
632
662
|
_currentHead;
|
|
633
663
|
get chainId() {
|
|
634
|
-
return
|
|
664
|
+
return assertEx6(this._currentHead?.chain ?? this.params?.head?.chain, () => "Current head is not set");
|
|
635
665
|
}
|
|
636
666
|
get chainMap() {
|
|
637
|
-
return
|
|
667
|
+
return assertEx6(this.params.chainMap);
|
|
638
668
|
}
|
|
639
669
|
async get(block) {
|
|
640
670
|
const head = await this.head();
|
|
641
|
-
|
|
671
|
+
assertEx6(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
|
|
642
672
|
const cached = this._blocksByBlockNumber.get(block);
|
|
643
673
|
if (cached) return cached;
|
|
644
674
|
const startingBlock = head;
|
|
645
|
-
const currentBlockHash = await
|
|
675
|
+
const currentBlockHash = await PayloadBuilder4.hash(startingBlock);
|
|
646
676
|
let currentBlock = await this.chainMap.get(currentBlockHash);
|
|
647
|
-
while (
|
|
648
|
-
|
|
677
|
+
while (isDefined3(currentBlock)) {
|
|
678
|
+
assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
|
|
649
679
|
if (isBlockBoundWitnessWithHashMeta(currentBlock)) {
|
|
650
680
|
this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
|
|
651
681
|
if (currentBlock.block === block) {
|
|
@@ -659,8 +689,8 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
659
689
|
throw new Error(`Block not found: ${block}`);
|
|
660
690
|
}
|
|
661
691
|
async head() {
|
|
662
|
-
if (
|
|
663
|
-
if (
|
|
692
|
+
if (isDefined3(this._currentHead)) return this._currentHead;
|
|
693
|
+
if (isDefined3(this.params.head)) {
|
|
664
694
|
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head);
|
|
665
695
|
this._currentHead = newHead;
|
|
666
696
|
return newHead;
|
|
@@ -676,17 +706,17 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
676
706
|
// and then communicate via method name and documentation
|
|
677
707
|
async previous(block = void 0, count = 1) {
|
|
678
708
|
const results = [];
|
|
679
|
-
let currentBlock =
|
|
680
|
-
while (
|
|
709
|
+
let currentBlock = isDefined3(block) ? await this.get(block) : await this.head();
|
|
710
|
+
while (isDefined3(currentBlock) && results.length < count) {
|
|
681
711
|
if (isBlockBoundWitnessWithHashMeta(currentBlock)) {
|
|
682
712
|
results.push(currentBlock);
|
|
683
713
|
const { previous } = currentBlock;
|
|
684
714
|
if (isNull(previous)) break;
|
|
685
715
|
const nextBlock = await this.chainMap.get(previous);
|
|
686
|
-
currentBlock =
|
|
716
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta2(nextBlock);
|
|
687
717
|
} else {
|
|
688
|
-
const hash =
|
|
689
|
-
|
|
718
|
+
const hash = PayloadBuilder4.hash(currentBlock);
|
|
719
|
+
assertEx6(asBlockBoundWitnessWithStorageMeta2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
|
|
690
720
|
}
|
|
691
721
|
}
|
|
692
722
|
return results;
|
|
@@ -701,16 +731,16 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
701
731
|
});
|
|
702
732
|
}
|
|
703
733
|
async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head) {
|
|
704
|
-
const hash = await
|
|
734
|
+
const hash = await PayloadBuilder4.hash(head);
|
|
705
735
|
const stored = await this.chainMap.get(hash);
|
|
706
|
-
const newHead =
|
|
736
|
+
const newHead = asBlockBoundWitnessWithStorageMeta2(stored);
|
|
707
737
|
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`);
|
|
708
738
|
return newHead;
|
|
709
739
|
}
|
|
710
740
|
};
|
|
711
741
|
|
|
712
742
|
// src/ChainService/Evm/Evm.ts
|
|
713
|
-
import { assertEx as
|
|
743
|
+
import { assertEx as assertEx7 } from "@xylabs/assert";
|
|
714
744
|
import { toAddress, toEthAddress as toEthAddress2 } from "@xylabs/hex";
|
|
715
745
|
import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
|
|
716
746
|
import { getAddress } from "ethers/address";
|
|
@@ -719,16 +749,16 @@ var EvmChainService = class extends BaseService {
|
|
|
719
749
|
__name(this, "EvmChainService");
|
|
720
750
|
}
|
|
721
751
|
get chainId() {
|
|
722
|
-
return
|
|
752
|
+
return assertEx7(this.params.id);
|
|
723
753
|
}
|
|
724
754
|
get contract() {
|
|
725
755
|
if (this.params.contract === void 0) {
|
|
726
756
|
this.params.contract = StakedXyoChainFactory.connect(toEthAddress2(this.chainId), this.params.runner);
|
|
727
757
|
}
|
|
728
|
-
return
|
|
758
|
+
return assertEx7(this.params.contract);
|
|
729
759
|
}
|
|
730
760
|
get runner() {
|
|
731
|
-
return
|
|
761
|
+
return assertEx7(this.params.runner);
|
|
732
762
|
}
|
|
733
763
|
async active() {
|
|
734
764
|
return await this.contract.active();
|
|
@@ -851,7 +881,7 @@ var MemoryChainService = class extends BaseService {
|
|
|
851
881
|
};
|
|
852
882
|
|
|
853
883
|
// src/ChainValidator/XyoValidator.ts
|
|
854
|
-
import { assertEx as
|
|
884
|
+
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
855
885
|
import { creatable as creatable8 } from "@xylabs/creatable";
|
|
856
886
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
857
887
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -868,22 +898,22 @@ var XyoValidator = class extends BaseService {
|
|
|
868
898
|
return this.account.address;
|
|
869
899
|
}
|
|
870
900
|
get account() {
|
|
871
|
-
return
|
|
901
|
+
return assertEx8(this.params.account, () => "account is required");
|
|
872
902
|
}
|
|
873
903
|
get chainArchivist() {
|
|
874
|
-
return
|
|
904
|
+
return assertEx8(this.params.chainArchivist, () => "chainArchivist is required");
|
|
875
905
|
}
|
|
876
906
|
get chainInfo() {
|
|
877
|
-
return
|
|
907
|
+
return assertEx8(this.params.chainId, () => "chainInfo is required");
|
|
878
908
|
}
|
|
879
909
|
get electionService() {
|
|
880
|
-
return
|
|
910
|
+
return assertEx8(this.params.electionService, () => "electionService is required");
|
|
881
911
|
}
|
|
882
912
|
get pendingBundledTransactionsArchivist() {
|
|
883
|
-
return
|
|
913
|
+
return assertEx8(this.params.pendingBundledTransactionsArchivist, () => "pendingBundledTransactions is required");
|
|
884
914
|
}
|
|
885
915
|
get rewardService() {
|
|
886
|
-
return
|
|
916
|
+
return assertEx8(this.params.rewardService, () => "rewardService is required");
|
|
887
917
|
}
|
|
888
918
|
validatePendingBlock(_block) {
|
|
889
919
|
return [];
|
|
@@ -902,7 +932,7 @@ XyoValidator = _ts_decorate8([
|
|
|
902
932
|
], XyoValidator);
|
|
903
933
|
|
|
904
934
|
// src/Election/BaseElectionService.ts
|
|
905
|
-
import { assertEx as
|
|
935
|
+
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
906
936
|
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
907
937
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
908
938
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
@@ -917,13 +947,13 @@ var BaseElectionService = class extends BaseService {
|
|
|
917
947
|
__name(this, "BaseElectionService");
|
|
918
948
|
}
|
|
919
949
|
get chainIterator() {
|
|
920
|
-
return
|
|
950
|
+
return assertEx9(this.params.chainIterator, () => "No chain iterator");
|
|
921
951
|
}
|
|
922
952
|
get chainStakeViewer() {
|
|
923
|
-
return
|
|
953
|
+
return assertEx9(this.params.chainStakeViewer, () => "No chain stake viewer");
|
|
924
954
|
}
|
|
925
955
|
get stakeIntentService() {
|
|
926
|
-
return
|
|
956
|
+
return assertEx9(this.params.stakeIntentService, () => "No staked intent service");
|
|
927
957
|
}
|
|
928
958
|
async getCreatorCommitteeForNextBlock(current) {
|
|
929
959
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
@@ -1019,22 +1049,22 @@ BaseNetworkStakeStepRewardService = _ts_decorate10([
|
|
|
1019
1049
|
// src/PendingTransactions/BasePendingTransactions.ts
|
|
1020
1050
|
import { ValueType } from "@opentelemetry/api";
|
|
1021
1051
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
1022
|
-
import { assertEx as
|
|
1052
|
+
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
1023
1053
|
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1024
1054
|
import { exists as exists2 } from "@xylabs/exists";
|
|
1025
1055
|
import { forget } from "@xylabs/forget";
|
|
1026
|
-
import { isDefined as
|
|
1056
|
+
import { isDefined as isDefined4, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1027
1057
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
1028
|
-
import { findMostRecentBlock as
|
|
1058
|
+
import { findMostRecentBlock as findMostRecentBlock2 } from "@xyo-network/chain-protocol";
|
|
1029
1059
|
import { asBlockBoundWitnessWithHashMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1030
1060
|
import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-network/xl1-validation";
|
|
1031
1061
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
1032
1062
|
|
|
1033
1063
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
1034
|
-
import { PayloadBuilder as
|
|
1064
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1035
1065
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1036
1066
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
1037
|
-
const withStorageMeta = await
|
|
1067
|
+
const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
|
|
1038
1068
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
1039
1069
|
if (tx) {
|
|
1040
1070
|
return [
|
|
@@ -1045,7 +1075,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
1045
1075
|
}, "bundledPayloadToHydratedTransaction");
|
|
1046
1076
|
|
|
1047
1077
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
1048
|
-
import { PayloadBuilder as
|
|
1078
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1049
1079
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1050
1080
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1051
1081
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -1053,8 +1083,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
1053
1083
|
return bundle(root, transaction);
|
|
1054
1084
|
}, "hydratedTransactionToPayloadBundle");
|
|
1055
1085
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
1056
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
1057
|
-
return new
|
|
1086
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
|
|
1087
|
+
return new PayloadBuilder6({
|
|
1058
1088
|
schema: PayloadBundleSchema
|
|
1059
1089
|
}).fields({
|
|
1060
1090
|
payloads,
|
|
@@ -1117,23 +1147,23 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1117
1147
|
return this.params.additionalPendingTransactionValidators ?? [];
|
|
1118
1148
|
}
|
|
1119
1149
|
get chainArchivist() {
|
|
1120
|
-
return
|
|
1150
|
+
return assertEx10(this.params.chainArchivist, () => "No completed blocks with data archivist");
|
|
1121
1151
|
}
|
|
1122
1152
|
get chainId() {
|
|
1123
|
-
return
|
|
1153
|
+
return assertEx10(this.params.chainId, () => "No chain id");
|
|
1124
1154
|
}
|
|
1125
1155
|
get pendingBundledTransactionsArchivist() {
|
|
1126
|
-
return
|
|
1156
|
+
return assertEx10(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
|
|
1127
1157
|
}
|
|
1128
1158
|
get pendingBundledTransactionsLocalArchivist() {
|
|
1129
|
-
return
|
|
1159
|
+
return assertEx10(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
|
|
1130
1160
|
}
|
|
1131
1161
|
get pendingTransactionsCount() {
|
|
1132
1162
|
forget(this.countPendingTransactions());
|
|
1133
1163
|
return this._pendingTransactionsCount;
|
|
1134
1164
|
}
|
|
1135
1165
|
get rejectedTransactionsArchivist() {
|
|
1136
|
-
return
|
|
1166
|
+
return assertEx10(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
|
|
1137
1167
|
}
|
|
1138
1168
|
async createHandler() {
|
|
1139
1169
|
await super.createHandler();
|
|
@@ -1202,8 +1232,8 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1202
1232
|
}
|
|
1203
1233
|
async cleanupWorker() {
|
|
1204
1234
|
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
1205
|
-
const lastHead = await
|
|
1206
|
-
if (
|
|
1235
|
+
const lastHead = await findMostRecentBlock2(this.chainArchivist);
|
|
1236
|
+
if (isDefined4(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
1207
1237
|
}, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
|
|
1208
1238
|
}
|
|
1209
1239
|
async countPendingTransactions() {
|
|
@@ -1265,7 +1295,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1265
1295
|
let [lastHead] = filterAs(await this.chainArchivist.get([
|
|
1266
1296
|
head
|
|
1267
1297
|
]), asBlockBoundWitnessWithHashMeta);
|
|
1268
|
-
while (
|
|
1298
|
+
while (isDefined4(lastHead)) {
|
|
1269
1299
|
const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
|
|
1270
1300
|
limit: 100,
|
|
1271
1301
|
order: "asc",
|
|
@@ -1334,15 +1364,15 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
|
|
|
1334
1364
|
|
|
1335
1365
|
// src/StakeIntent/XyoStakeIntentService.ts
|
|
1336
1366
|
import { filterAs as filterAs3 } from "@xylabs/array";
|
|
1337
|
-
import { assertEx as
|
|
1367
|
+
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1338
1368
|
import { creatable as creatable12 } from "@xylabs/creatable";
|
|
1339
1369
|
import { asAddress } from "@xylabs/hex";
|
|
1340
1370
|
import { isUndefined as isUndefined3 } from "@xylabs/typeof";
|
|
1341
1371
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1342
1372
|
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
1343
|
-
import { PayloadBuilder as
|
|
1344
|
-
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as
|
|
1345
|
-
import { asChainIndexingServiceStateWithStorageMeta, ChainIndexingServiceStateSchema, isChainIndexingServiceState, readPayloadMapFromStore as
|
|
1373
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1374
|
+
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asChainStakeIntent as asChainStakeIntent2 } from "@xyo-network/xl1-protocol";
|
|
1375
|
+
import { asChainIndexingServiceStateWithStorageMeta, ChainIndexingServiceStateSchema, isChainIndexingServiceState, readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
1346
1376
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1347
1377
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
1348
1378
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
@@ -1374,16 +1404,16 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1374
1404
|
});
|
|
1375
1405
|
_updateMutex = new Mutex3();
|
|
1376
1406
|
get chainArchivist() {
|
|
1377
|
-
return
|
|
1407
|
+
return assertEx11(this.params.chainArchivist, () => "chainArchivist not set");
|
|
1378
1408
|
}
|
|
1379
1409
|
get chainIterator() {
|
|
1380
|
-
return
|
|
1410
|
+
return assertEx11(this.params.chainIterator, () => "chainIterator not set");
|
|
1381
1411
|
}
|
|
1382
1412
|
get chainStakeViewer() {
|
|
1383
|
-
return
|
|
1413
|
+
return assertEx11(this.params.chainStakeViewer, () => "chainStakeViewer not set");
|
|
1384
1414
|
}
|
|
1385
1415
|
get stakeIntentStateArchivist() {
|
|
1386
|
-
return
|
|
1416
|
+
return assertEx11(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
|
|
1387
1417
|
}
|
|
1388
1418
|
async createHandler() {
|
|
1389
1419
|
this.chainIterator.on("headUpdated", async () => {
|
|
@@ -1391,18 +1421,18 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1391
1421
|
});
|
|
1392
1422
|
const head = await this.chainIterator.head();
|
|
1393
1423
|
if (isUndefined3(head)) return;
|
|
1394
|
-
const headHash = await
|
|
1424
|
+
const headHash = await PayloadBuilder7.hash(head);
|
|
1395
1425
|
await this.recoverState(headHash);
|
|
1396
1426
|
}
|
|
1397
1427
|
async getDeclaredCandidateRanges(address, intent) {
|
|
1398
1428
|
await Promise.resolve();
|
|
1399
|
-
|
|
1429
|
+
assertEx11(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
1400
1430
|
const results = this._producers.get(address);
|
|
1401
1431
|
return results ?? [];
|
|
1402
1432
|
}
|
|
1403
1433
|
async getDeclaredCandidatesForBlock(block, intent) {
|
|
1404
1434
|
return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
|
|
1405
|
-
|
|
1435
|
+
assertEx11(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
1406
1436
|
const results = this._producers.findAllContaining(block);
|
|
1407
1437
|
const candidates = [
|
|
1408
1438
|
...results
|
|
@@ -1456,7 +1486,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1456
1486
|
}
|
|
1457
1487
|
async persistState(current) {
|
|
1458
1488
|
const state = this._producers.serialize();
|
|
1459
|
-
const payload = new
|
|
1489
|
+
const payload = new PayloadBuilder7({
|
|
1460
1490
|
schema: ChainIndexingServiceStateSchema
|
|
1461
1491
|
}).fields({
|
|
1462
1492
|
endBlockHash: current,
|
|
@@ -1467,7 +1497,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1467
1497
|
]);
|
|
1468
1498
|
}
|
|
1469
1499
|
async recoverState(current) {
|
|
1470
|
-
const currentBlock =
|
|
1500
|
+
const currentBlock = assertEx11(asBlockBoundWitness3((await this.chainArchivist.get([
|
|
1471
1501
|
current
|
|
1472
1502
|
]))?.[0]), () => `Block ${current} not found`);
|
|
1473
1503
|
const currentBlockNum = currentBlock.block;
|
|
@@ -1484,7 +1514,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1484
1514
|
const indexed = (await this.chainArchivist.get([
|
|
1485
1515
|
state.endBlockHash
|
|
1486
1516
|
]))?.[0];
|
|
1487
|
-
const indexedBlock =
|
|
1517
|
+
const indexedBlock = asBlockBoundWitnessWithStorageMeta3(indexed);
|
|
1488
1518
|
if (indexedBlock) {
|
|
1489
1519
|
const indexedBlockNum = indexedBlock.block;
|
|
1490
1520
|
if (indexedBlockNum <= currentBlockNum) {
|
|
@@ -1508,8 +1538,8 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1508
1538
|
return await this.spanAsync("updateIndex", async () => {
|
|
1509
1539
|
const currentHead = await this.chainIterator.head();
|
|
1510
1540
|
if (isUndefined3(currentHead)) return;
|
|
1511
|
-
const currentHeadHash = await
|
|
1512
|
-
const chainMap =
|
|
1541
|
+
const currentHeadHash = await PayloadBuilder7.hash(currentHead);
|
|
1542
|
+
const chainMap = readPayloadMapFromStore2(this.chainArchivist);
|
|
1513
1543
|
const result = await analyzeChain({
|
|
1514
1544
|
chainMap
|
|
1515
1545
|
}, [
|
|
@@ -1562,11 +1592,8 @@ BaseStepStakeService = _ts_decorate13([
|
|
|
1562
1592
|
], BaseStepStakeService);
|
|
1563
1593
|
|
|
1564
1594
|
// src/Time/BaseTimeSyncService.ts
|
|
1565
|
-
import { assertEx as assertEx13 } from "@xylabs/assert";
|
|
1566
1595
|
import { creatable as creatable14 } from "@xylabs/creatable";
|
|
1567
|
-
import {
|
|
1568
|
-
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1569
|
-
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1596
|
+
import { SimpleTimeSyncViewer } from "@xyo-network/xl1-protocol-sdk";
|
|
1570
1597
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
1571
1598
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1572
1599
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1578,6 +1605,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1578
1605
|
static {
|
|
1579
1606
|
__name(this, "BaseTimeSyncService");
|
|
1580
1607
|
}
|
|
1608
|
+
timeSyncViewer;
|
|
1581
1609
|
get chainArchivist() {
|
|
1582
1610
|
return this.params.chainArchivist;
|
|
1583
1611
|
}
|
|
@@ -1588,93 +1616,21 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1588
1616
|
return this.params.ethProvider;
|
|
1589
1617
|
}
|
|
1590
1618
|
async convertTime(fromDomain, toDomain, from) {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
hash
|
|
1598
|
-
]);
|
|
1599
|
-
const timePayload = asTimePayload(payload);
|
|
1600
|
-
if (timePayload === void 0) return 0;
|
|
1601
|
-
switch (toDomain) {
|
|
1602
|
-
case "xl1": {
|
|
1603
|
-
return timePayload.xl1 ?? 0;
|
|
1604
|
-
}
|
|
1605
|
-
case "epoch": {
|
|
1606
|
-
return timePayload.epoch ?? 0;
|
|
1607
|
-
}
|
|
1608
|
-
case "ethereum": {
|
|
1609
|
-
return timePayload.ethereum ?? 0;
|
|
1610
|
-
}
|
|
1611
|
-
default: {
|
|
1612
|
-
throw new Error(`Unsupported to toDomain: ${toDomain}`);
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
default: {
|
|
1617
|
-
throw new Error(`Unsupported from fromDomain: ${fromDomain}`);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1619
|
+
return await this.timeSyncViewer.convertTime(fromDomain, toDomain, from);
|
|
1620
|
+
}
|
|
1621
|
+
async createHandler() {
|
|
1622
|
+
await super.createHandler();
|
|
1623
|
+
const blockViewer = blockViewerFromChainIteratorAndArchivist(this.chainIterator, this.chainArchivist);
|
|
1624
|
+
this.timeSyncViewer = new SimpleTimeSyncViewer(blockViewer, this.ethProvider);
|
|
1620
1625
|
}
|
|
1621
1626
|
async currentTime(domain) {
|
|
1622
|
-
|
|
1623
|
-
case "xl1": {
|
|
1624
|
-
return [
|
|
1625
|
-
"xl1",
|
|
1626
|
-
(await this.chainIterator.head()).block
|
|
1627
|
-
];
|
|
1628
|
-
}
|
|
1629
|
-
case "epoch": {
|
|
1630
|
-
return [
|
|
1631
|
-
"epoch",
|
|
1632
|
-
Date.now()
|
|
1633
|
-
];
|
|
1634
|
-
}
|
|
1635
|
-
case "ethereum": {
|
|
1636
|
-
return [
|
|
1637
|
-
"ethereum",
|
|
1638
|
-
await this.ethProvider?.getBlockNumber() ?? 0
|
|
1639
|
-
];
|
|
1640
|
-
}
|
|
1641
|
-
default: {
|
|
1642
|
-
throw new Error(`Unknown time domain: ${domain}`);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1627
|
+
return await this.timeSyncViewer.currentTime(domain);
|
|
1645
1628
|
}
|
|
1646
1629
|
async currentTimeAndHash(domain) {
|
|
1647
|
-
|
|
1648
|
-
case "xl1": {
|
|
1649
|
-
const head = await this.chainIterator.head();
|
|
1650
|
-
return [
|
|
1651
|
-
head.block,
|
|
1652
|
-
await PayloadBuilder7.hash(head)
|
|
1653
|
-
];
|
|
1654
|
-
}
|
|
1655
|
-
case "epoch": {
|
|
1656
|
-
return [
|
|
1657
|
-
Date.now(),
|
|
1658
|
-
null
|
|
1659
|
-
];
|
|
1660
|
-
}
|
|
1661
|
-
case "ethereum": {
|
|
1662
|
-
const provider = assertEx13(this.ethProvider, () => "Ethereum provider not configured");
|
|
1663
|
-
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
1664
|
-
const block = await provider.getBlock(blockNumber);
|
|
1665
|
-
const blockHash = asHash(assertEx13(block?.hash, () => "Block hash not found"), true);
|
|
1666
|
-
return [
|
|
1667
|
-
blockNumber,
|
|
1668
|
-
blockHash
|
|
1669
|
-
];
|
|
1670
|
-
}
|
|
1671
|
-
default: {
|
|
1672
|
-
throw new Error(`Unknown time domain: ${domain}`);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1630
|
+
return await this.timeSyncViewer.currentTimeAndHash(domain);
|
|
1675
1631
|
}
|
|
1676
|
-
currentTimePayload() {
|
|
1677
|
-
|
|
1632
|
+
async currentTimePayload() {
|
|
1633
|
+
return await this.timeSyncViewer.currentTimePayload();
|
|
1678
1634
|
}
|
|
1679
1635
|
};
|
|
1680
1636
|
BaseTimeSyncService = _ts_decorate14([
|
|
@@ -1703,7 +1659,6 @@ export {
|
|
|
1703
1659
|
XyoStakeIntentService,
|
|
1704
1660
|
XyoValidator,
|
|
1705
1661
|
accountBalancesServiceFromArchivist,
|
|
1706
|
-
accountTransfersServiceFromArchivist,
|
|
1707
1662
|
creatableService,
|
|
1708
1663
|
getBlockSignedStakeDeclarations
|
|
1709
1664
|
};
|