@xyo-network/chain-services 1.14.1 → 1.14.3
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.map +1 -1
- package/dist/neutral/BaseService.d.ts +5 -3
- package/dist/neutral/BaseService.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +5 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/BlockReward/spec/MemoryBlockRewardService.spec.d.ts +2 -0
- package/dist/neutral/BlockReward/spec/MemoryBlockRewardService.spec.d.ts.map +1 -0
- package/dist/neutral/Bridge/BaseBridgeService.d.ts +15 -0
- package/dist/neutral/Bridge/BaseBridgeService.d.ts.map +1 -0
- package/dist/neutral/Bridge/index.d.ts +2 -0
- package/dist/neutral/Bridge/index.d.ts.map +1 -0
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +14 -0
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -0
- package/dist/neutral/StepStake/index.d.ts +2 -0
- package/dist/neutral/StepStake/index.d.ts.map +1 -0
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +22 -0
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +1 -0
- package/dist/neutral/Time/index.d.ts +2 -0
- package/dist/neutral/Time/index.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +3 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +232 -58
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +24 -24
- package/src/AccountBalance/BaseAccountBalanceService.ts +11 -8
- package/src/BaseService.ts +11 -6
- package/src/BlockProducer/BaseBlockProducerService.ts +63 -23
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +5 -0
- package/src/BlockReward/spec/MemoryBlockRewardService.spec.ts +64 -0
- package/src/Bridge/BaseBridgeService.ts +35 -0
- package/src/Bridge/index.ts +1 -0
- package/src/StepStake/BaseStepStakeService.ts +26 -0
- package/src/StepStake/index.ts +1 -0
- package/src/Time/BaseTimeSyncService.ts +79 -0
- package/src/Time/index.ts +1 -0
- package/src/index.ts +3 -0
package/dist/neutral/index.mjs
CHANGED
|
@@ -9,12 +9,13 @@ import { LRUCache } from "lru-cache";
|
|
|
9
9
|
|
|
10
10
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
11
11
|
import { creatable as creatable2 } from "@xylabs/creatable";
|
|
12
|
+
import { spanRootAsync as spanRootAsync2 } from "@xylabs/telemetry";
|
|
12
13
|
import { AttoXL1 } from "@xyo-network/xl1-protocol";
|
|
13
14
|
import { balanceSummary } from "@xyo-network/xl1-protocol-sdk";
|
|
14
15
|
|
|
15
16
|
// src/BaseService.ts
|
|
16
17
|
import { AbstractCreatable, creatable } from "@xylabs/creatable";
|
|
17
|
-
import {
|
|
18
|
+
import { spanRoot, spanRootAsync } from "@xylabs/telemetry";
|
|
18
19
|
import { Mutex } from "async-mutex";
|
|
19
20
|
function _ts_decorate(decorators, target, key, desc) {
|
|
20
21
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -41,10 +42,13 @@ var BaseService = class extends AbstractCreatable {
|
|
|
41
42
|
return params;
|
|
42
43
|
}
|
|
43
44
|
span(name, fn) {
|
|
44
|
-
return
|
|
45
|
+
return spanRoot(name, fn, this.tracer);
|
|
45
46
|
}
|
|
46
47
|
async spanAsync(name, fn) {
|
|
47
|
-
return await
|
|
48
|
+
return await spanRootAsync(name, fn, this.tracer);
|
|
49
|
+
}
|
|
50
|
+
sync(_head) {
|
|
51
|
+
throw new Error("Method not implemented.");
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
54
|
BaseService = _ts_decorate([
|
|
@@ -75,17 +79,19 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
75
79
|
__name(this, "BaseAccountBalanceService");
|
|
76
80
|
}
|
|
77
81
|
async balances(head, address) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
return await spanRootAsync2("balances", async () => {
|
|
83
|
+
const summary = await balanceSummary({
|
|
84
|
+
chainArchivist: this.params.chainArchivist,
|
|
85
|
+
summaryRepository: this.params.summaryRepository,
|
|
86
|
+
head
|
|
87
|
+
});
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const addr of address) {
|
|
90
|
+
const summaryBalance = summary[addr] ?? 0n;
|
|
91
|
+
result[addr] = AttoXL1(summaryBalance < 0n ? 0n : summaryBalance);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
82
94
|
});
|
|
83
|
-
const result = {};
|
|
84
|
-
for (const addr of address) {
|
|
85
|
-
const summaryBalance = summary[addr] ?? 0n;
|
|
86
|
-
result[addr] = AttoXL1(summaryBalance < 0n ? 0n : summaryBalance);
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
95
|
}
|
|
90
96
|
};
|
|
91
97
|
BaseAccountBalanceService = _ts_decorate2([
|
|
@@ -137,7 +143,7 @@ import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
|
137
143
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
138
144
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
139
145
|
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
140
|
-
import { asBlockBoundWitness, AttoXL1 as AttoXL12, BlockNumberSchema } from "@xyo-network/xl1-protocol";
|
|
146
|
+
import { asBlockBoundWitness, AttoXL1 as AttoXL12, BlockNumberSchema, defaultRewardRatio, TimeSchema } from "@xyo-network/xl1-protocol";
|
|
141
147
|
|
|
142
148
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
143
149
|
import { assertEx } from "@xylabs/assert";
|
|
@@ -252,6 +258,9 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
252
258
|
get stakeIntentService() {
|
|
253
259
|
return assertEx2(this.params.stakeIntentService, () => "No StakeIntentService provided");
|
|
254
260
|
}
|
|
261
|
+
get time() {
|
|
262
|
+
return assertEx2(this.params.time, () => "No TimeSyncViewInterface provided");
|
|
263
|
+
}
|
|
255
264
|
get validateHydratedBlockState() {
|
|
256
265
|
return assertEx2(this.params.validateHydratedBlockState, () => "validateHydratedBlockState is required");
|
|
257
266
|
}
|
|
@@ -268,7 +277,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
268
277
|
blockRewardService: this.rewardService,
|
|
269
278
|
config: {
|
|
270
279
|
rewardAddress: this.rewardAddress,
|
|
271
|
-
rewardPercentageRatio:
|
|
280
|
+
rewardPercentageRatio: defaultRewardRatio,
|
|
272
281
|
schema: FixedPercentageBlockRewardDivinerConfigSchema
|
|
273
282
|
}
|
|
274
283
|
});
|
|
@@ -313,35 +322,21 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
313
322
|
const rewardTransferPayload = await this.getBlockRewardTransfer(nextBlock);
|
|
314
323
|
if (rewardTransferPayload) blockPayloads.push(rewardTransferPayload);
|
|
315
324
|
const transactionTransfers = await generateTransactionFeeTransfers(this.address, nextBlockTransactions);
|
|
316
|
-
const
|
|
317
|
-
const fundedNextBlockTransactions =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (validateBalances) {
|
|
322
|
-
const balance = (await this.balanceService.balances(head._hash, [
|
|
323
|
-
transfer.from
|
|
324
|
-
]))[transfer.from] ?? AttoXL12(0n);
|
|
325
|
-
if (balance >= totalTransferCost) {
|
|
326
|
-
fundedTransfers.push(transfer);
|
|
327
|
-
return tx;
|
|
328
|
-
}
|
|
329
|
-
} else {
|
|
330
|
-
fundedTransfers.push(transfer);
|
|
331
|
-
return tx;
|
|
332
|
-
}
|
|
333
|
-
}))).filter(exists2);
|
|
334
|
-
blockPayloads.push(...fundedTransfers);
|
|
335
|
-
this.logger?.info(`buildNextBlock: Building block ${head.block + 1} (${(/* @__PURE__ */ new Date()).toISOString()})`);
|
|
325
|
+
const timePayload = await this.generateTimePayload(nextBlock);
|
|
326
|
+
const [fundedNextBlockTransactions, fundedTransfers] = await this.filterByFunded(head, nextBlockTransactions, transactionTransfers, validateBalances);
|
|
327
|
+
blockPayloads.push(...fundedTransfers, timePayload);
|
|
328
|
+
this.logger?.info(`Building block ${head.block + 1}`);
|
|
329
|
+
const startBuild = Date.now();
|
|
336
330
|
const block = await buildNextBlock(head, fundedNextBlockTransactions, blockPayloads, [
|
|
337
331
|
this.account
|
|
338
332
|
]);
|
|
339
|
-
this.logger?.info(`
|
|
340
|
-
this.logger?.info(`
|
|
333
|
+
this.logger?.info(`Built block ${block[0].block} in ${Date.now() - startBuild}ms with ${block[1].length} payloads`);
|
|
334
|
+
this.logger?.info(`Validating block ${block[0].block} with ${block[1].length} payloads`);
|
|
335
|
+
const startValidate = Date.now();
|
|
341
336
|
const errors = await this.validateHydratedBlockState(block, this.chainId, {
|
|
342
337
|
accountBalance: this.balanceService
|
|
343
338
|
});
|
|
344
|
-
this.logger?.info(`
|
|
339
|
+
this.logger?.info(`Validated block ${block[0].block} in ${Date.now() - startValidate}ms with ${block[1].length} payloads`);
|
|
345
340
|
if (errors.length > 0) {
|
|
346
341
|
this.logger?.warn(`Validation of produced block failed: ${errors.at(0)?.message}`);
|
|
347
342
|
const rejectedTransactions = block[1];
|
|
@@ -351,6 +346,43 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
351
346
|
}
|
|
352
347
|
});
|
|
353
348
|
}
|
|
349
|
+
// remove unfunded transactions and block transfers
|
|
350
|
+
async filterByFunded(head, txs, transfers, validateBalances = false) {
|
|
351
|
+
const start = Date.now();
|
|
352
|
+
const fundedTransfers = [];
|
|
353
|
+
const fundedTransactions = (await Promise.all(txs.map(async (tx) => {
|
|
354
|
+
const transfer = transfers.find((transfer2) => transfer2.from === tx[0].from);
|
|
355
|
+
if (!transfer) return;
|
|
356
|
+
const totalTransferCost = Object.values(transfer?.transfers).reduce((acc, t) => acc + hexToBigInt(t ?? "00"), 0n);
|
|
357
|
+
if (validateBalances) {
|
|
358
|
+
const balance = (await this.balanceService.balances(head._hash, [
|
|
359
|
+
transfer.from
|
|
360
|
+
]))[transfer.from] ?? AttoXL12(0n);
|
|
361
|
+
if (balance >= totalTransferCost) {
|
|
362
|
+
fundedTransfers.push(transfer);
|
|
363
|
+
return tx;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
fundedTransfers.push(transfer);
|
|
367
|
+
return tx;
|
|
368
|
+
}
|
|
369
|
+
}))).filter(exists2);
|
|
370
|
+
this.logger?.info(`Filtered ${txs.length} transactions to ${fundedTransactions.length} funded transactions in ${Date.now() - start}ms`);
|
|
371
|
+
return [
|
|
372
|
+
fundedTransactions,
|
|
373
|
+
fundedTransfers
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
async generateTimePayload(nextBlock) {
|
|
377
|
+
const timePayload = {
|
|
378
|
+
schema: TimeSchema,
|
|
379
|
+
xl1: nextBlock,
|
|
380
|
+
// TODO: Change to entire tuple for time in ETH
|
|
381
|
+
ethereum: (await this.time.currentTime("ethereum"))[1],
|
|
382
|
+
epoch: Date.now()
|
|
383
|
+
};
|
|
384
|
+
return timePayload;
|
|
385
|
+
}
|
|
354
386
|
};
|
|
355
387
|
BaseBlockProducerService = _ts_decorate3([
|
|
356
388
|
creatable3()
|
|
@@ -475,6 +507,36 @@ MemoryBlockRewardService = _ts_decorate6([
|
|
|
475
507
|
creatable6()
|
|
476
508
|
], MemoryBlockRewardService);
|
|
477
509
|
|
|
510
|
+
// src/Bridge/BaseBridgeService.ts
|
|
511
|
+
import { creatable as creatable7 } from "@xylabs/creatable";
|
|
512
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
513
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
514
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
515
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
516
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
517
|
+
}
|
|
518
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
519
|
+
var BaseBridgeService = class extends BaseService {
|
|
520
|
+
static {
|
|
521
|
+
__name(this, "BaseBridgeService");
|
|
522
|
+
}
|
|
523
|
+
completedBridgeBack() {
|
|
524
|
+
throw new Error("Method not implemented.");
|
|
525
|
+
}
|
|
526
|
+
completedBridgeRequests() {
|
|
527
|
+
throw new Error("Method not implemented.");
|
|
528
|
+
}
|
|
529
|
+
pendingBridgeBack() {
|
|
530
|
+
throw new Error("Method not implemented.");
|
|
531
|
+
}
|
|
532
|
+
pendingBridgeRequests() {
|
|
533
|
+
throw new Error("Method not implemented.");
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
BaseBridgeService = _ts_decorate7([
|
|
537
|
+
creatable7()
|
|
538
|
+
], BaseBridgeService);
|
|
539
|
+
|
|
478
540
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
479
541
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
480
542
|
import { isDefined, isNull } from "@xylabs/typeof";
|
|
@@ -703,14 +765,14 @@ var MemoryChainService = class extends BaseService {
|
|
|
703
765
|
|
|
704
766
|
// src/ChainValidator/XyoValidator.ts
|
|
705
767
|
import { assertEx as assertEx7 } from "@xylabs/assert";
|
|
706
|
-
import { creatable as
|
|
707
|
-
function
|
|
768
|
+
import { creatable as creatable8 } from "@xylabs/creatable";
|
|
769
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
708
770
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
709
771
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
710
772
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
711
773
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
712
774
|
}
|
|
713
|
-
__name(
|
|
775
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
714
776
|
var XyoValidator = class extends BaseService {
|
|
715
777
|
static {
|
|
716
778
|
__name(this, "XyoValidator");
|
|
@@ -748,22 +810,22 @@ var XyoValidator = class extends BaseService {
|
|
|
748
810
|
return await Promise.resolve(true);
|
|
749
811
|
}
|
|
750
812
|
};
|
|
751
|
-
XyoValidator =
|
|
752
|
-
|
|
813
|
+
XyoValidator = _ts_decorate8([
|
|
814
|
+
creatable8()
|
|
753
815
|
], XyoValidator);
|
|
754
816
|
|
|
755
817
|
// src/Election/BaseElectionService.ts
|
|
756
818
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
757
|
-
import { creatable as
|
|
819
|
+
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
758
820
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
759
821
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
760
|
-
function
|
|
822
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
761
823
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
762
824
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
763
825
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
764
826
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
765
827
|
}
|
|
766
|
-
__name(
|
|
828
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
767
829
|
var BaseElectionService = class extends BaseService {
|
|
768
830
|
static {
|
|
769
831
|
__name(this, "BaseElectionService");
|
|
@@ -792,15 +854,15 @@ var BaseElectionService = class extends BaseService {
|
|
|
792
854
|
return creatorArray.slice(0, maxSize);
|
|
793
855
|
}
|
|
794
856
|
};
|
|
795
|
-
BaseElectionService =
|
|
796
|
-
|
|
857
|
+
BaseElectionService = _ts_decorate9([
|
|
858
|
+
creatable9()
|
|
797
859
|
], BaseElectionService);
|
|
798
860
|
|
|
799
861
|
// src/PendingTransactions/BasePendingTransactions.ts
|
|
800
862
|
import { ValueType } from "@opentelemetry/api";
|
|
801
863
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
802
864
|
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
803
|
-
import { creatable as
|
|
865
|
+
import { creatable as creatable10 } from "@xylabs/creatable";
|
|
804
866
|
import { exists as exists3 } from "@xylabs/exists";
|
|
805
867
|
import { forget } from "@xylabs/forget";
|
|
806
868
|
import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
|
|
@@ -843,13 +905,13 @@ var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
|
843
905
|
}, "bundle");
|
|
844
906
|
|
|
845
907
|
// src/PendingTransactions/BasePendingTransactions.ts
|
|
846
|
-
function
|
|
908
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
847
909
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
848
910
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
849
911
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
850
912
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
851
913
|
}
|
|
852
|
-
__name(
|
|
914
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
853
915
|
var BasePendingTransactionsService = class _BasePendingTransactionsService extends BaseService {
|
|
854
916
|
static {
|
|
855
917
|
__name(this, "BasePendingTransactionsService");
|
|
@@ -1067,8 +1129,8 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1067
1129
|
});
|
|
1068
1130
|
}
|
|
1069
1131
|
};
|
|
1070
|
-
BasePendingTransactionsService =
|
|
1071
|
-
|
|
1132
|
+
BasePendingTransactionsService = _ts_decorate10([
|
|
1133
|
+
creatable10()
|
|
1072
1134
|
], BasePendingTransactionsService);
|
|
1073
1135
|
var isTransactionExpired = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.exp < block, "isTransactionExpired");
|
|
1074
1136
|
var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf <= block && txBw.exp >= block, "isTransactionActive");
|
|
@@ -1103,7 +1165,7 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
|
|
|
1103
1165
|
// src/StakeIntent/XyoStakeIntentService.ts
|
|
1104
1166
|
import { filterAs as filterAs3 } from "@xylabs/array";
|
|
1105
1167
|
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
1106
|
-
import { creatable as
|
|
1168
|
+
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1107
1169
|
import { asAddress } from "@xylabs/hex";
|
|
1108
1170
|
import { isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1109
1171
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
@@ -1112,13 +1174,13 @@ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder"
|
|
|
1112
1174
|
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1113
1175
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1114
1176
|
import { LRUCache as LRUCache3 } from "lru-cache";
|
|
1115
|
-
function
|
|
1177
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1116
1178
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1117
1179
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1118
1180
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1119
1181
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1120
1182
|
}
|
|
1121
|
-
__name(
|
|
1183
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1122
1184
|
var ACTIVE_STAKE_TTL = 1e3 * 60 * 60 * 2;
|
|
1123
1185
|
var NO_ACTIVE_STAKE_TTL = 1e3 * 2;
|
|
1124
1186
|
var STAKE_CACHE_MAX_ENTRIES = 1e4;
|
|
@@ -1297,17 +1359,129 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1297
1359
|
});
|
|
1298
1360
|
}
|
|
1299
1361
|
};
|
|
1300
|
-
XyoStakeIntentService =
|
|
1301
|
-
|
|
1362
|
+
XyoStakeIntentService = _ts_decorate11([
|
|
1363
|
+
creatable11()
|
|
1302
1364
|
], XyoStakeIntentService);
|
|
1365
|
+
|
|
1366
|
+
// src/StepStake/BaseStepStakeService.ts
|
|
1367
|
+
import { creatable as creatable12 } from "@xylabs/creatable";
|
|
1368
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
1369
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1370
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1371
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1372
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1373
|
+
}
|
|
1374
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1375
|
+
var BaseStepStakeService = class extends BaseService {
|
|
1376
|
+
static {
|
|
1377
|
+
__name(this, "BaseStepStakeService");
|
|
1378
|
+
}
|
|
1379
|
+
stepStake(_step) {
|
|
1380
|
+
throw new Error("Method not implemented.");
|
|
1381
|
+
}
|
|
1382
|
+
stepStakeForAddress(_address, _step) {
|
|
1383
|
+
throw new Error("Method not implemented.");
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
BaseStepStakeService = _ts_decorate12([
|
|
1387
|
+
creatable12()
|
|
1388
|
+
], BaseStepStakeService);
|
|
1389
|
+
|
|
1390
|
+
// src/Time/BaseTimeSyncService.ts
|
|
1391
|
+
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1392
|
+
import { creatable as creatable13 } from "@xylabs/creatable";
|
|
1393
|
+
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1394
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
1395
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1396
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1397
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1398
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1399
|
+
}
|
|
1400
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1401
|
+
var BaseTimeSyncService = class extends BaseService {
|
|
1402
|
+
static {
|
|
1403
|
+
__name(this, "BaseTimeSyncService");
|
|
1404
|
+
}
|
|
1405
|
+
get chainArchivist() {
|
|
1406
|
+
return this.params.chainArchivist;
|
|
1407
|
+
}
|
|
1408
|
+
get chainIterator() {
|
|
1409
|
+
return this.params.chainIterator;
|
|
1410
|
+
}
|
|
1411
|
+
get ethProvider() {
|
|
1412
|
+
return this.params.ethProvider;
|
|
1413
|
+
}
|
|
1414
|
+
async convertTime(fromDomain, toDomain, from) {
|
|
1415
|
+
switch (fromDomain) {
|
|
1416
|
+
case "xl1": {
|
|
1417
|
+
const block = assertEx11(await this.chainIterator.get(from), () => "Block not found");
|
|
1418
|
+
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema2);
|
|
1419
|
+
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
1420
|
+
const [payload] = hash === void 0 ? [] : await this.chainArchivist.get([
|
|
1421
|
+
hash
|
|
1422
|
+
]);
|
|
1423
|
+
const timePayload = asTimePayload(payload);
|
|
1424
|
+
if (timePayload === void 0) return 0;
|
|
1425
|
+
switch (toDomain) {
|
|
1426
|
+
case "xl1": {
|
|
1427
|
+
return timePayload.xl1 ?? 0;
|
|
1428
|
+
}
|
|
1429
|
+
case "epoch": {
|
|
1430
|
+
return timePayload.epoch ?? 0;
|
|
1431
|
+
}
|
|
1432
|
+
case "ethereum": {
|
|
1433
|
+
return timePayload.ethereum ?? 0;
|
|
1434
|
+
}
|
|
1435
|
+
default: {
|
|
1436
|
+
throw new Error(`Unsupported to toDomain: ${toDomain}`);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
default: {
|
|
1441
|
+
throw new Error(`Unsupported from fromDomain: ${fromDomain}`);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
async currentTime(domain) {
|
|
1446
|
+
switch (domain) {
|
|
1447
|
+
case "xl1": {
|
|
1448
|
+
return [
|
|
1449
|
+
"xl1",
|
|
1450
|
+
(await this.chainIterator.head()).block
|
|
1451
|
+
];
|
|
1452
|
+
}
|
|
1453
|
+
case "epoch": {
|
|
1454
|
+
return [
|
|
1455
|
+
"epoch",
|
|
1456
|
+
Date.now()
|
|
1457
|
+
];
|
|
1458
|
+
}
|
|
1459
|
+
case "ethereum": {
|
|
1460
|
+
return [
|
|
1461
|
+
"ethereum",
|
|
1462
|
+
await this.ethProvider?.getBlockNumber() ?? 0
|
|
1463
|
+
];
|
|
1464
|
+
}
|
|
1465
|
+
default: {
|
|
1466
|
+
throw new Error(`Unknown time domain: ${domain}`);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
BaseTimeSyncService = _ts_decorate13([
|
|
1472
|
+
creatable13()
|
|
1473
|
+
], BaseTimeSyncService);
|
|
1303
1474
|
export {
|
|
1304
1475
|
BaseAccountBalanceService,
|
|
1305
1476
|
BaseAccountableService,
|
|
1306
1477
|
BaseBlockProducerService,
|
|
1307
1478
|
BaseBlockRewardService,
|
|
1479
|
+
BaseBridgeService,
|
|
1308
1480
|
BaseElectionService,
|
|
1309
1481
|
BasePendingTransactionsService,
|
|
1310
1482
|
BaseService,
|
|
1483
|
+
BaseStepStakeService,
|
|
1484
|
+
BaseTimeSyncService,
|
|
1311
1485
|
ChainBlockNumberIterationService,
|
|
1312
1486
|
DEFAULT_BLOCK_SIZE,
|
|
1313
1487
|
EvmBlockRewardService,
|