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