@xyo-network/xl1-protocol-sdk 1.15.2 → 1.15.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/README.md +1507 -388
- package/dist/neutral/block/hydrate/hydrateBlock.d.ts +5 -2
- package/dist/neutral/block/hydrate/hydrateBlock.d.ts.map +1 -1
- package/dist/neutral/block/primitives/balances/balancesStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/block/primitives/blockFromBlockNumber.d.ts +2 -2
- package/dist/neutral/block/primitives/blockFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/block/primitives/hashFromBlockNumber.d.ts +2 -2
- package/dist/neutral/block/primitives/hashFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/block/primitives/model.d.ts +8 -8
- package/dist/neutral/block/primitives/model.d.ts.map +1 -1
- package/dist/neutral/block/primitives/payloads/StepSummary.d.ts.map +1 -1
- package/dist/neutral/block/primitives/payloads/TransfersSummary.d.ts +1 -2
- package/dist/neutral/block/primitives/payloads/TransfersSummary.d.ts.map +1 -1
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts +1 -1
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/config/Bridge.d.ts +8 -0
- package/dist/neutral/config/Bridge.d.ts.map +1 -0
- package/dist/neutral/config/Config.d.ts +5 -0
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +2 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +296 -298
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/instances/ShiftedBigIntConfig.d.ts +1 -1
- package/dist/neutral/instances/ShiftedBigIntConfig.d.ts.map +1 -1
- package/dist/neutral/instances/XL1Amount.d.ts +1 -1
- package/dist/neutral/instances/XL1Amount.d.ts.map +1 -1
- package/dist/neutral/map/AsynchronousMap.d.ts +14 -0
- package/dist/neutral/map/AsynchronousMap.d.ts.map +1 -0
- package/dist/neutral/map/MapType.d.ts +6 -0
- package/dist/neutral/map/MapType.d.ts.map +1 -0
- package/dist/neutral/map/SynchronousMap.d.ts +13 -0
- package/dist/neutral/map/SynchronousMap.d.ts.map +1 -0
- package/dist/neutral/map/index.d.ts +4 -0
- package/dist/neutral/map/index.d.ts.map +1 -0
- package/dist/neutral/model/ChainContext/ChainContext.d.ts +15 -0
- package/dist/neutral/model/ChainContext/ChainContext.d.ts.map +1 -0
- package/dist/neutral/model/ChainContext/ChainStakeContext.d.ts +10 -0
- package/dist/neutral/model/ChainContext/ChainStakeContext.d.ts.map +1 -0
- package/dist/neutral/model/ChainContext/ChainStateContext.d.ts +9 -0
- package/dist/neutral/model/ChainContext/ChainStateContext.d.ts.map +1 -0
- package/dist/neutral/model/ChainContext/ChainStoreContext.d.ts +10 -0
- package/dist/neutral/model/ChainContext/ChainStoreContext.d.ts.map +1 -0
- package/dist/neutral/model/ChainContext/index.d.ts +5 -0
- package/dist/neutral/model/ChainContext/index.d.ts.map +1 -0
- package/dist/neutral/model/ChainFork/ChainForkStatic.d.ts +8 -0
- package/dist/neutral/model/ChainFork/ChainForkStatic.d.ts.map +1 -0
- package/dist/neutral/model/ChainFork/index.d.ts +2 -0
- package/dist/neutral/model/ChainFork/index.d.ts.map +1 -0
- package/dist/neutral/model/ChainIdentity.d.ts +5 -0
- package/dist/neutral/model/ChainIdentity.d.ts.map +1 -0
- package/dist/neutral/model/ChainStake/ChainStakeRead.d.ts +17 -0
- package/dist/neutral/model/ChainStake/ChainStakeRead.d.ts.map +1 -0
- package/dist/neutral/model/ChainStake/ChainStakeStatic.d.ts +7 -0
- package/dist/neutral/model/ChainStake/ChainStakeStatic.d.ts.map +1 -0
- package/dist/neutral/model/ChainStake/ChainStakeWrite.d.ts +6 -0
- package/dist/neutral/model/ChainStake/ChainStakeWrite.d.ts.map +1 -0
- package/dist/neutral/model/ChainStake/index.d.ts +4 -0
- package/dist/neutral/model/ChainStake/index.d.ts.map +1 -0
- package/dist/neutral/model/ChainStore.d.ts +10 -0
- package/dist/neutral/model/ChainStore.d.ts.map +1 -0
- package/dist/neutral/model/PayloadMap.d.ts +7 -0
- package/dist/neutral/model/PayloadMap.d.ts.map +1 -0
- package/dist/neutral/model/StakeEvents.d.ts +31 -0
- package/dist/neutral/model/StakeEvents.d.ts.map +1 -0
- package/dist/neutral/model/index.d.ts +8 -0
- package/dist/neutral/model/index.d.ts.map +1 -0
- package/dist/neutral/payload/netTransfersForPayloads.d.ts +1 -1
- package/dist/neutral/payload/netTransfersForPayloads.d.ts.map +1 -1
- package/dist/neutral/steps/primitives/index.d.ts +0 -10
- package/dist/neutral/steps/primitives/index.d.ts.map +1 -1
- package/dist/neutral/time/primitives/xl1BlockNumberToEthBlockNumber.d.ts +2 -2
- package/dist/neutral/time/primitives/xl1BlockNumberToEthBlockNumber.d.ts.map +1 -1
- package/dist/neutral/transaction/buildTransaction.d.ts +2 -2
- package/dist/neutral/transaction/buildTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/buildUnsignedTransaction.d.ts +2 -2
- package/dist/neutral/transaction/buildUnsignedTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/hydrateTransaction.d.ts +5 -5
- package/dist/neutral/transaction/hydrateTransaction.d.ts.map +1 -1
- package/package.json +29 -29
- package/src/block/hydrate/hydrateBlock.ts +32 -10
- package/src/block/primitives/balances/balancesStepSummaryFromRange.ts +5 -4
- package/src/block/primitives/balances/balancesSummary.ts +3 -2
- package/src/block/primitives/blockFromBlockNumber.ts +8 -6
- package/src/block/primitives/hashFromBlockNumber.ts +2 -2
- package/src/block/primitives/model.ts +13 -11
- package/src/block/primitives/payloads/StepSummary.ts +1 -1
- package/src/block/primitives/payloads/TransfersSummary.ts +1 -2
- package/src/block/primitives/transfers/transfersStepSummaryFromRange.ts +25 -15
- package/src/block/primitives/transfers/transfersSummary.ts +12 -7
- package/src/config/Bridge.ts +26 -0
- package/src/config/Config.ts +2 -0
- package/src/index.ts +2 -0
- package/src/instances/ShiftedBigIntConfig.ts +1 -1
- package/src/instances/XL1Amount.ts +1 -1
- package/src/map/AsynchronousMap.ts +15 -0
- package/src/map/MapType.ts +8 -0
- package/src/map/SynchronousMap.ts +13 -0
- package/src/map/index.ts +3 -0
- package/src/model/ChainContext/ChainContext.ts +20 -0
- package/src/model/ChainContext/ChainStakeContext.ts +12 -0
- package/src/model/ChainContext/ChainStateContext.ts +10 -0
- package/src/model/ChainContext/ChainStoreContext.ts +12 -0
- package/src/model/ChainContext/index.ts +4 -0
- package/src/model/ChainFork/ChainForkStatic.ts +8 -0
- package/src/model/ChainFork/index.ts +1 -0
- package/src/model/ChainIdentity.ts +5 -0
- package/src/model/ChainStake/ChainStakeRead.ts +17 -0
- package/src/model/ChainStake/ChainStakeStatic.ts +7 -0
- package/src/model/ChainStake/ChainStakeWrite.ts +5 -0
- package/src/model/ChainStake/index.ts +3 -0
- package/src/model/ChainStore.ts +13 -0
- package/src/model/PayloadMap.ts +10 -0
- package/src/model/StakeEvents.ts +38 -0
- package/src/model/index.ts +7 -0
- package/src/payload/netTransfersForPayloads.ts +7 -12
- package/src/steps/primitives/index.ts +0 -10
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +4 -5
- package/src/transaction/buildTransaction.ts +2 -2
- package/src/transaction/buildUnsignedTransaction.ts +2 -2
- package/src/transaction/hydrateTransaction.ts +24 -9
- package/dist/neutral/steps/primitives/networkStakeStepAddressReward.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepAddressReward.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepPoolRewardShares.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepPoolRewardShares.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepPoolRewards.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepPoolRewards.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardAddressHistory.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepRewardAddressHistory.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardAddressShare.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepRewardAddressShare.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardForStep.d.ts +0 -3
- package/dist/neutral/steps/primitives/networkStakeStepRewardForStep.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardPositionWeight.d.ts +0 -3
- package/dist/neutral/steps/primitives/networkStakeStepRewardPositionWeight.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardPotentialPositionLoss.d.ts +0 -3
- package/dist/neutral/steps/primitives/networkStakeStepRewardPotentialPositionLoss.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardRandomizer.d.ts +0 -3
- package/dist/neutral/steps/primitives/networkStakeStepRewardRandomizer.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/networkStakeStepRewardWeightForAddress.d.ts +0 -4
- package/dist/neutral/steps/primitives/networkStakeStepRewardWeightForAddress.d.ts.map +0 -1
- package/src/steps/primitives/networkStakeStepAddressReward.ts +0 -6
- package/src/steps/primitives/networkStakeStepPoolRewardShares.ts +0 -6
- package/src/steps/primitives/networkStakeStepPoolRewards.ts +0 -6
- package/src/steps/primitives/networkStakeStepRewardAddressHistory.ts +0 -6
- package/src/steps/primitives/networkStakeStepRewardAddressShare.ts +0 -6
- package/src/steps/primitives/networkStakeStepRewardForStep.ts +0 -5
- package/src/steps/primitives/networkStakeStepRewardPositionWeight.ts +0 -5
- package/src/steps/primitives/networkStakeStepRewardPotentialPositionLoss.ts +0 -5
- package/src/steps/primitives/networkStakeStepRewardRandomizer.ts +0 -5
- package/src/steps/primitives/networkStakeStepRewardWeightForAddress.ts +0 -6
package/dist/neutral/index.mjs
CHANGED
|
@@ -28,90 +28,12 @@ var flattenHydratedBlock = /* @__PURE__ */ __name((hydratedBlock) => {
|
|
|
28
28
|
var flattenHydratedBlocks = /* @__PURE__ */ __name((hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk)), "flattenHydratedBlocks");
|
|
29
29
|
|
|
30
30
|
// src/block/hydrate/hydrateBlock.ts
|
|
31
|
-
import { assertEx as
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
assertEx2(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
35
|
-
assertEx2(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
36
|
-
assertEx2(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
37
|
-
const bw = assertEx2((await archivist.get([
|
|
38
|
-
hash
|
|
39
|
-
])).find(isBlockBoundWitnessWithStorageMeta), () => `block ${hash} not found`);
|
|
40
|
-
if (maxDepth === 0) return [
|
|
41
|
-
bw,
|
|
42
|
-
[]
|
|
43
|
-
];
|
|
44
|
-
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
45
|
-
if (minDepth === 1) assertEx2(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
46
|
-
if (maxDepth === 1) return [
|
|
47
|
-
bw,
|
|
48
|
-
blkPayloads
|
|
49
|
-
];
|
|
50
|
-
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta2);
|
|
51
|
-
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
52
|
-
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
53
|
-
assertEx2(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
54
|
-
const allPayloadsHashes = new Set([
|
|
55
|
-
...blkPayloads,
|
|
56
|
-
...transactionsPayloads
|
|
57
|
-
].flatMap((p) => p._hash));
|
|
58
|
-
const allPayloads = await archivist.get([
|
|
59
|
-
...allPayloadsHashes
|
|
60
|
-
]);
|
|
61
|
-
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
62
|
-
if (maxDepth === 2) assertEx2(allHashesPresent([
|
|
63
|
-
...allPayloadsHashes
|
|
64
|
-
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
65
|
-
return [
|
|
66
|
-
bw,
|
|
67
|
-
allPayloadsFiltered
|
|
68
|
-
];
|
|
69
|
-
}, "hydrateBlock");
|
|
70
|
-
|
|
71
|
-
// src/block/hydrate/transactionsFromHydratedBlock.ts
|
|
72
|
-
import { filterAs } from "@xylabs/array";
|
|
73
|
-
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
74
|
-
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
75
|
-
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
76
|
-
}, "transactionsFromHydratedBlock");
|
|
77
|
-
|
|
78
|
-
// src/block/hydrate/tryHydrateBlock.ts
|
|
79
|
-
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
80
|
-
import { isBlockBoundWitnessWithStorageMeta as isBlockBoundWitnessWithStorageMeta2, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta3 } from "@xyo-network/xl1-protocol";
|
|
81
|
-
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
82
|
-
assertEx3(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
83
|
-
const bw = (await archivist.get([
|
|
84
|
-
hash
|
|
85
|
-
])).find(isBlockBoundWitnessWithStorageMeta2);
|
|
86
|
-
if (!bw) return void 0;
|
|
87
|
-
if (maxDepth === 0) return [
|
|
88
|
-
bw,
|
|
89
|
-
[]
|
|
90
|
-
];
|
|
91
|
-
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
92
|
-
if (maxDepth === 1) return [
|
|
93
|
-
bw,
|
|
94
|
-
blkPayloads
|
|
95
|
-
];
|
|
96
|
-
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta3);
|
|
97
|
-
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
98
|
-
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
99
|
-
const allPayloadsHashes = new Set([
|
|
100
|
-
...blkPayloads,
|
|
101
|
-
...transactionsPayloads
|
|
102
|
-
].flatMap((p) => p._hash));
|
|
103
|
-
const allPayloads = await archivist.get([
|
|
104
|
-
...allPayloadsHashes
|
|
105
|
-
]);
|
|
106
|
-
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
107
|
-
return [
|
|
108
|
-
bw,
|
|
109
|
-
allPayloadsFiltered
|
|
110
|
-
];
|
|
111
|
-
}, "tryHydrateBlock");
|
|
31
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
32
|
+
import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
33
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
112
34
|
|
|
113
35
|
// src/block/primitives/balances/balancesStepSummaryFromRange.ts
|
|
114
|
-
import { assertEx as
|
|
36
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
115
37
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
116
38
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
117
39
|
import { StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol";
|
|
@@ -140,22 +62,17 @@ var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
|
140
62
|
import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
|
|
141
63
|
import { span as span2 } from "@xylabs/telemetry";
|
|
142
64
|
import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
|
|
143
|
-
function netTransfersForPayloads(payloads
|
|
65
|
+
function netTransfersForPayloads(payloads) {
|
|
144
66
|
return span2("netTransfersForPayloads", () => {
|
|
145
67
|
const transfers = {};
|
|
146
68
|
for (const payload of payloads) {
|
|
147
69
|
if (isTransfer2(payload)) {
|
|
148
70
|
const { from } = payload;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} else {
|
|
155
|
-
if (account === address) {
|
|
156
|
-
transfers[from] = (transfers[from] ?? 0n) - hexToBigInt2(amount);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
71
|
+
transfers[from] = transfers[from] ?? {};
|
|
72
|
+
for (let [to, amount] of Object.entries(payload.transfers)) {
|
|
73
|
+
transfers[to] = transfers[to] ?? {};
|
|
74
|
+
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt2(amount);
|
|
75
|
+
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt2(amount);
|
|
159
76
|
}
|
|
160
77
|
}
|
|
161
78
|
}
|
|
@@ -275,10 +192,9 @@ import { asHash } from "@xylabs/hex";
|
|
|
275
192
|
import { toSafeJsonString } from "@xylabs/object";
|
|
276
193
|
import { asBlockBoundWitnessWithStorageMeta, StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
277
194
|
async function blockFromBlockNumber(context, blockNumber) {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
let currentBlock = asBlockBoundWitnessWithStorageMeta(result.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
195
|
+
const head = await context.head();
|
|
196
|
+
const result = await context.store.chainMap.get(head);
|
|
197
|
+
let currentBlock = asBlockBoundWitnessWithStorageMeta(result, () => `Head block not found for hash: ${head}`, {
|
|
282
198
|
required: true
|
|
283
199
|
});
|
|
284
200
|
while (currentBlock.block > blockNumber) {
|
|
@@ -291,9 +207,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
291
207
|
jumpHash = asHash(currentBlock.step_hashes.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
292
208
|
}
|
|
293
209
|
}
|
|
294
|
-
const
|
|
295
|
-
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
296
|
-
]);
|
|
210
|
+
const newBlock = await context.store.chainMap.get(asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
|
|
297
211
|
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
298
212
|
required: true
|
|
299
213
|
});
|
|
@@ -343,26 +257,25 @@ var asTransfersStepSummaryWithStorageMeta = AsObjectFactory2.create(isTransfersS
|
|
|
343
257
|
async function balancesStepSummaryFromRange(context, range) {
|
|
344
258
|
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
345
259
|
const frameSize = range[1] - range[0] + 1;
|
|
260
|
+
const head = await context.head();
|
|
346
261
|
let result = void 0;
|
|
347
262
|
if (frameSize === 1) {
|
|
348
263
|
const hash = await hashFromBlockNumber(context, range[0]);
|
|
349
|
-
const [, payloads] = await hydrateBlock(context.
|
|
264
|
+
const [, payloads] = await hydrateBlock(context.store, hash);
|
|
350
265
|
const balances = {};
|
|
351
266
|
for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
|
|
352
267
|
balances[address] = toSignedBigInt(balance);
|
|
353
268
|
}
|
|
354
269
|
result = {
|
|
355
270
|
schema: BalancesStepSummarySchema,
|
|
356
|
-
hash:
|
|
271
|
+
hash: head,
|
|
357
272
|
stepSize: -1,
|
|
358
273
|
balances
|
|
359
274
|
};
|
|
360
275
|
} else {
|
|
361
276
|
const step = StepSizes3.indexOf(frameSize);
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
frameHeadHash
|
|
365
|
-
]);
|
|
277
|
+
assertEx2(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes3.join(", ")}`);
|
|
278
|
+
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
366
279
|
if (isAnyPayload(summaryResult)) {
|
|
367
280
|
result = summaryResult;
|
|
368
281
|
} else {
|
|
@@ -385,9 +298,7 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
385
298
|
stepSize: frameSize,
|
|
386
299
|
balances
|
|
387
300
|
};
|
|
388
|
-
await context.
|
|
389
|
-
result
|
|
390
|
-
]);
|
|
301
|
+
await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
|
|
391
302
|
}
|
|
392
303
|
}
|
|
393
304
|
const finalResult = await PayloadBuilder.addStorageMeta(result);
|
|
@@ -402,10 +313,9 @@ import { isDefined } from "@xylabs/typeof";
|
|
|
402
313
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
403
314
|
async function balancesSummary(context) {
|
|
404
315
|
return await spanRootAsync("balanceSummary", async () => {
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
316
|
+
const head = await context.head();
|
|
317
|
+
const headResult = await context.store.chainMap.get(head);
|
|
318
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${context.head}`, {
|
|
409
319
|
required: true
|
|
410
320
|
});
|
|
411
321
|
const rangeStart = isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0;
|
|
@@ -426,36 +336,42 @@ async function balancesSummary(context) {
|
|
|
426
336
|
}
|
|
427
337
|
__name(balancesSummary, "balancesSummary");
|
|
428
338
|
|
|
339
|
+
// src/block/primitives/model.ts
|
|
340
|
+
function isReadArchivist(obj) {
|
|
341
|
+
return obj.get !== void 0 && obj.next !== void 0;
|
|
342
|
+
}
|
|
343
|
+
__name(isReadArchivist, "isReadArchivist");
|
|
344
|
+
|
|
429
345
|
// src/block/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
430
|
-
import { assertEx as
|
|
346
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
431
347
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
432
348
|
import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
|
|
433
349
|
import { StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
|
|
434
350
|
async function transfersStepSummaryFromRange(context, range) {
|
|
435
351
|
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
436
352
|
const frameSize = range[1] - range[0] + 1;
|
|
437
|
-
const
|
|
353
|
+
const head = await context.head();
|
|
438
354
|
let result = void 0;
|
|
439
355
|
if (frameSize === 1) {
|
|
440
356
|
const hash = await hashFromBlockNumber(context, range[0]);
|
|
441
|
-
const [, payloads] = await hydrateBlock(context.
|
|
357
|
+
const [, payloads] = await hydrateBlock(context.store, hash);
|
|
442
358
|
const transfers = {};
|
|
443
|
-
for (const [
|
|
444
|
-
transfers[
|
|
359
|
+
for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
|
|
360
|
+
transfers[from] = transfers[from] ?? {};
|
|
361
|
+
for (const [to, amount] of Object.entries(toMap)) {
|
|
362
|
+
transfers[from][to] = toSignedBigInt(amount);
|
|
363
|
+
}
|
|
445
364
|
}
|
|
446
365
|
result = {
|
|
447
366
|
schema: TransfersStepSummarySchema,
|
|
448
|
-
hash:
|
|
367
|
+
hash: head,
|
|
449
368
|
stepSize: -1,
|
|
450
|
-
transfers
|
|
451
|
-
account
|
|
369
|
+
transfers
|
|
452
370
|
};
|
|
453
371
|
} else {
|
|
454
372
|
const step = StepSizes4.indexOf(frameSize);
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
frameHeadHash
|
|
458
|
-
]);
|
|
373
|
+
assertEx3(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes4.join(", ")}`);
|
|
374
|
+
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
459
375
|
if (isAnyPayload2(summaryResult)) {
|
|
460
376
|
result = summaryResult;
|
|
461
377
|
} else {
|
|
@@ -464,24 +380,27 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
464
380
|
const subResults = await Promise.all(promises);
|
|
465
381
|
const bigIntBalances = {};
|
|
466
382
|
for (const subResult of subResults) {
|
|
467
|
-
for (const [
|
|
468
|
-
bigIntBalances[
|
|
383
|
+
for (const [from, toMap] of Object.entries(subResult.transfers)) {
|
|
384
|
+
bigIntBalances[from] = bigIntBalances[from] ?? {};
|
|
385
|
+
for (const [to, transfer] of Object.entries(toMap)) {
|
|
386
|
+
bigIntBalances[from][to] = (bigIntBalances[from][to] ?? 0n) + parseSignedBigInt(transfer);
|
|
387
|
+
}
|
|
469
388
|
}
|
|
470
389
|
}
|
|
471
390
|
const transfers = {};
|
|
472
|
-
for (const [
|
|
473
|
-
transfers[
|
|
391
|
+
for (const [from, toMap] of Object.entries(bigIntBalances)) {
|
|
392
|
+
transfers[from] = transfers[from] ?? {};
|
|
393
|
+
for (const [to, transfer] of Object.entries(toMap)) {
|
|
394
|
+
transfers[from][to] = toSignedBigInt(transfer);
|
|
395
|
+
}
|
|
474
396
|
}
|
|
475
397
|
result = {
|
|
476
398
|
schema: TransfersStepSummarySchema,
|
|
477
399
|
hash: frameHeadHash,
|
|
478
400
|
stepSize: frameSize,
|
|
479
|
-
transfers
|
|
480
|
-
account
|
|
401
|
+
transfers
|
|
481
402
|
};
|
|
482
|
-
await context.
|
|
483
|
-
result
|
|
484
|
-
]);
|
|
403
|
+
await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
|
|
485
404
|
}
|
|
486
405
|
}
|
|
487
406
|
const finalResult = await PayloadBuilder2.addStorageMeta(result);
|
|
@@ -496,10 +415,9 @@ import { isDefined as isDefined2 } from "@xylabs/typeof";
|
|
|
496
415
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3 } from "@xyo-network/xl1-protocol";
|
|
497
416
|
async function transfersSummary(context) {
|
|
498
417
|
return await spanRootAsync2("transferSummary", async () => {
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
418
|
+
const head = await context.head();
|
|
419
|
+
const headResult = await context.store.chainMap.get(head);
|
|
420
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${context.head}`, {
|
|
503
421
|
required: true
|
|
504
422
|
});
|
|
505
423
|
const rangeStart = isDefined2(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0;
|
|
@@ -510,9 +428,13 @@ async function transfersSummary(context) {
|
|
|
510
428
|
const summaries = await Promise.all(ranges.map((range) => transfersStepSummaryFromRange(context, range)));
|
|
511
429
|
const transfers = {};
|
|
512
430
|
for (let summary of summaries) {
|
|
513
|
-
for (const [
|
|
514
|
-
const
|
|
515
|
-
transfers[
|
|
431
|
+
for (const [from, toMap] of Object.entries(summary.transfers)) {
|
|
432
|
+
const validFrom = asAddress2(from, () => `Invalid address: ${from}`);
|
|
433
|
+
transfers[validFrom] = transfers[validFrom] ?? {};
|
|
434
|
+
for (const [to, transfer] of Object.entries(toMap)) {
|
|
435
|
+
const validTo = asAddress2(to, () => `Invalid address: ${to}`);
|
|
436
|
+
transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer);
|
|
437
|
+
}
|
|
516
438
|
}
|
|
517
439
|
}
|
|
518
440
|
return transfers;
|
|
@@ -520,8 +442,108 @@ async function transfersSummary(context) {
|
|
|
520
442
|
}
|
|
521
443
|
__name(transfersSummary, "transfersSummary");
|
|
522
444
|
|
|
445
|
+
// src/block/hydrate/hydrateBlock.ts
|
|
446
|
+
function readPayloadMapFromStore(store) {
|
|
447
|
+
if (isReadArchivist(store)) {
|
|
448
|
+
return {
|
|
449
|
+
get: /* @__PURE__ */ __name(async (hash) => {
|
|
450
|
+
return (await store.get([
|
|
451
|
+
hash
|
|
452
|
+
]))[0];
|
|
453
|
+
}, "get"),
|
|
454
|
+
getMany: /* @__PURE__ */ __name(async (hashes) => {
|
|
455
|
+
return await store.get(hashes);
|
|
456
|
+
}, "getMany"),
|
|
457
|
+
has: /* @__PURE__ */ __name(async (hash) => {
|
|
458
|
+
return isDefined3((await store.get([
|
|
459
|
+
hash
|
|
460
|
+
]))[0]);
|
|
461
|
+
}, "has")
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
return store;
|
|
465
|
+
}
|
|
466
|
+
__name(readPayloadMapFromStore, "readPayloadMapFromStore");
|
|
467
|
+
var hydrateBlock = /* @__PURE__ */ __name(async ({ chainMap }, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
468
|
+
assertEx4(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
469
|
+
assertEx4(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
470
|
+
assertEx4(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
471
|
+
const bw = assertEx4(asBlockBoundWitnessWithStorageMeta4(assertEx4(await chainMap.get(hash), () => `block ${hash} not found`)), () => `hash ${hash} is not a BlockBoundWitness`);
|
|
472
|
+
if (maxDepth === 0) return [
|
|
473
|
+
bw,
|
|
474
|
+
[]
|
|
475
|
+
];
|
|
476
|
+
const blkPayloads = await chainMap.getMany(bw.payload_hashes);
|
|
477
|
+
if (minDepth === 1) assertEx4(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
478
|
+
if (maxDepth === 1) return [
|
|
479
|
+
bw,
|
|
480
|
+
blkPayloads
|
|
481
|
+
];
|
|
482
|
+
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta2);
|
|
483
|
+
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
484
|
+
const transactionsPayloads = await chainMap.getMany(transactionsPayloadHashes);
|
|
485
|
+
assertEx4(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
486
|
+
const allPayloadsHashes = new Set([
|
|
487
|
+
...blkPayloads,
|
|
488
|
+
...transactionsPayloads
|
|
489
|
+
].flatMap((p) => p._hash));
|
|
490
|
+
const allPayloads = await chainMap.getMany([
|
|
491
|
+
...allPayloadsHashes
|
|
492
|
+
]);
|
|
493
|
+
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
494
|
+
if (maxDepth === 2) assertEx4(allHashesPresent([
|
|
495
|
+
...allPayloadsHashes
|
|
496
|
+
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
497
|
+
return [
|
|
498
|
+
bw,
|
|
499
|
+
allPayloadsFiltered
|
|
500
|
+
];
|
|
501
|
+
}, "hydrateBlock");
|
|
502
|
+
|
|
503
|
+
// src/block/hydrate/transactionsFromHydratedBlock.ts
|
|
504
|
+
import { filterAs } from "@xylabs/array";
|
|
505
|
+
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
506
|
+
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
507
|
+
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
508
|
+
}, "transactionsFromHydratedBlock");
|
|
509
|
+
|
|
510
|
+
// src/block/hydrate/tryHydrateBlock.ts
|
|
511
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
512
|
+
import { isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta3 } from "@xyo-network/xl1-protocol";
|
|
513
|
+
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
514
|
+
assertEx5(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
515
|
+
const bw = (await archivist.get([
|
|
516
|
+
hash
|
|
517
|
+
])).find(isBlockBoundWitnessWithStorageMeta);
|
|
518
|
+
if (!bw) return void 0;
|
|
519
|
+
if (maxDepth === 0) return [
|
|
520
|
+
bw,
|
|
521
|
+
[]
|
|
522
|
+
];
|
|
523
|
+
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
524
|
+
if (maxDepth === 1) return [
|
|
525
|
+
bw,
|
|
526
|
+
blkPayloads
|
|
527
|
+
];
|
|
528
|
+
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta3);
|
|
529
|
+
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
530
|
+
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
531
|
+
const allPayloadsHashes = new Set([
|
|
532
|
+
...blkPayloads,
|
|
533
|
+
...transactionsPayloads
|
|
534
|
+
].flatMap((p) => p._hash));
|
|
535
|
+
const allPayloads = await archivist.get([
|
|
536
|
+
...allPayloadsHashes
|
|
537
|
+
]);
|
|
538
|
+
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
539
|
+
return [
|
|
540
|
+
bw,
|
|
541
|
+
allPayloadsFiltered
|
|
542
|
+
];
|
|
543
|
+
}, "tryHydrateBlock");
|
|
544
|
+
|
|
523
545
|
// src/config/Config.ts
|
|
524
|
-
import * as
|
|
546
|
+
import * as z12 from "zod";
|
|
525
547
|
|
|
526
548
|
// src/config/Api.ts
|
|
527
549
|
import { globalRegistry } from "zod";
|
|
@@ -586,11 +608,34 @@ var AppConfigZod = z3.object({
|
|
|
586
608
|
})
|
|
587
609
|
});
|
|
588
610
|
|
|
589
|
-
// src/config/
|
|
611
|
+
// src/config/Bridge.ts
|
|
590
612
|
import { globalRegistry as globalRegistry3 } from "zod";
|
|
591
613
|
import * as z4 from "zod";
|
|
592
|
-
var
|
|
593
|
-
|
|
614
|
+
var BridgeConfigZod = z4.object({
|
|
615
|
+
host: z4.string().default("localhost").register(globalRegistry3, {
|
|
616
|
+
default: "localhost",
|
|
617
|
+
description: "Host for the Bridge",
|
|
618
|
+
title: "api.host",
|
|
619
|
+
type: "string"
|
|
620
|
+
}),
|
|
621
|
+
mnemonic: MnemonicStringZod.optional().register(globalRegistry3, {
|
|
622
|
+
description: "Mnemonic for the Bridge wallet",
|
|
623
|
+
title: "api.mnemonic",
|
|
624
|
+
type: "string"
|
|
625
|
+
}),
|
|
626
|
+
port: z4.coerce.number().default(8081).register(globalRegistry3, {
|
|
627
|
+
default: 8081,
|
|
628
|
+
description: "Port for the Bridge",
|
|
629
|
+
title: "api.port",
|
|
630
|
+
type: "number"
|
|
631
|
+
})
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// src/config/Chain.ts
|
|
635
|
+
import { globalRegistry as globalRegistry4 } from "zod";
|
|
636
|
+
import * as z5 from "zod";
|
|
637
|
+
var ChainConfigZod = z5.object({
|
|
638
|
+
id: z5.string().optional().register(globalRegistry4, {
|
|
594
639
|
description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
|
|
595
640
|
title: "chain.id",
|
|
596
641
|
type: "string"
|
|
@@ -598,29 +643,29 @@ var ChainConfigZod = z4.object({
|
|
|
598
643
|
});
|
|
599
644
|
|
|
600
645
|
// src/config/Evm.ts
|
|
601
|
-
import { globalRegistry as
|
|
602
|
-
import * as
|
|
603
|
-
var EvmInfuraConfigZod =
|
|
604
|
-
projectId:
|
|
646
|
+
import { globalRegistry as globalRegistry5 } from "zod";
|
|
647
|
+
import * as z6 from "zod";
|
|
648
|
+
var EvmInfuraConfigZod = z6.object({
|
|
649
|
+
projectId: z6.string().optional().register(globalRegistry5, {
|
|
605
650
|
description: "Infura project ID",
|
|
606
651
|
title: "evm.infura.projectId",
|
|
607
652
|
type: "string"
|
|
608
653
|
}),
|
|
609
|
-
projectSecret:
|
|
654
|
+
projectSecret: z6.string().optional().register(globalRegistry5, {
|
|
610
655
|
description: "Infura project secret",
|
|
611
656
|
title: "evm.infura.projectSecret",
|
|
612
657
|
type: "string"
|
|
613
658
|
})
|
|
614
659
|
});
|
|
615
|
-
var EvmJsonRpcConfigZod =
|
|
616
|
-
url:
|
|
660
|
+
var EvmJsonRpcConfigZod = z6.object({
|
|
661
|
+
url: z6.url().optional().register(globalRegistry5, {
|
|
617
662
|
description: "JSON-RPC URL",
|
|
618
663
|
title: "evm.jsonRpc.url",
|
|
619
664
|
type: "string"
|
|
620
665
|
})
|
|
621
666
|
});
|
|
622
|
-
var EvmConfigZod =
|
|
623
|
-
chainId:
|
|
667
|
+
var EvmConfigZod = z6.object({
|
|
668
|
+
chainId: z6.string().optional().register(globalRegistry5, {
|
|
624
669
|
description: "EVM chain ID",
|
|
625
670
|
title: "evm.chainId",
|
|
626
671
|
type: "string"
|
|
@@ -631,18 +676,18 @@ var EvmConfigZod = z5.object({
|
|
|
631
676
|
|
|
632
677
|
// src/config/Log.ts
|
|
633
678
|
import { LogLevel } from "@xylabs/logger";
|
|
634
|
-
import { globalRegistry as
|
|
635
|
-
import * as
|
|
679
|
+
import { globalRegistry as globalRegistry6 } from "zod";
|
|
680
|
+
import * as z7 from "zod";
|
|
636
681
|
var LogLevels = Object.keys(LogLevel);
|
|
637
|
-
var LogConfigZod =
|
|
638
|
-
logLevel:
|
|
682
|
+
var LogConfigZod = z7.object({
|
|
683
|
+
logLevel: z7.enum(LogLevels).default("info").register(globalRegistry6, {
|
|
639
684
|
choices: LogLevels,
|
|
640
685
|
default: "info",
|
|
641
686
|
description: "Desired process verbosity",
|
|
642
687
|
title: "logLevel",
|
|
643
688
|
type: "string"
|
|
644
689
|
}),
|
|
645
|
-
silent:
|
|
690
|
+
silent: z7.boolean().default(false).register(globalRegistry6, {
|
|
646
691
|
default: false,
|
|
647
692
|
description: "Whether to run in silent mode",
|
|
648
693
|
title: "silent",
|
|
@@ -652,55 +697,55 @@ var LogConfigZod = z6.object({
|
|
|
652
697
|
|
|
653
698
|
// src/config/Producer.ts
|
|
654
699
|
import { AddressZod, asAddress as asAddress3 } from "@xylabs/hex";
|
|
655
|
-
import { globalRegistry as
|
|
656
|
-
import * as
|
|
657
|
-
var ProducerConfigZod =
|
|
658
|
-
allowlist:
|
|
700
|
+
import { globalRegistry as globalRegistry7 } from "zod";
|
|
701
|
+
import * as z8 from "zod";
|
|
702
|
+
var ProducerConfigZod = z8.object({
|
|
703
|
+
allowlist: z8.preprocess((val) => {
|
|
659
704
|
if (typeof val === "string") {
|
|
660
705
|
return val.split(",").map((s) => asAddress3(s.trim()));
|
|
661
706
|
}
|
|
662
707
|
return val;
|
|
663
|
-
},
|
|
708
|
+
}, z8.array(AddressZod).optional().register(globalRegistry7, {
|
|
664
709
|
description: "List of allowed producer addresses, if undefined anyone can participate",
|
|
665
710
|
title: "allowlist",
|
|
666
711
|
type: "array"
|
|
667
712
|
})),
|
|
668
|
-
disableIntentRedeclaration:
|
|
713
|
+
disableIntentRedeclaration: z8.boolean().optional().register(globalRegistry7, {
|
|
669
714
|
description: "Should the producer skip redeclaring their intent to continue producing blocks",
|
|
670
715
|
title: "producer.disableIntentRedeclaration",
|
|
671
716
|
type: "boolean"
|
|
672
717
|
}),
|
|
673
718
|
// TODO: Port schema
|
|
674
|
-
healthCheckPort:
|
|
719
|
+
healthCheckPort: z8.coerce.number().optional().register(globalRegistry7, {
|
|
675
720
|
description: "Port for the Producer health checks",
|
|
676
721
|
title: "producer.healthCheckPort",
|
|
677
722
|
type: "number"
|
|
678
723
|
}),
|
|
679
|
-
heartbeatInterval:
|
|
724
|
+
heartbeatInterval: z8.coerce.number().default(36e5).register(globalRegistry7, {
|
|
680
725
|
description: "The number of milliseconds between heartbeats if no blocks are produced",
|
|
681
726
|
title: "producer.heartbeatInterval",
|
|
682
727
|
type: "number"
|
|
683
728
|
}),
|
|
684
729
|
// TODO: BigInt schema
|
|
685
|
-
minStake:
|
|
730
|
+
minStake: z8.coerce.number().default(1).register(globalRegistry7, {
|
|
686
731
|
description: "Minimum stake required to be a Producer",
|
|
687
732
|
title: "producer.minStake",
|
|
688
733
|
type: "number"
|
|
689
734
|
}),
|
|
690
|
-
mnemonic: MnemonicStringZod.optional().register(
|
|
735
|
+
mnemonic: MnemonicStringZod.optional().register(globalRegistry7, {
|
|
691
736
|
description: "Mnemonic for the Producer wallet",
|
|
692
737
|
title: "producer.mnemonic",
|
|
693
738
|
type: "string"
|
|
694
739
|
}),
|
|
695
740
|
// TODO: Port schema
|
|
696
|
-
port:
|
|
741
|
+
port: z8.coerce.number().default(8081).register(globalRegistry7, {
|
|
697
742
|
default: 8081,
|
|
698
743
|
description: "Port for the Producer",
|
|
699
744
|
title: "producer.port",
|
|
700
745
|
type: "number"
|
|
701
746
|
}),
|
|
702
747
|
// TODO: Address schema
|
|
703
|
-
rewardAddress:
|
|
748
|
+
rewardAddress: z8.string().optional().register(globalRegistry7, {
|
|
704
749
|
description: "Address to receive block rewards",
|
|
705
750
|
title: "producer.rewardAddress",
|
|
706
751
|
type: "string"
|
|
@@ -708,36 +753,36 @@ var ProducerConfigZod = z7.object({
|
|
|
708
753
|
});
|
|
709
754
|
|
|
710
755
|
// src/config/storage/driver/Mongo.ts
|
|
711
|
-
import { isDefined as
|
|
712
|
-
import { globalRegistry as
|
|
713
|
-
import * as
|
|
756
|
+
import { isDefined as isDefined4, isUndefined } from "@xylabs/typeof";
|
|
757
|
+
import { globalRegistry as globalRegistry8 } from "zod";
|
|
758
|
+
import * as z9 from "zod";
|
|
714
759
|
var hasMongoConfig = /* @__PURE__ */ __name((config) => {
|
|
715
760
|
if (isUndefined(config)) return false;
|
|
716
|
-
return
|
|
761
|
+
return isDefined4(config.connectionString) && isDefined4(config.database) && isDefined4(config.domain) && isDefined4(config.password) && isDefined4(config.username);
|
|
717
762
|
}, "hasMongoConfig");
|
|
718
|
-
var MongoConfigZod =
|
|
763
|
+
var MongoConfigZod = z9.object({
|
|
719
764
|
// TODO: Create from other arguments
|
|
720
|
-
connectionString:
|
|
765
|
+
connectionString: z9.string().min(1).optional().register(globalRegistry8, {
|
|
721
766
|
description: "MongoDB connection string",
|
|
722
767
|
title: "storage.mongo.connectionString",
|
|
723
768
|
type: "string"
|
|
724
769
|
}),
|
|
725
|
-
database:
|
|
770
|
+
database: z9.string().min(1).optional().register(globalRegistry8, {
|
|
726
771
|
description: "MongoDB database name",
|
|
727
772
|
title: "storage.mongo.database",
|
|
728
773
|
type: "string"
|
|
729
774
|
}),
|
|
730
|
-
domain:
|
|
775
|
+
domain: z9.string().min(1).optional().register(globalRegistry8, {
|
|
731
776
|
description: "MongoDB domain",
|
|
732
777
|
title: "storage.mongo.domain",
|
|
733
778
|
type: "string"
|
|
734
779
|
}),
|
|
735
|
-
password:
|
|
780
|
+
password: z9.string().min(1).optional().register(globalRegistry8, {
|
|
736
781
|
description: "MongoDB password",
|
|
737
782
|
title: "storage.mongo.password",
|
|
738
783
|
type: "string"
|
|
739
784
|
}),
|
|
740
|
-
username:
|
|
785
|
+
username: z9.string().min(1).optional().register(globalRegistry8, {
|
|
741
786
|
description: "MongoDB username",
|
|
742
787
|
title: "storage.mongo.username",
|
|
743
788
|
type: "string"
|
|
@@ -745,11 +790,11 @@ var MongoConfigZod = z8.object({
|
|
|
745
790
|
});
|
|
746
791
|
|
|
747
792
|
// src/config/storage/Storage.ts
|
|
748
|
-
import { globalRegistry as
|
|
749
|
-
import * as
|
|
750
|
-
var StorageConfigZod =
|
|
793
|
+
import { globalRegistry as globalRegistry9 } from "zod";
|
|
794
|
+
import * as z10 from "zod";
|
|
795
|
+
var StorageConfigZod = z10.object({
|
|
751
796
|
mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
|
|
752
|
-
root:
|
|
797
|
+
root: z10.string().optional().register(globalRegistry9, {
|
|
753
798
|
description: "Root directory for local storage",
|
|
754
799
|
title: "storage.root",
|
|
755
800
|
type: "string"
|
|
@@ -757,29 +802,30 @@ var StorageConfigZod = z9.object({
|
|
|
757
802
|
}).describe("Storage configuration options");
|
|
758
803
|
|
|
759
804
|
// src/config/Telemetry.ts
|
|
760
|
-
import { globalRegistry as
|
|
761
|
-
import * as
|
|
762
|
-
var OpenTelemetryConfigZod =
|
|
805
|
+
import { globalRegistry as globalRegistry10 } from "zod";
|
|
806
|
+
import * as z11 from "zod";
|
|
807
|
+
var OpenTelemetryConfigZod = z11.object({
|
|
763
808
|
// OpenTelemetry options
|
|
764
|
-
otlpEndpoint:
|
|
809
|
+
otlpEndpoint: z11.url().optional().register(globalRegistry10, {
|
|
765
810
|
description: "OTLP endpoint for exporting telemetry data",
|
|
766
811
|
title: "telemetry.otel.otlpEndpoint",
|
|
767
812
|
type: "string"
|
|
768
813
|
})
|
|
769
814
|
});
|
|
770
|
-
var TelemetryConfigZod =
|
|
815
|
+
var TelemetryConfigZod = z11.object({
|
|
771
816
|
// OpenTelemetry configuration
|
|
772
817
|
otel: OpenTelemetryConfigZod.optional().describe("OpenTelemetry configuration")
|
|
773
818
|
}).describe("Telemetry configuration options");
|
|
774
819
|
|
|
775
820
|
// src/config/Config.ts
|
|
776
|
-
var Xl1CommonConfigSchema =
|
|
821
|
+
var Xl1CommonConfigSchema = z12.object({
|
|
777
822
|
...LogConfigZod.shape
|
|
778
823
|
}).describe("XL1 common configuration options");
|
|
779
|
-
var ConfigZod =
|
|
824
|
+
var ConfigZod = z12.object({
|
|
780
825
|
...Xl1CommonConfigSchema.shape,
|
|
781
826
|
api: ApiConfigZod.default(ApiConfigZod.parse({})).describe("Configuration for the API node"),
|
|
782
827
|
app: AppConfigZod.default(AppConfigZod.parse({})).describe("Configuration for the application"),
|
|
828
|
+
bridge: BridgeConfigZod.default(BridgeConfigZod.parse({})).describe("Configuration for the Bridge node"),
|
|
783
829
|
chain: ChainConfigZod.default(ChainConfigZod.parse({})).describe("Configuration for the chain"),
|
|
784
830
|
evm: EvmConfigZod.default(EvmConfigZod.parse({})).describe("Configuration for EVM-backed services"),
|
|
785
831
|
producer: ProducerConfigZod.default(ProducerConfigZod.parse({})).describe("Configuration for the producer"),
|
|
@@ -789,35 +835,35 @@ var ConfigZod = z11.object({
|
|
|
789
835
|
var getDefaultConfig = /* @__PURE__ */ __name(() => ConfigZod.parse({}), "getDefaultConfig");
|
|
790
836
|
|
|
791
837
|
// src/config/UsageMeta.ts
|
|
792
|
-
import * as
|
|
793
|
-
var DescriptionSchema =
|
|
794
|
-
var TitleSchema =
|
|
795
|
-
var JSONSchemaMetaSchema =
|
|
796
|
-
id:
|
|
838
|
+
import * as z13 from "zod";
|
|
839
|
+
var DescriptionSchema = z13.string();
|
|
840
|
+
var TitleSchema = z13.string();
|
|
841
|
+
var JSONSchemaMetaSchema = z13.object({
|
|
842
|
+
id: z13.string().optional(),
|
|
797
843
|
title: TitleSchema.optional(),
|
|
798
844
|
description: DescriptionSchema.optional(),
|
|
799
|
-
deprecated:
|
|
800
|
-
}).catchall(
|
|
845
|
+
deprecated: z13.boolean().optional()
|
|
846
|
+
}).catchall(z13.unknown());
|
|
801
847
|
var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
|
|
802
|
-
var ChoicesSchema =
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
848
|
+
var ChoicesSchema = z13.array(z13.union([
|
|
849
|
+
z13.string(),
|
|
850
|
+
z13.number(),
|
|
851
|
+
z13.literal(true),
|
|
852
|
+
z13.undefined()
|
|
807
853
|
])).readonly();
|
|
808
854
|
var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
809
855
|
choices: ChoicesSchema.optional(),
|
|
810
|
-
default:
|
|
856
|
+
default: z13.unknown().optional(),
|
|
811
857
|
description: DescriptionSchema,
|
|
812
|
-
group:
|
|
813
|
-
hidden:
|
|
858
|
+
group: z13.string().optional(),
|
|
859
|
+
hidden: z13.boolean().optional(),
|
|
814
860
|
title: TitleSchema,
|
|
815
|
-
type:
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
861
|
+
type: z13.union([
|
|
862
|
+
z13.literal("array"),
|
|
863
|
+
z13.literal("count"),
|
|
864
|
+
z13.literal("boolean"),
|
|
865
|
+
z13.literal("number"),
|
|
866
|
+
z13.literal("string")
|
|
821
867
|
])
|
|
822
868
|
});
|
|
823
869
|
function isUsageMeta(v) {
|
|
@@ -825,6 +871,13 @@ function isUsageMeta(v) {
|
|
|
825
871
|
}
|
|
826
872
|
__name(isUsageMeta, "isUsageMeta");
|
|
827
873
|
|
|
874
|
+
// src/model/StakeEvents.ts
|
|
875
|
+
var StakeEventNames = [
|
|
876
|
+
"StakeAdded",
|
|
877
|
+
"StakeRemoved",
|
|
878
|
+
"StakeWithdrawn"
|
|
879
|
+
];
|
|
880
|
+
|
|
828
881
|
// src/steps/primitives/addressStakeWeight.ts
|
|
829
882
|
import { toAddress as toAddress2 } from "@xylabs/hex";
|
|
830
883
|
import { XYO_NETWORK_STAKING_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
@@ -879,70 +932,6 @@ function claimedRewards(_address) {
|
|
|
879
932
|
}
|
|
880
933
|
__name(claimedRewards, "claimedRewards");
|
|
881
934
|
|
|
882
|
-
// src/steps/primitives/networkStakeStepAddressReward.ts
|
|
883
|
-
function networkStakeStepAddressReward(address, _step, _block) {
|
|
884
|
-
return {
|
|
885
|
-
[address]: 0n
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
__name(networkStakeStepAddressReward, "networkStakeStepAddressReward");
|
|
889
|
-
|
|
890
|
-
// src/steps/primitives/networkStakeStepPoolRewards.ts
|
|
891
|
-
function networkStakeStepPoolRewards(_step, _block) {
|
|
892
|
-
return {};
|
|
893
|
-
}
|
|
894
|
-
__name(networkStakeStepPoolRewards, "networkStakeStepPoolRewards");
|
|
895
|
-
|
|
896
|
-
// src/steps/primitives/networkStakeStepPoolRewardShares.ts
|
|
897
|
-
function networkStakeStepPoolRewardShares(_step, _block) {
|
|
898
|
-
return {};
|
|
899
|
-
}
|
|
900
|
-
__name(networkStakeStepPoolRewardShares, "networkStakeStepPoolRewardShares");
|
|
901
|
-
|
|
902
|
-
// src/steps/primitives/networkStakeStepRewardAddressHistory.ts
|
|
903
|
-
function networkStakeStepRewardAddressHistory(address) {
|
|
904
|
-
return {
|
|
905
|
-
[address]: 0n
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
__name(networkStakeStepRewardAddressHistory, "networkStakeStepRewardAddressHistory");
|
|
909
|
-
|
|
910
|
-
// src/steps/primitives/networkStakeStepRewardAddressShare.ts
|
|
911
|
-
function networkStakeStepRewardAddressShare(_address, _step, _block) {
|
|
912
|
-
throw new Error("Method not implemented.");
|
|
913
|
-
}
|
|
914
|
-
__name(networkStakeStepRewardAddressShare, "networkStakeStepRewardAddressShare");
|
|
915
|
-
|
|
916
|
-
// src/steps/primitives/networkStakeStepRewardForStep.ts
|
|
917
|
-
function networkStakeStepRewardForStep(_step) {
|
|
918
|
-
return 0n;
|
|
919
|
-
}
|
|
920
|
-
__name(networkStakeStepRewardForStep, "networkStakeStepRewardForStep");
|
|
921
|
-
|
|
922
|
-
// src/steps/primitives/networkStakeStepRewardPositionWeight.ts
|
|
923
|
-
function networkStakeStepRewardPositionWeight(_position, _step) {
|
|
924
|
-
throw new Error("Method not implemented.");
|
|
925
|
-
}
|
|
926
|
-
__name(networkStakeStepRewardPositionWeight, "networkStakeStepRewardPositionWeight");
|
|
927
|
-
|
|
928
|
-
// src/steps/primitives/networkStakeStepRewardPotentialPositionLoss.ts
|
|
929
|
-
function networkStakeStepRewardPotentialPositionLoss(_position, _step) {
|
|
930
|
-
throw new Error("Method not implemented.");
|
|
931
|
-
}
|
|
932
|
-
__name(networkStakeStepRewardPotentialPositionLoss, "networkStakeStepRewardPotentialPositionLoss");
|
|
933
|
-
|
|
934
|
-
// src/steps/primitives/networkStakeStepRewardRandomizer.ts
|
|
935
|
-
function networkStakeStepRewardRandomizer(_step, _block) {
|
|
936
|
-
throw new Error("Method not implemented.");
|
|
937
|
-
}
|
|
938
|
-
__name(networkStakeStepRewardRandomizer, "networkStakeStepRewardRandomizer");
|
|
939
|
-
|
|
940
|
-
// src/steps/primitives/networkStakeStepRewardWeightForAddress.ts
|
|
941
|
-
function networkStakeStepRewardWeightForAddress(_address, _step) {
|
|
942
|
-
throw new Error("Method not implemented.");
|
|
943
|
-
}
|
|
944
|
-
__name(networkStakeStepRewardWeightForAddress, "networkStakeStepRewardWeightForAddress");
|
|
945
|
-
|
|
946
935
|
// src/steps/primitives/stakersAsOfBlock.ts
|
|
947
936
|
import { toAddress as toAddress4 } from "@xylabs/hex";
|
|
948
937
|
|
|
@@ -1038,7 +1027,7 @@ import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
|
1038
1027
|
import { asTimePayload, TimeSchema } from "@xyo-network/xl1-protocol";
|
|
1039
1028
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
1040
1029
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
1041
|
-
const hydratedBlock = await hydrateBlock(context.
|
|
1030
|
+
const hydratedBlock = await hydrateBlock(context.store, blockHash);
|
|
1042
1031
|
const timePayload = asTimePayload(hydratedBlock[1].find((p) => p.schema === TimeSchema), {
|
|
1043
1032
|
required: true
|
|
1044
1033
|
});
|
|
@@ -1138,7 +1127,7 @@ __name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
|
1138
1127
|
|
|
1139
1128
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
1140
1129
|
import { delay } from "@xylabs/delay";
|
|
1141
|
-
import { isDefined as
|
|
1130
|
+
import { isDefined as isDefined5 } from "@xylabs/typeof";
|
|
1142
1131
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1143
1132
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
1144
1133
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
@@ -1149,7 +1138,7 @@ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, transact
|
|
|
1149
1138
|
let attempts = 0;
|
|
1150
1139
|
while (true) {
|
|
1151
1140
|
const tx = await viewer.transactionByHash(txBWHash) ?? void 0;
|
|
1152
|
-
if (
|
|
1141
|
+
if (isDefined5(tx)) {
|
|
1153
1142
|
options?.logger?.log("\u2705 Transaction confirmed:", txBWHash, "\n");
|
|
1154
1143
|
return tx;
|
|
1155
1144
|
} else {
|
|
@@ -1169,11 +1158,25 @@ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, transact
|
|
|
1169
1158
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
1170
1159
|
import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
|
|
1171
1160
|
import { isAllowedBlockPayload, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1172
|
-
var tryHydrateTransaction = /* @__PURE__ */ __name(async (
|
|
1173
|
-
return await tryHydrateTypedBoundWitness(
|
|
1161
|
+
var tryHydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
|
|
1162
|
+
return await tryHydrateTypedBoundWitness({
|
|
1163
|
+
get(hashes) {
|
|
1164
|
+
return chainMap.getMany(hashes);
|
|
1165
|
+
},
|
|
1166
|
+
next() {
|
|
1167
|
+
throw new Error("Not implemented");
|
|
1168
|
+
}
|
|
1169
|
+
}, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
1174
1170
|
}, "tryHydrateTransaction");
|
|
1175
|
-
var hydrateTransaction = /* @__PURE__ */ __name(async (
|
|
1176
|
-
return await hydrateTypedBoundWitness(
|
|
1171
|
+
var hydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
|
|
1172
|
+
return await hydrateTypedBoundWitness({
|
|
1173
|
+
get(hashes) {
|
|
1174
|
+
return chainMap.getMany(hashes);
|
|
1175
|
+
},
|
|
1176
|
+
next() {
|
|
1177
|
+
throw new Error("Not implemented");
|
|
1178
|
+
}
|
|
1179
|
+
}, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
1177
1180
|
}, "hydrateTransaction");
|
|
1178
1181
|
var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) => {
|
|
1179
1182
|
const [tx, txPayloads] = hydratedTransaction;
|
|
@@ -1183,8 +1186,10 @@ var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) =>
|
|
|
1183
1186
|
];
|
|
1184
1187
|
}, "flattenHydratedTransaction");
|
|
1185
1188
|
var flattenHydratedTransactions = /* @__PURE__ */ __name((hydratedTransactions) => hydratedTransactions.flatMap((tx) => flattenHydratedTransaction(tx)), "flattenHydratedTransactions");
|
|
1186
|
-
var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async (
|
|
1187
|
-
const hydratedTransaction = await tryHydrateTransaction(
|
|
1189
|
+
var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
|
|
1190
|
+
const hydratedTransaction = await tryHydrateTransaction({
|
|
1191
|
+
chainMap
|
|
1192
|
+
}, hash);
|
|
1188
1193
|
if (!hydratedTransaction) {
|
|
1189
1194
|
return void 0;
|
|
1190
1195
|
}
|
|
@@ -1208,8 +1213,8 @@ var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async (archivist, has
|
|
|
1208
1213
|
}
|
|
1209
1214
|
return void 0;
|
|
1210
1215
|
}, "tryHydrateElevatedTransaction");
|
|
1211
|
-
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (
|
|
1212
|
-
return assertEx8(await tryHydrateElevatedTransaction(
|
|
1216
|
+
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) => {
|
|
1217
|
+
return assertEx8(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
|
|
1213
1218
|
}, "hydrateElevatedTransaction");
|
|
1214
1219
|
|
|
1215
1220
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
@@ -1365,6 +1370,7 @@ export {
|
|
|
1365
1370
|
GlobalMetaSchema,
|
|
1366
1371
|
JSONSchemaMetaSchema,
|
|
1367
1372
|
MnemonicStringZod,
|
|
1373
|
+
StakeEventNames,
|
|
1368
1374
|
StepSummarySchema,
|
|
1369
1375
|
TODO,
|
|
1370
1376
|
TransfersStepSummarySchema,
|
|
@@ -1408,22 +1414,14 @@ export {
|
|
|
1408
1414
|
isLocalhost,
|
|
1409
1415
|
isNegativeBigInt,
|
|
1410
1416
|
isPositiveBigInt,
|
|
1417
|
+
isReadArchivist,
|
|
1411
1418
|
isTransfersStepSummary,
|
|
1412
1419
|
isTransfersStepSummaryWithStorageMeta,
|
|
1413
1420
|
isUsageMeta,
|
|
1414
1421
|
netBalancesForPayloads,
|
|
1415
1422
|
netTransfersForPayloads,
|
|
1416
|
-
networkStakeStepAddressReward,
|
|
1417
|
-
networkStakeStepPoolRewardShares,
|
|
1418
|
-
networkStakeStepPoolRewards,
|
|
1419
|
-
networkStakeStepRewardAddressHistory,
|
|
1420
|
-
networkStakeStepRewardAddressShare,
|
|
1421
|
-
networkStakeStepRewardForStep,
|
|
1422
|
-
networkStakeStepRewardPositionWeight,
|
|
1423
|
-
networkStakeStepRewardPotentialPositionLoss,
|
|
1424
|
-
networkStakeStepRewardRandomizer,
|
|
1425
|
-
networkStakeStepRewardWeightForAddress,
|
|
1426
1423
|
parseSignedBigInt,
|
|
1424
|
+
readPayloadMapFromStore,
|
|
1427
1425
|
signTransaction,
|
|
1428
1426
|
stakersAsOfBlock,
|
|
1429
1427
|
startingStakes,
|