@xyo-network/chain-services 1.16.9 → 1.16.11
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 +15 -5
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.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 -3
- 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/generateTransactionFeeTransfers.d.ts +1 -1
- package/dist/neutral/BlockProducer/generateTransactionFeeTransfers.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
- package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts +1 -2
- package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts.map +1 -1
- package/dist/neutral/BlockReward/MemoryBlockRewardService.d.ts +1 -1
- package/dist/neutral/BlockReward/MemoryBlockRewardService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts +1 -1
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +4 -9
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/model/Validator.d.ts +1 -1
- package/dist/neutral/ChainValidator/model/Validator.d.ts.map +1 -1
- package/dist/neutral/Election/BaseElectionService.d.ts +1 -1
- package/dist/neutral/Election/BaseElectionService.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +1 -2
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +2 -4
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/lib/getBlockSignedStakeDeclarations.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +1 -2
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +8 -11
- 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 +194 -261
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Params.d.ts +1 -2
- package/dist/neutral/model/Params.d.ts.map +1 -1
- package/package.json +26 -36
- package/src/AccountBalance/BaseAccountBalanceService.ts +34 -7
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +2 -2
- package/src/AccountTransfers/BaseAccountTransfersService.ts +3 -2
- package/src/AccountTransfers/index.ts +0 -1
- package/src/BaseService.ts +2 -3
- package/src/BlockProducer/BaseBlockProducerService.ts +8 -7
- package/src/BlockProducer/generateTransactionFeeTransfers.ts +2 -2
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +10 -13
- package/src/BlockProducer/spec/generateTransactionTransfer.spec.ts +5 -5
- package/src/BlockReward/BaseBlockRewardService.ts +3 -3
- package/src/BlockReward/EvmBlockRewardService.ts +3 -3
- package/src/BlockReward/MemoryBlockRewardService.ts +3 -4
- package/src/BlockReward/spec/MemoryBlockRewardService.spec.ts +1 -1
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +3 -3
- package/src/ChainBlockNumberIteration/model/BlockNumberIteration.ts +1 -1
- package/src/ChainService/Evm/Evm.ts +4 -3
- package/src/ChainService/Memory/Memory.ts +2 -2
- package/src/ChainValidator/XyoValidator.ts +4 -4
- package/src/ChainValidator/model/Validator.ts +1 -1
- package/src/Election/BaseElectionService.ts +3 -3
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +3 -3
- package/src/PendingTransactions/BasePendingTransactions.ts +6 -7
- package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +1 -1
- package/src/PendingTransactions/spec/BasePendingTransactions.spec.ts +4 -4
- package/src/StakeIntent/XyoStakeIntentService.ts +5 -8
- package/src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts +2 -3
- package/src/StepStake/BaseStepStakeService.ts +3 -3
- package/src/Time/BaseTimeSyncService.ts +25 -80
- package/src/blockViewerFromChainIteratorAndArchivist.ts +61 -0
- package/src/model/Params.ts +1 -2
- 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
|
@@ -2,20 +2,20 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
5
|
-
import { assertEx } from "@xylabs/
|
|
5
|
+
import { assertEx } from "@xylabs/sdk-js";
|
|
6
6
|
import { findMostRecentBlock } from "@xyo-network/chain-protocol";
|
|
7
7
|
import { StepSizes } from "@xyo-network/xl1-protocol";
|
|
8
8
|
import { LruCacheMap, readPayloadMapFromStore } from "@xyo-network/xl1-protocol-sdk";
|
|
9
9
|
import { Semaphore } from "async-mutex";
|
|
10
10
|
|
|
11
11
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
12
|
-
import { creatable as creatable2 } from "@xylabs/
|
|
12
|
+
import { creatable as creatable2 } from "@xylabs/sdk-js";
|
|
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
|
-
import { AbstractCreatable, creatable } from "@xylabs/
|
|
18
|
+
import { AbstractCreatable, creatable } from "@xylabs/sdk-js";
|
|
19
19
|
import { spanRoot, spanRootAsync } from "@xylabs/telemetry";
|
|
20
20
|
import { Mutex } from "async-mutex";
|
|
21
21
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -64,6 +64,67 @@ function creatableService() {
|
|
|
64
64
|
}
|
|
65
65
|
__name(creatableService, "creatableService");
|
|
66
66
|
|
|
67
|
+
// src/blockViewerFromChainIteratorAndArchivist.ts
|
|
68
|
+
import { isDefined } from "@xylabs/sdk-js";
|
|
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,15 +201,8 @@ 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
|
-
import { creatable as creatable3 } from "@xylabs/
|
|
205
|
+
import { creatable as creatable3 } from "@xylabs/sdk-js";
|
|
146
206
|
import { spanRootAsync as spanRootAsync3 } from "@xylabs/telemetry";
|
|
147
207
|
import { AttoXL1 as AttoXL12 } from "@xyo-network/xl1-protocol";
|
|
148
208
|
import { transfersSummary } from "@xyo-network/xl1-protocol-sdk";
|
|
@@ -178,59 +238,25 @@ 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
|
|
213
|
-
import { creatable as creatable4 } from "@xylabs/creatable";
|
|
214
|
-
import { exists } from "@xylabs/exists";
|
|
215
|
-
import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
216
|
-
import { isDefined } from "@xylabs/typeof";
|
|
242
|
+
import { asHash, assertEx as assertEx3, creatable as creatable4, exists, hexToBigInt, isDefined as isDefined2, toHex } from "@xylabs/sdk-js";
|
|
217
243
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
218
244
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
219
|
-
import { PayloadBuilder as
|
|
245
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
220
246
|
import { asBlockBoundWitness, AttoXL1 as AttoXL13, BlockNumberSchema, defaultRewardRatio, TimeSchema, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
221
247
|
|
|
222
248
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
223
|
-
import {
|
|
224
|
-
import {
|
|
225
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
249
|
+
import { hexFromBigInt } from "@xylabs/sdk-js";
|
|
250
|
+
import { assertEx as assertEx2 } from "@xylabs/sdk-js";
|
|
251
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
226
252
|
import { TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
227
253
|
import { transactionRequiredGas } from "@xyo-network/xl1-protocol-sdk";
|
|
228
254
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
229
255
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
230
256
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
231
257
|
return HydratedTransactionWrapper.parse([
|
|
232
|
-
await
|
|
233
|
-
await
|
|
258
|
+
await PayloadBuilder2.addStorageMeta(tx[0]),
|
|
259
|
+
await PayloadBuilder2.addStorageMeta(tx[1])
|
|
234
260
|
]);
|
|
235
261
|
}));
|
|
236
262
|
const txBaseFeeCosts = {};
|
|
@@ -256,7 +282,7 @@ async function generateTransactionFeeTransfers(address, transactions) {
|
|
|
256
282
|
return payload;
|
|
257
283
|
});
|
|
258
284
|
for (const [from, amount] of Object.entries(txGasCosts)) {
|
|
259
|
-
const fromPayload =
|
|
285
|
+
const fromPayload = assertEx2(payloads.find((p) => p.from === from), () => "from payload not found");
|
|
260
286
|
fromPayload.transfers[address] = hexFromBigInt(amount);
|
|
261
287
|
}
|
|
262
288
|
return payloads;
|
|
@@ -303,40 +329,40 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
303
329
|
return this.account.address;
|
|
304
330
|
}
|
|
305
331
|
get account() {
|
|
306
|
-
return
|
|
332
|
+
return assertEx3(this.params.account, () => "account is required");
|
|
307
333
|
}
|
|
308
334
|
get balanceService() {
|
|
309
|
-
return
|
|
335
|
+
return assertEx3(this.params.balanceService, () => "balanceService is required");
|
|
310
336
|
}
|
|
311
337
|
get chainArchivist() {
|
|
312
|
-
return
|
|
338
|
+
return assertEx3(this.params.chainArchivist, () => "chainArchivist is required");
|
|
313
339
|
}
|
|
314
340
|
get chainId() {
|
|
315
|
-
return
|
|
341
|
+
return assertEx3(this.params.chainId, () => "chainId is required");
|
|
316
342
|
}
|
|
317
343
|
get electionService() {
|
|
318
|
-
return
|
|
344
|
+
return assertEx3(this.params.electionService, () => "electionService is required");
|
|
319
345
|
}
|
|
320
346
|
get pendingTransactionsService() {
|
|
321
|
-
return
|
|
347
|
+
return assertEx3(this.params.pendingTransactionsService, () => "Missing pendingTransactionsService");
|
|
322
348
|
}
|
|
323
349
|
get rejectedTransactionsArchivist() {
|
|
324
|
-
return
|
|
350
|
+
return assertEx3(this.params.rejectedTransactionsArchivist, () => "No rejected bundled transactions archivist");
|
|
325
351
|
}
|
|
326
352
|
get rewardAddress() {
|
|
327
|
-
return
|
|
353
|
+
return assertEx3(this.params.rewardAddress, () => "No reward address provided");
|
|
328
354
|
}
|
|
329
355
|
get rewardService() {
|
|
330
|
-
return
|
|
356
|
+
return assertEx3(this.params.rewardService, () => "rewardService is required");
|
|
331
357
|
}
|
|
332
358
|
get stakeIntentService() {
|
|
333
|
-
return
|
|
359
|
+
return assertEx3(this.params.stakeIntentService, () => "No StakeIntentService provided");
|
|
334
360
|
}
|
|
335
361
|
get time() {
|
|
336
|
-
return
|
|
362
|
+
return assertEx3(this.params.time, () => "No TimeSyncViewer provided");
|
|
337
363
|
}
|
|
338
364
|
get validateHydratedBlockState() {
|
|
339
|
-
return
|
|
365
|
+
return assertEx3(this.params.validateHydratedBlockState, () => "validateHydratedBlockState is required");
|
|
340
366
|
}
|
|
341
367
|
async next(head) {
|
|
342
368
|
if (head.chain !== this.chainId) return;
|
|
@@ -361,8 +387,8 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
361
387
|
}
|
|
362
388
|
});
|
|
363
389
|
}
|
|
364
|
-
const blockHex =
|
|
365
|
-
const blockId = new
|
|
390
|
+
const blockHex = assertEx3(toHex(block), () => "Failed to convert block to hex");
|
|
391
|
+
const blockId = new PayloadBuilder3({
|
|
366
392
|
schema: BlockNumberSchema
|
|
367
393
|
}).fields({
|
|
368
394
|
block: blockHex
|
|
@@ -390,7 +416,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
390
416
|
}
|
|
391
417
|
async proposeNextValidBlock(head, validateBalances = false) {
|
|
392
418
|
return await this.spanAsync("proposeNextValidBlock", async () => {
|
|
393
|
-
const { block: previousBlock } =
|
|
419
|
+
const { block: previousBlock } = assertEx3(asBlockBoundWitness(head), () => "Invalid head block");
|
|
394
420
|
const nextBlock = previousBlock + 1;
|
|
395
421
|
const nextBlockTransactionsStart = Date.now();
|
|
396
422
|
const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash, _BaseBlockProducerService.DefaultBlockSize);
|
|
@@ -464,7 +490,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
464
490
|
}
|
|
465
491
|
async generateTimePayload(head) {
|
|
466
492
|
const [ethereum, ethHashOrNull] = await this.time.currentTimeAndHash("ethereum");
|
|
467
|
-
const ethereumHash =
|
|
493
|
+
const ethereumHash = asHash(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
468
494
|
const timePayload = {
|
|
469
495
|
schema: TimeSchema,
|
|
470
496
|
// note, this is for the previous block
|
|
@@ -484,7 +510,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
484
510
|
*/
|
|
485
511
|
heartbeatRequired(head) {
|
|
486
512
|
const epoch = head.$epoch;
|
|
487
|
-
if (
|
|
513
|
+
if (isDefined2(epoch)) {
|
|
488
514
|
const { heartbeatInterval } = this.params.config.producer;
|
|
489
515
|
if (Date.now() - epoch > heartbeatInterval) {
|
|
490
516
|
return true;
|
|
@@ -498,7 +524,7 @@ BaseBlockProducerService = _ts_decorate4([
|
|
|
498
524
|
], BaseBlockProducerService);
|
|
499
525
|
|
|
500
526
|
// src/BlockReward/BaseBlockRewardService.ts
|
|
501
|
-
import { creatable as creatable5 } from "@xylabs/
|
|
527
|
+
import { creatable as creatable5 } from "@xylabs/sdk-js";
|
|
502
528
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
503
529
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
504
530
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -519,9 +545,7 @@ BaseBlockRewardService = _ts_decorate5([
|
|
|
519
545
|
], BaseBlockRewardService);
|
|
520
546
|
|
|
521
547
|
// src/BlockReward/EvmBlockRewardService.ts
|
|
522
|
-
import { assertEx as
|
|
523
|
-
import { creatable as creatable6 } from "@xylabs/creatable";
|
|
524
|
-
import { toEthAddress } from "@xylabs/hex";
|
|
548
|
+
import { assertEx as assertEx4, creatable as creatable6, toEthAddress } from "@xylabs/sdk-js";
|
|
525
549
|
import { XyoChainRewards__factory as XyoChainRewardsFactory } from "@xyo-network/typechain";
|
|
526
550
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
527
551
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -536,13 +560,13 @@ var EvmBlockRewardService = class extends BaseBlockRewardService {
|
|
|
536
560
|
}
|
|
537
561
|
_contractAddress;
|
|
538
562
|
get chainService() {
|
|
539
|
-
return
|
|
563
|
+
return assertEx4(this.params.chainService, () => "chainService is required");
|
|
540
564
|
}
|
|
541
565
|
get contractAddress() {
|
|
542
|
-
return
|
|
566
|
+
return assertEx4(this._contractAddress, () => "contractAddress is required");
|
|
543
567
|
}
|
|
544
568
|
get provider() {
|
|
545
|
-
return
|
|
569
|
+
return assertEx4(this.params.provider, () => "provider is required");
|
|
546
570
|
}
|
|
547
571
|
async createHandler() {
|
|
548
572
|
await super.createHandler();
|
|
@@ -563,9 +587,7 @@ EvmBlockRewardService = _ts_decorate6([
|
|
|
563
587
|
], EvmBlockRewardService);
|
|
564
588
|
|
|
565
589
|
// src/BlockReward/MemoryBlockRewardService.ts
|
|
566
|
-
import { assertEx as
|
|
567
|
-
import { creatable as creatable7 } from "@xylabs/creatable";
|
|
568
|
-
import { toFixedPoint } from "@xylabs/decimal-precision";
|
|
590
|
+
import { assertEx as assertEx5, creatable as creatable7, toFixedPoint } from "@xylabs/sdk-js";
|
|
569
591
|
import { rewardFromBlockNumber } from "@xyo-network/chain-protocol";
|
|
570
592
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
571
593
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -580,22 +602,22 @@ var MemoryBlockRewardService = class extends BaseBlockRewardService {
|
|
|
580
602
|
}
|
|
581
603
|
rewardFromBlockNumber = rewardFromBlockNumber(18);
|
|
582
604
|
get creatorReward() {
|
|
583
|
-
return
|
|
605
|
+
return assertEx5(this.params.creatorReward, () => "creatorReward is required");
|
|
584
606
|
}
|
|
585
607
|
get initialReward() {
|
|
586
|
-
return
|
|
608
|
+
return assertEx5(this.params.initialStepReward, () => "initialStepReward is required");
|
|
587
609
|
}
|
|
588
610
|
get minRewardPerBlock() {
|
|
589
|
-
return
|
|
611
|
+
return assertEx5(this.params.minRewardPerBlock, () => "minRewardPerBlock is required");
|
|
590
612
|
}
|
|
591
613
|
get stepFactorDenominator() {
|
|
592
|
-
return
|
|
614
|
+
return assertEx5(this.params.stepFactorDenominator, () => "stepFactorDenominator is required");
|
|
593
615
|
}
|
|
594
616
|
get stepFactorNumerator() {
|
|
595
|
-
return
|
|
617
|
+
return assertEx5(this.params.stepFactorNumerator, () => "stepFactorNumerator is required");
|
|
596
618
|
}
|
|
597
619
|
get stepSize() {
|
|
598
|
-
return
|
|
620
|
+
return assertEx5(this.params.stepSize, () => "stepSize is required");
|
|
599
621
|
}
|
|
600
622
|
static async paramsHandler(inParams) {
|
|
601
623
|
return {
|
|
@@ -617,10 +639,9 @@ MemoryBlockRewardService = _ts_decorate7([
|
|
|
617
639
|
], MemoryBlockRewardService);
|
|
618
640
|
|
|
619
641
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
620
|
-
import { assertEx as
|
|
621
|
-
import {
|
|
622
|
-
import {
|
|
623
|
-
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
642
|
+
import { assertEx as assertEx6, isDefined as isDefined3, isNull, isUndefined } from "@xylabs/sdk-js";
|
|
643
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
644
|
+
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, isBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
624
645
|
import { LRUCache } from "lru-cache";
|
|
625
646
|
var ChainBlockNumberIterationService = class extends BaseService {
|
|
626
647
|
static {
|
|
@@ -631,21 +652,21 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
631
652
|
});
|
|
632
653
|
_currentHead;
|
|
633
654
|
get chainId() {
|
|
634
|
-
return
|
|
655
|
+
return assertEx6(this._currentHead?.chain ?? this.params?.head?.chain, () => "Current head is not set");
|
|
635
656
|
}
|
|
636
657
|
get chainMap() {
|
|
637
|
-
return
|
|
658
|
+
return assertEx6(this.params.chainMap);
|
|
638
659
|
}
|
|
639
660
|
async get(block) {
|
|
640
661
|
const head = await this.head();
|
|
641
|
-
|
|
662
|
+
assertEx6(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
|
|
642
663
|
const cached = this._blocksByBlockNumber.get(block);
|
|
643
664
|
if (cached) return cached;
|
|
644
665
|
const startingBlock = head;
|
|
645
|
-
const currentBlockHash = await
|
|
666
|
+
const currentBlockHash = await PayloadBuilder4.hash(startingBlock);
|
|
646
667
|
let currentBlock = await this.chainMap.get(currentBlockHash);
|
|
647
|
-
while (
|
|
648
|
-
|
|
668
|
+
while (isDefined3(currentBlock)) {
|
|
669
|
+
assertEx6(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
|
|
649
670
|
if (isBlockBoundWitnessWithHashMeta(currentBlock)) {
|
|
650
671
|
this._blocksByBlockNumber.set(currentBlock.block, currentBlock);
|
|
651
672
|
if (currentBlock.block === block) {
|
|
@@ -659,8 +680,8 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
659
680
|
throw new Error(`Block not found: ${block}`);
|
|
660
681
|
}
|
|
661
682
|
async head() {
|
|
662
|
-
if (
|
|
663
|
-
if (
|
|
683
|
+
if (isDefined3(this._currentHead)) return this._currentHead;
|
|
684
|
+
if (isDefined3(this.params.head)) {
|
|
664
685
|
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head);
|
|
665
686
|
this._currentHead = newHead;
|
|
666
687
|
return newHead;
|
|
@@ -676,17 +697,17 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
676
697
|
// and then communicate via method name and documentation
|
|
677
698
|
async previous(block = void 0, count = 1) {
|
|
678
699
|
const results = [];
|
|
679
|
-
let currentBlock =
|
|
680
|
-
while (
|
|
700
|
+
let currentBlock = isDefined3(block) ? await this.get(block) : await this.head();
|
|
701
|
+
while (isDefined3(currentBlock) && results.length < count) {
|
|
681
702
|
if (isBlockBoundWitnessWithHashMeta(currentBlock)) {
|
|
682
703
|
results.push(currentBlock);
|
|
683
704
|
const { previous } = currentBlock;
|
|
684
705
|
if (isNull(previous)) break;
|
|
685
706
|
const nextBlock = await this.chainMap.get(previous);
|
|
686
|
-
currentBlock =
|
|
707
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta2(nextBlock);
|
|
687
708
|
} else {
|
|
688
|
-
const hash =
|
|
689
|
-
|
|
709
|
+
const hash = PayloadBuilder4.hash(currentBlock);
|
|
710
|
+
assertEx6(asBlockBoundWitnessWithStorageMeta2(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
|
|
690
711
|
}
|
|
691
712
|
}
|
|
692
713
|
return results;
|
|
@@ -701,17 +722,16 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
701
722
|
});
|
|
702
723
|
}
|
|
703
724
|
async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head) {
|
|
704
|
-
const hash = await
|
|
725
|
+
const hash = await PayloadBuilder4.hash(head);
|
|
705
726
|
const stored = await this.chainMap.get(hash);
|
|
706
|
-
const newHead =
|
|
727
|
+
const newHead = asBlockBoundWitnessWithStorageMeta2(stored);
|
|
707
728
|
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`);
|
|
708
729
|
return newHead;
|
|
709
730
|
}
|
|
710
731
|
};
|
|
711
732
|
|
|
712
733
|
// src/ChainService/Evm/Evm.ts
|
|
713
|
-
import { assertEx as
|
|
714
|
-
import { toAddress, toEthAddress as toEthAddress2 } from "@xylabs/hex";
|
|
734
|
+
import { assertEx as assertEx7, toAddress, toEthAddress as toEthAddress2 } from "@xylabs/sdk-js";
|
|
715
735
|
import { StakedXyoChain__factory as StakedXyoChainFactory } from "@xyo-network/typechain";
|
|
716
736
|
import { getAddress } from "ethers/address";
|
|
717
737
|
var EvmChainService = class extends BaseService {
|
|
@@ -719,16 +739,16 @@ var EvmChainService = class extends BaseService {
|
|
|
719
739
|
__name(this, "EvmChainService");
|
|
720
740
|
}
|
|
721
741
|
get chainId() {
|
|
722
|
-
return
|
|
742
|
+
return assertEx7(this.params.id);
|
|
723
743
|
}
|
|
724
744
|
get contract() {
|
|
725
745
|
if (this.params.contract === void 0) {
|
|
726
746
|
this.params.contract = StakedXyoChainFactory.connect(toEthAddress2(this.chainId), this.params.runner);
|
|
727
747
|
}
|
|
728
|
-
return
|
|
748
|
+
return assertEx7(this.params.contract);
|
|
729
749
|
}
|
|
730
750
|
get runner() {
|
|
731
|
-
return
|
|
751
|
+
return assertEx7(this.params.runner);
|
|
732
752
|
}
|
|
733
753
|
async active() {
|
|
734
754
|
return await this.contract.active();
|
|
@@ -787,7 +807,7 @@ var EvmChainService = class extends BaseService {
|
|
|
787
807
|
};
|
|
788
808
|
|
|
789
809
|
// src/ChainService/Memory/Memory.ts
|
|
790
|
-
import { ZERO_ADDRESS } from "@xylabs/
|
|
810
|
+
import { ZERO_ADDRESS } from "@xylabs/sdk-js";
|
|
791
811
|
var MemoryChainService = class extends BaseService {
|
|
792
812
|
static {
|
|
793
813
|
__name(this, "MemoryChainService");
|
|
@@ -851,8 +871,7 @@ var MemoryChainService = class extends BaseService {
|
|
|
851
871
|
};
|
|
852
872
|
|
|
853
873
|
// src/ChainValidator/XyoValidator.ts
|
|
854
|
-
import { assertEx as
|
|
855
|
-
import { creatable as creatable8 } from "@xylabs/creatable";
|
|
874
|
+
import { assertEx as assertEx8, creatable as creatable8 } from "@xylabs/sdk-js";
|
|
856
875
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
857
876
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
858
877
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -868,22 +887,22 @@ var XyoValidator = class extends BaseService {
|
|
|
868
887
|
return this.account.address;
|
|
869
888
|
}
|
|
870
889
|
get account() {
|
|
871
|
-
return
|
|
890
|
+
return assertEx8(this.params.account, () => "account is required");
|
|
872
891
|
}
|
|
873
892
|
get chainArchivist() {
|
|
874
|
-
return
|
|
893
|
+
return assertEx8(this.params.chainArchivist, () => "chainArchivist is required");
|
|
875
894
|
}
|
|
876
895
|
get chainInfo() {
|
|
877
|
-
return
|
|
896
|
+
return assertEx8(this.params.chainId, () => "chainInfo is required");
|
|
878
897
|
}
|
|
879
898
|
get electionService() {
|
|
880
|
-
return
|
|
899
|
+
return assertEx8(this.params.electionService, () => "electionService is required");
|
|
881
900
|
}
|
|
882
901
|
get pendingBundledTransactionsArchivist() {
|
|
883
|
-
return
|
|
902
|
+
return assertEx8(this.params.pendingBundledTransactionsArchivist, () => "pendingBundledTransactions is required");
|
|
884
903
|
}
|
|
885
904
|
get rewardService() {
|
|
886
|
-
return
|
|
905
|
+
return assertEx8(this.params.rewardService, () => "rewardService is required");
|
|
887
906
|
}
|
|
888
907
|
validatePendingBlock(_block) {
|
|
889
908
|
return [];
|
|
@@ -902,8 +921,7 @@ XyoValidator = _ts_decorate8([
|
|
|
902
921
|
], XyoValidator);
|
|
903
922
|
|
|
904
923
|
// src/Election/BaseElectionService.ts
|
|
905
|
-
import { assertEx as
|
|
906
|
-
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
924
|
+
import { assertEx as assertEx9, creatable as creatable9 } from "@xylabs/sdk-js";
|
|
907
925
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
908
926
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
909
927
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -917,13 +935,13 @@ var BaseElectionService = class extends BaseService {
|
|
|
917
935
|
__name(this, "BaseElectionService");
|
|
918
936
|
}
|
|
919
937
|
get chainIterator() {
|
|
920
|
-
return
|
|
938
|
+
return assertEx9(this.params.chainIterator, () => "No chain iterator");
|
|
921
939
|
}
|
|
922
940
|
get chainStakeViewer() {
|
|
923
|
-
return
|
|
941
|
+
return assertEx9(this.params.chainStakeViewer, () => "No chain stake viewer");
|
|
924
942
|
}
|
|
925
943
|
get stakeIntentService() {
|
|
926
|
-
return
|
|
944
|
+
return assertEx9(this.params.stakeIntentService, () => "No staked intent service");
|
|
927
945
|
}
|
|
928
946
|
async getCreatorCommitteeForNextBlock(current) {
|
|
929
947
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
@@ -945,7 +963,7 @@ BaseElectionService = _ts_decorate9([
|
|
|
945
963
|
], BaseElectionService);
|
|
946
964
|
|
|
947
965
|
// src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts
|
|
948
|
-
import { creatable as creatable10 } from "@xylabs/
|
|
966
|
+
import { creatable as creatable10 } from "@xylabs/sdk-js";
|
|
949
967
|
function _ts_decorate10(decorators, target, key, desc) {
|
|
950
968
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
951
969
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1018,23 +1036,18 @@ BaseNetworkStakeStepRewardService = _ts_decorate10([
|
|
|
1018
1036
|
|
|
1019
1037
|
// src/PendingTransactions/BasePendingTransactions.ts
|
|
1020
1038
|
import { ValueType } from "@opentelemetry/api";
|
|
1021
|
-
import { filterAs, filterAsync } from "@xylabs/
|
|
1022
|
-
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1023
|
-
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1024
|
-
import { exists as exists2 } from "@xylabs/exists";
|
|
1025
|
-
import { forget } from "@xylabs/forget";
|
|
1026
|
-
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1039
|
+
import { assertEx as assertEx10, creatable as creatable11, exists as exists2, filterAs, filterAsync, forget, isDefined as isDefined4, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
1027
1040
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
1028
|
-
import { findMostRecentBlock as
|
|
1041
|
+
import { findMostRecentBlock as findMostRecentBlock2 } from "@xyo-network/chain-protocol";
|
|
1029
1042
|
import { asBlockBoundWitnessWithHashMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1030
1043
|
import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-network/xl1-validation";
|
|
1031
1044
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
1032
1045
|
|
|
1033
1046
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
1034
|
-
import { PayloadBuilder as
|
|
1047
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1035
1048
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1036
1049
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
1037
|
-
const withStorageMeta = await
|
|
1050
|
+
const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
|
|
1038
1051
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
1039
1052
|
if (tx) {
|
|
1040
1053
|
return [
|
|
@@ -1045,7 +1058,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
1045
1058
|
}, "bundledPayloadToHydratedTransaction");
|
|
1046
1059
|
|
|
1047
1060
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
1048
|
-
import { PayloadBuilder as
|
|
1061
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1049
1062
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1050
1063
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1051
1064
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -1053,8 +1066,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
1053
1066
|
return bundle(root, transaction);
|
|
1054
1067
|
}, "hydratedTransactionToPayloadBundle");
|
|
1055
1068
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
1056
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
1057
|
-
return new
|
|
1069
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
|
|
1070
|
+
return new PayloadBuilder6({
|
|
1058
1071
|
schema: PayloadBundleSchema
|
|
1059
1072
|
}).fields({
|
|
1060
1073
|
payloads,
|
|
@@ -1117,23 +1130,23 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1117
1130
|
return this.params.additionalPendingTransactionValidators ?? [];
|
|
1118
1131
|
}
|
|
1119
1132
|
get chainArchivist() {
|
|
1120
|
-
return
|
|
1133
|
+
return assertEx10(this.params.chainArchivist, () => "No completed blocks with data archivist");
|
|
1121
1134
|
}
|
|
1122
1135
|
get chainId() {
|
|
1123
|
-
return
|
|
1136
|
+
return assertEx10(this.params.chainId, () => "No chain id");
|
|
1124
1137
|
}
|
|
1125
1138
|
get pendingBundledTransactionsArchivist() {
|
|
1126
|
-
return
|
|
1139
|
+
return assertEx10(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
|
|
1127
1140
|
}
|
|
1128
1141
|
get pendingBundledTransactionsLocalArchivist() {
|
|
1129
|
-
return
|
|
1142
|
+
return assertEx10(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
|
|
1130
1143
|
}
|
|
1131
1144
|
get pendingTransactionsCount() {
|
|
1132
1145
|
forget(this.countPendingTransactions());
|
|
1133
1146
|
return this._pendingTransactionsCount;
|
|
1134
1147
|
}
|
|
1135
1148
|
get rejectedTransactionsArchivist() {
|
|
1136
|
-
return
|
|
1149
|
+
return assertEx10(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
|
|
1137
1150
|
}
|
|
1138
1151
|
async createHandler() {
|
|
1139
1152
|
await super.createHandler();
|
|
@@ -1202,8 +1215,8 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1202
1215
|
}
|
|
1203
1216
|
async cleanupWorker() {
|
|
1204
1217
|
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
1205
|
-
const lastHead = await
|
|
1206
|
-
if (
|
|
1218
|
+
const lastHead = await findMostRecentBlock2(this.chainArchivist);
|
|
1219
|
+
if (isDefined4(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
|
|
1207
1220
|
}, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
|
|
1208
1221
|
}
|
|
1209
1222
|
async countPendingTransactions() {
|
|
@@ -1265,7 +1278,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1265
1278
|
let [lastHead] = filterAs(await this.chainArchivist.get([
|
|
1266
1279
|
head
|
|
1267
1280
|
]), asBlockBoundWitnessWithHashMeta);
|
|
1268
|
-
while (
|
|
1281
|
+
while (isDefined4(lastHead)) {
|
|
1269
1282
|
const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
|
|
1270
1283
|
limit: 100,
|
|
1271
1284
|
order: "asc",
|
|
@@ -1306,8 +1319,7 @@ var isTransactionExpired = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.ex
|
|
|
1306
1319
|
var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf <= block && txBw.exp >= block, "isTransactionActive");
|
|
1307
1320
|
|
|
1308
1321
|
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
1309
|
-
import { filterAs as filterAs2 } from "@xylabs/
|
|
1310
|
-
import { exists as exists3 } from "@xylabs/exists";
|
|
1322
|
+
import { exists as exists3, filterAs as filterAs2 } from "@xylabs/sdk-js";
|
|
1311
1323
|
import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
|
|
1312
1324
|
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
1313
1325
|
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
@@ -1333,16 +1345,12 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
|
|
|
1333
1345
|
}, "mapBoundWitnessToStakeIntentHashes");
|
|
1334
1346
|
|
|
1335
1347
|
// src/StakeIntent/XyoStakeIntentService.ts
|
|
1336
|
-
import { filterAs as filterAs3 } from "@xylabs/
|
|
1337
|
-
import { assertEx as assertEx12 } from "@xylabs/assert";
|
|
1338
|
-
import { creatable as creatable12 } from "@xylabs/creatable";
|
|
1339
|
-
import { asAddress } from "@xylabs/hex";
|
|
1340
|
-
import { isUndefined as isUndefined3 } from "@xylabs/typeof";
|
|
1348
|
+
import { asAddress, assertEx as assertEx11, creatable as creatable12, filterAs as filterAs3, isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
1341
1349
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1342
1350
|
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
|
|
1351
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1352
|
+
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asChainStakeIntent as asChainStakeIntent2 } from "@xyo-network/xl1-protocol";
|
|
1353
|
+
import { asChainIndexingServiceStateWithStorageMeta, ChainIndexingServiceStateSchema, isChainIndexingServiceState, readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
1346
1354
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1347
1355
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
1348
1356
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
@@ -1374,16 +1382,16 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1374
1382
|
});
|
|
1375
1383
|
_updateMutex = new Mutex3();
|
|
1376
1384
|
get chainArchivist() {
|
|
1377
|
-
return
|
|
1385
|
+
return assertEx11(this.params.chainArchivist, () => "chainArchivist not set");
|
|
1378
1386
|
}
|
|
1379
1387
|
get chainIterator() {
|
|
1380
|
-
return
|
|
1388
|
+
return assertEx11(this.params.chainIterator, () => "chainIterator not set");
|
|
1381
1389
|
}
|
|
1382
1390
|
get chainStakeViewer() {
|
|
1383
|
-
return
|
|
1391
|
+
return assertEx11(this.params.chainStakeViewer, () => "chainStakeViewer not set");
|
|
1384
1392
|
}
|
|
1385
1393
|
get stakeIntentStateArchivist() {
|
|
1386
|
-
return
|
|
1394
|
+
return assertEx11(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
|
|
1387
1395
|
}
|
|
1388
1396
|
async createHandler() {
|
|
1389
1397
|
this.chainIterator.on("headUpdated", async () => {
|
|
@@ -1391,18 +1399,18 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1391
1399
|
});
|
|
1392
1400
|
const head = await this.chainIterator.head();
|
|
1393
1401
|
if (isUndefined3(head)) return;
|
|
1394
|
-
const headHash = await
|
|
1402
|
+
const headHash = await PayloadBuilder7.hash(head);
|
|
1395
1403
|
await this.recoverState(headHash);
|
|
1396
1404
|
}
|
|
1397
1405
|
async getDeclaredCandidateRanges(address, intent) {
|
|
1398
1406
|
await Promise.resolve();
|
|
1399
|
-
|
|
1407
|
+
assertEx11(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
1400
1408
|
const results = this._producers.get(address);
|
|
1401
1409
|
return results ?? [];
|
|
1402
1410
|
}
|
|
1403
1411
|
async getDeclaredCandidatesForBlock(block, intent) {
|
|
1404
1412
|
return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
|
|
1405
|
-
|
|
1413
|
+
assertEx11(intent === "producer", () => `Support not yet added for intent ${intent}`);
|
|
1406
1414
|
const results = this._producers.findAllContaining(block);
|
|
1407
1415
|
const candidates = [
|
|
1408
1416
|
...results
|
|
@@ -1456,7 +1464,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1456
1464
|
}
|
|
1457
1465
|
async persistState(current) {
|
|
1458
1466
|
const state = this._producers.serialize();
|
|
1459
|
-
const payload = new
|
|
1467
|
+
const payload = new PayloadBuilder7({
|
|
1460
1468
|
schema: ChainIndexingServiceStateSchema
|
|
1461
1469
|
}).fields({
|
|
1462
1470
|
endBlockHash: current,
|
|
@@ -1467,7 +1475,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1467
1475
|
]);
|
|
1468
1476
|
}
|
|
1469
1477
|
async recoverState(current) {
|
|
1470
|
-
const currentBlock =
|
|
1478
|
+
const currentBlock = assertEx11(asBlockBoundWitness3((await this.chainArchivist.get([
|
|
1471
1479
|
current
|
|
1472
1480
|
]))?.[0]), () => `Block ${current} not found`);
|
|
1473
1481
|
const currentBlockNum = currentBlock.block;
|
|
@@ -1484,7 +1492,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1484
1492
|
const indexed = (await this.chainArchivist.get([
|
|
1485
1493
|
state.endBlockHash
|
|
1486
1494
|
]))?.[0];
|
|
1487
|
-
const indexedBlock =
|
|
1495
|
+
const indexedBlock = asBlockBoundWitnessWithStorageMeta3(indexed);
|
|
1488
1496
|
if (indexedBlock) {
|
|
1489
1497
|
const indexedBlockNum = indexedBlock.block;
|
|
1490
1498
|
if (indexedBlockNum <= currentBlockNum) {
|
|
@@ -1508,8 +1516,8 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1508
1516
|
return await this.spanAsync("updateIndex", async () => {
|
|
1509
1517
|
const currentHead = await this.chainIterator.head();
|
|
1510
1518
|
if (isUndefined3(currentHead)) return;
|
|
1511
|
-
const currentHeadHash = await
|
|
1512
|
-
const chainMap =
|
|
1519
|
+
const currentHeadHash = await PayloadBuilder7.hash(currentHead);
|
|
1520
|
+
const chainMap = readPayloadMapFromStore2(this.chainArchivist);
|
|
1513
1521
|
const result = await analyzeChain({
|
|
1514
1522
|
chainMap
|
|
1515
1523
|
}, [
|
|
@@ -1538,7 +1546,7 @@ XyoStakeIntentService = _ts_decorate12([
|
|
|
1538
1546
|
], XyoStakeIntentService);
|
|
1539
1547
|
|
|
1540
1548
|
// src/StepStake/BaseStepStakeService.ts
|
|
1541
|
-
import { creatable as creatable13 } from "@xylabs/
|
|
1549
|
+
import { creatable as creatable13 } from "@xylabs/sdk-js";
|
|
1542
1550
|
function _ts_decorate13(decorators, target, key, desc) {
|
|
1543
1551
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1544
1552
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1562,11 +1570,8 @@ BaseStepStakeService = _ts_decorate13([
|
|
|
1562
1570
|
], BaseStepStakeService);
|
|
1563
1571
|
|
|
1564
1572
|
// src/Time/BaseTimeSyncService.ts
|
|
1565
|
-
import {
|
|
1566
|
-
import {
|
|
1567
|
-
import { asHash } from "@xylabs/hex";
|
|
1568
|
-
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1569
|
-
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1573
|
+
import { creatable as creatable14 } from "@xylabs/sdk-js";
|
|
1574
|
+
import { SimpleTimeSyncViewer } from "@xyo-network/xl1-protocol-sdk";
|
|
1570
1575
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
1571
1576
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1572
1577
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1578,6 +1583,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1578
1583
|
static {
|
|
1579
1584
|
__name(this, "BaseTimeSyncService");
|
|
1580
1585
|
}
|
|
1586
|
+
timeSyncViewer;
|
|
1581
1587
|
get chainArchivist() {
|
|
1582
1588
|
return this.params.chainArchivist;
|
|
1583
1589
|
}
|
|
@@ -1588,93 +1594,21 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1588
1594
|
return this.params.ethProvider;
|
|
1589
1595
|
}
|
|
1590
1596
|
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
|
-
}
|
|
1597
|
+
return await this.timeSyncViewer.convertTime(fromDomain, toDomain, from);
|
|
1598
|
+
}
|
|
1599
|
+
async createHandler() {
|
|
1600
|
+
await super.createHandler();
|
|
1601
|
+
const blockViewer = blockViewerFromChainIteratorAndArchivist(this.chainIterator, this.chainArchivist);
|
|
1602
|
+
this.timeSyncViewer = new SimpleTimeSyncViewer(blockViewer, this.ethProvider);
|
|
1620
1603
|
}
|
|
1621
1604
|
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
|
-
}
|
|
1605
|
+
return await this.timeSyncViewer.currentTime(domain);
|
|
1645
1606
|
}
|
|
1646
1607
|
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
|
-
}
|
|
1608
|
+
return await this.timeSyncViewer.currentTimeAndHash(domain);
|
|
1675
1609
|
}
|
|
1676
|
-
currentTimePayload() {
|
|
1677
|
-
|
|
1610
|
+
async currentTimePayload() {
|
|
1611
|
+
return await this.timeSyncViewer.currentTimePayload();
|
|
1678
1612
|
}
|
|
1679
1613
|
};
|
|
1680
1614
|
BaseTimeSyncService = _ts_decorate14([
|
|
@@ -1703,7 +1637,6 @@ export {
|
|
|
1703
1637
|
XyoStakeIntentService,
|
|
1704
1638
|
XyoValidator,
|
|
1705
1639
|
accountBalancesServiceFromArchivist,
|
|
1706
|
-
accountTransfersServiceFromArchivist,
|
|
1707
1640
|
creatableService,
|
|
1708
1641
|
getBlockSignedStakeDeclarations
|
|
1709
1642
|
};
|