@xyo-network/xl1-protocol-sdk 1.18.0-rc.1 → 1.18.0
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/CreatableProvider/AbstractCreatableProvider.d.ts +6 -5
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +5 -5
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +2 -2
- package/dist/neutral/config/Services.d.ts +2 -2
- package/dist/neutral/config/Services.d.ts.map +1 -1
- package/dist/neutral/index.mjs +537 -211
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/ChainQualification.d.ts +42 -0
- package/dist/neutral/model/ChainQualification.d.ts.map +1 -0
- package/dist/neutral/model/index.d.ts +1 -1
- package/dist/neutral/model/index.d.ts.map +1 -1
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts +26 -0
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/index.d.ts +1 -0
- package/dist/neutral/primitives/chain/index.d.ts.map +1 -1
- package/dist/neutral/primitives/index.d.ts +1 -0
- package/dist/neutral/primitives/index.d.ts.map +1 -1
- package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts +1 -1
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts +24 -0
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts +26 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/index.d.ts +4 -0
- package/dist/neutral/primitives/uncle/index.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/scoreUncle.d.ts +3 -0
- package/dist/neutral/primitives/uncle/scoreUncle.d.ts.map +1 -0
- package/dist/neutral/provider/viewer/XyoViewer.d.ts +7 -5
- package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +61 -10
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts +31 -0
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -0
- package/dist/neutral/simple/blockValidation/index.d.ts +2 -0
- package/dist/neutral/simple/blockValidation/index.d.ts.map +1 -0
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts +1 -1
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/index.d.ts +1 -0
- package/dist/neutral/simple/index.d.ts.map +1 -1
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
- package/dist/neutral/summary/model/summary.d.ts +0 -1
- package/dist/neutral/summary/model/summary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/viewers/AccountBalance.d.ts +35 -15
- package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
- package/dist/neutral/viewers/BlockValidation.d.ts +54 -0
- package/dist/neutral/viewers/BlockValidation.d.ts.map +1 -0
- package/dist/neutral/viewers/StakeIntent.d.ts +2 -2
- package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -1
- package/dist/neutral/viewers/TransactionValidation.d.ts +35 -0
- package/dist/neutral/viewers/TransactionValidation.d.ts.map +1 -0
- package/dist/neutral/viewers/index.d.ts +2 -0
- package/dist/neutral/viewers/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/CreatableProvider/AbstractCreatableProvider.ts +22 -6
- package/src/CreatableProvider/CreatableProvider.ts +5 -5
- package/src/CreatableProvider/CreatableProviderRegistry.ts +1 -0
- package/src/CreatableProvider/ProviderFactory.ts +3 -2
- package/src/CreatableProvider/ProviderFactoryLocator.ts +2 -1
- package/src/config/Services.ts +4 -2
- package/src/model/ChainQualification.ts +33 -0
- package/src/model/index.ts +1 -1
- package/src/primitives/chain/getWindowedChain.ts +23 -0
- package/src/primitives/chain/index.ts +1 -0
- package/src/primitives/index.ts +1 -0
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +1 -1
- package/src/primitives/uncle/findBestUncle.ts +8 -0
- package/src/primitives/uncle/findUncles.ts +75 -0
- package/src/primitives/uncle/index.ts +3 -0
- package/src/primitives/uncle/scoreUncle.ts +6 -0
- package/src/provider/viewer/XyoViewer.ts +7 -7
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +46 -30
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +126 -0
- package/src/simple/blockValidation/index.ts +1 -0
- package/src/simple/datalake/AbstractSimpleDataLake.ts +2 -1
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -1
- package/src/simple/index.ts +1 -0
- package/src/simple/timesync/SimpleTimeSyncViewer.ts +1 -1
- package/src/summary/model/summary.ts +0 -1
- package/src/summary/primitives/balances/balancesSummary.ts +12 -12
- package/src/summary/primitives/schemas/schemasSummary.ts +12 -10
- package/src/summary/primitives/transfers/transfersSummary.ts +14 -16
- package/src/viewers/AccountBalance.ts +22 -14
- package/src/viewers/BlockValidation.ts +47 -0
- package/src/viewers/StakeIntent.ts +2 -2
- package/src/viewers/TransactionValidation.ts +35 -0
- package/src/viewers/index.ts +2 -0
- package/dist/neutral/model/Qualified.d.ts +0 -6
- package/dist/neutral/model/Qualified.d.ts.map +0 -1
- package/src/model/Qualified.ts +0 -9
package/dist/neutral/index.mjs
CHANGED
|
@@ -234,6 +234,30 @@ function blockRangeSteps(range, steps) {
|
|
|
234
234
|
}
|
|
235
235
|
__name(blockRangeSteps, "blockRangeSteps");
|
|
236
236
|
|
|
237
|
+
// src/primitives/chain/getWindowedChain.ts
|
|
238
|
+
async function getWindowedChain(blockViewer, maxWindowSize, previousChain = []) {
|
|
239
|
+
const newBlocks = [];
|
|
240
|
+
let currentBlock = await blockViewer.currentBlock();
|
|
241
|
+
console.log("[getWindowedChain] Current Block:", currentBlock?.[0]._hash);
|
|
242
|
+
const head = currentBlock;
|
|
243
|
+
while (currentBlock !== null && currentBlock[0].block >= head[0].block) {
|
|
244
|
+
newBlocks.unshift(currentBlock);
|
|
245
|
+
const previousBlockHash = currentBlock[0].previous;
|
|
246
|
+
currentBlock = previousBlockHash === null ? null : await blockViewer.blockByHash(previousBlockHash);
|
|
247
|
+
}
|
|
248
|
+
const newChain = [
|
|
249
|
+
...previousChain,
|
|
250
|
+
...newBlocks
|
|
251
|
+
].slice(-maxWindowSize);
|
|
252
|
+
while (newChain.length > 0 && newChain.length < maxWindowSize && newChain[0][0].previous !== null) {
|
|
253
|
+
const block = await blockViewer.blockByHash(newChain[0][0].previous);
|
|
254
|
+
if (block === null) break;
|
|
255
|
+
newChain.unshift(block);
|
|
256
|
+
}
|
|
257
|
+
return newChain;
|
|
258
|
+
}
|
|
259
|
+
__name(getWindowedChain, "getWindowedChain");
|
|
260
|
+
|
|
237
261
|
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
238
262
|
import { assertEx as assertEx7, exists, toAddress as toAddress4 } from "@xylabs/sdk-js";
|
|
239
263
|
import { asTransfer, isTransfer, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
@@ -921,6 +945,83 @@ function elevatedPayloads([tx, payloads]) {
|
|
|
921
945
|
}
|
|
922
946
|
__name(elevatedPayloads, "elevatedPayloads");
|
|
923
947
|
|
|
948
|
+
// src/primitives/uncle/scoreUncle.ts
|
|
949
|
+
function scoreUncle(finalizedWindowedChain, blocks) {
|
|
950
|
+
return blocks.length;
|
|
951
|
+
}
|
|
952
|
+
__name(scoreUncle, "scoreUncle");
|
|
953
|
+
|
|
954
|
+
// src/primitives/uncle/findBestUncle.ts
|
|
955
|
+
function findBestUncle(finalizedWindowedChain, uncles) {
|
|
956
|
+
const scores = uncles.map((uncle) => [
|
|
957
|
+
scoreUncle(finalizedWindowedChain, uncle),
|
|
958
|
+
uncle
|
|
959
|
+
]).toSorted((a, b) => b[0] - a[0]);
|
|
960
|
+
return scores[0]?.[1] ?? finalizedWindowedChain;
|
|
961
|
+
}
|
|
962
|
+
__name(findBestUncle, "findBestUncle");
|
|
963
|
+
|
|
964
|
+
// src/primitives/uncle/findUncles.ts
|
|
965
|
+
import { assertEx as assertEx10, exists as exists2 } from "@xylabs/sdk-js";
|
|
966
|
+
import { isTransactionBoundWitness as isTransactionBoundWitness2 } from "@xyo-network/xl1-protocol";
|
|
967
|
+
function blocksToChains(blocks) {
|
|
968
|
+
const chains = [];
|
|
969
|
+
const map = /* @__PURE__ */ new Map();
|
|
970
|
+
for (const block of blocks) {
|
|
971
|
+
map.set(block[0]._hash, block);
|
|
972
|
+
}
|
|
973
|
+
for (const block of blocks) {
|
|
974
|
+
let uncle = [
|
|
975
|
+
block
|
|
976
|
+
];
|
|
977
|
+
let previous = block[0].previous ? map.get(block[0].previous) : void 0;
|
|
978
|
+
while (previous) {
|
|
979
|
+
if (previous[0].block === uncle[0][0].block - 1) {
|
|
980
|
+
uncle.unshift(previous);
|
|
981
|
+
previous = previous[0].previous ? map.get(previous[0].previous) : void 0;
|
|
982
|
+
} else {
|
|
983
|
+
uncle = [];
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
if (uncle.length > 0) {
|
|
988
|
+
chains.push(uncle);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return chains;
|
|
992
|
+
}
|
|
993
|
+
__name(blocksToChains, "blocksToChains");
|
|
994
|
+
function toValidUncle(_context, finalizedWindowedChain, possibleUncle) {
|
|
995
|
+
const finalizedWindowStartBlockNumber = finalizedWindowedChain.at(0)?.[0].block ?? -1;
|
|
996
|
+
const finalizedHead = assertEx10(finalizedWindowedChain.at(-1), () => "finalizedWindowedChain is empty");
|
|
997
|
+
const prunedPossibleUncle = possibleUncle.filter((b) => b[0].block > finalizedHead[0].block);
|
|
998
|
+
if (prunedPossibleUncle.length === 0) {
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (prunedPossibleUncle[0][0].block !== finalizedHead[0].block + 1) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (prunedPossibleUncle[0][0].previous !== finalizedHead[0]._hash) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const allUncleTransactions = prunedPossibleUncle.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
1008
|
+
const allFinalizedTransactions = finalizedWindowedChain.flatMap((b) => b[1]).filter(isTransactionBoundWitness2);
|
|
1009
|
+
const txPossiblyBeforeWindow = allUncleTransactions.find((tx) => tx.nbf < finalizedWindowStartBlockNumber);
|
|
1010
|
+
if (txPossiblyBeforeWindow) {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
const txExistsInWindow = allUncleTransactions.find((tx) => allFinalizedTransactions.find((finalTx) => finalTx._hash === tx._hash));
|
|
1014
|
+
if (txExistsInWindow) {
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
return prunedPossibleUncle;
|
|
1018
|
+
}
|
|
1019
|
+
__name(toValidUncle, "toValidUncle");
|
|
1020
|
+
function findUncles(context, finalizedWindowedChain, blocks) {
|
|
1021
|
+
return blocksToChains(blocks).map((chain) => toValidUncle(context, finalizedWindowedChain, chain)).filter(exists2);
|
|
1022
|
+
}
|
|
1023
|
+
__name(findUncles, "findUncles");
|
|
1024
|
+
|
|
924
1025
|
// src/model/ChainContext/ChainContext.ts
|
|
925
1026
|
function contextCache(context, name, create) {
|
|
926
1027
|
if (!context.caches) {
|
|
@@ -946,6 +1047,44 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4, t
|
|
|
946
1047
|
}
|
|
947
1048
|
__name(withContextCacheResponse, "withContextCacheResponse");
|
|
948
1049
|
|
|
1050
|
+
// src/model/ChainQualification.ts
|
|
1051
|
+
import { HashZod } from "@xylabs/hex";
|
|
1052
|
+
import { zodIsFactory } from "@xylabs/zod";
|
|
1053
|
+
import { XL1BlockRangeZod } from "@xyo-network/xl1-protocol";
|
|
1054
|
+
import z from "zod";
|
|
1055
|
+
var ChainQualificationZod = z.object({
|
|
1056
|
+
head: HashZod,
|
|
1057
|
+
range: XL1BlockRangeZod
|
|
1058
|
+
});
|
|
1059
|
+
var isChainQualification = zodIsFactory(ChainQualificationZod);
|
|
1060
|
+
var ChainQualifiedRangeConfigZod = z.object({
|
|
1061
|
+
range: XL1BlockRangeZod
|
|
1062
|
+
});
|
|
1063
|
+
var isChainQualifiedRangeConfig = zodIsFactory(ChainQualifiedRangeConfigZod);
|
|
1064
|
+
var ChainQualifiedHeadConfigZod = z.object({
|
|
1065
|
+
head: HashZod
|
|
1066
|
+
});
|
|
1067
|
+
var isChainQualifiedHeadConfig = zodIsFactory(ChainQualifiedHeadConfigZod);
|
|
1068
|
+
var ChainQualifiedConfigZod = z.union([
|
|
1069
|
+
ChainQualifiedRangeConfigZod,
|
|
1070
|
+
ChainQualifiedHeadConfigZod,
|
|
1071
|
+
z.object({})
|
|
1072
|
+
]);
|
|
1073
|
+
var isChainQualifiedConfig = zodIsFactory(ChainQualifiedConfigZod);
|
|
1074
|
+
var ExtendChainQualifiedConfigZod = /* @__PURE__ */ __name((zodType) => {
|
|
1075
|
+
return z.union([
|
|
1076
|
+
ChainQualifiedRangeConfigZod.extend(zodType),
|
|
1077
|
+
ChainQualifiedHeadConfigZod.extend(zodType),
|
|
1078
|
+
zodType
|
|
1079
|
+
]);
|
|
1080
|
+
}, "ExtendChainQualifiedConfigZod");
|
|
1081
|
+
var ChainQualifiedZod = /* @__PURE__ */ __name((zodType) => {
|
|
1082
|
+
return z.tuple([
|
|
1083
|
+
zodType,
|
|
1084
|
+
ChainQualificationZod
|
|
1085
|
+
]);
|
|
1086
|
+
}, "ChainQualifiedZod");
|
|
1087
|
+
|
|
949
1088
|
// src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts
|
|
950
1089
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
951
1090
|
import { asSignedBlockBoundWitnessWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
@@ -1019,7 +1158,7 @@ function createTransferPayload(from, transfers, context) {
|
|
|
1019
1158
|
__name(createTransferPayload, "createTransferPayload");
|
|
1020
1159
|
|
|
1021
1160
|
// src/transaction/buildTransaction.ts
|
|
1022
|
-
import { assertEx as
|
|
1161
|
+
import { assertEx as assertEx11, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
1023
1162
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
1024
1163
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1025
1164
|
import { defaultTransactionFees } from "@xyo-network/xl1-protocol";
|
|
@@ -1045,7 +1184,7 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
1045
1184
|
}
|
|
1046
1185
|
const fields = {
|
|
1047
1186
|
...txBoundWitnessFields,
|
|
1048
|
-
from: from ?? (Array.isArray(signer) ?
|
|
1187
|
+
from: from ?? (Array.isArray(signer) ? assertEx11(signer.at(0)?.address) : signer.address)
|
|
1049
1188
|
};
|
|
1050
1189
|
if (script.length > 0) {
|
|
1051
1190
|
fields.script = script;
|
|
@@ -1153,7 +1292,7 @@ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash,
|
|
|
1153
1292
|
}, "confirmSubmittedTransaction");
|
|
1154
1293
|
|
|
1155
1294
|
// src/transaction/hydrateTransaction.ts
|
|
1156
|
-
import { assertEx as
|
|
1295
|
+
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
1157
1296
|
import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
|
|
1158
1297
|
import { asSignedHydratedTransaction, isAllowedBlockPayload as isAllowedBlockPayload3, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1159
1298
|
var tryHydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
|
|
@@ -1221,7 +1360,7 @@ var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap },
|
|
|
1221
1360
|
return void 0;
|
|
1222
1361
|
}, "tryHydrateElevatedTransaction");
|
|
1223
1362
|
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) => {
|
|
1224
|
-
return
|
|
1363
|
+
return assertEx12(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
|
|
1225
1364
|
}, "hydrateElevatedTransaction");
|
|
1226
1365
|
|
|
1227
1366
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
@@ -1287,7 +1426,7 @@ __name(transactionRequiredGas, "transactionRequiredGas");
|
|
|
1287
1426
|
|
|
1288
1427
|
// src/transaction/script.ts
|
|
1289
1428
|
import { asHash as asHash2 } from "@xylabs/sdk-js";
|
|
1290
|
-
import { assertEx as
|
|
1429
|
+
import { assertEx as assertEx13, filterAs } from "@xylabs/sdk-js";
|
|
1291
1430
|
import { isAllowedBlockPayloadWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
1292
1431
|
var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
1293
1432
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
@@ -1296,7 +1435,7 @@ var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
|
1296
1435
|
var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
1297
1436
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
1298
1437
|
const filtered = filterAs(hashes, (h) => asHash2(h));
|
|
1299
|
-
|
|
1438
|
+
assertEx13(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
1300
1439
|
return filtered;
|
|
1301
1440
|
}, "extractElevatedHashesFromScript");
|
|
1302
1441
|
var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
@@ -1310,15 +1449,15 @@ var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
|
1310
1449
|
const { script } = bw;
|
|
1311
1450
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
1312
1451
|
const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
|
|
1313
|
-
|
|
1452
|
+
assertEx13(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
1314
1453
|
return filtered;
|
|
1315
1454
|
}, "extractElevatedHashes");
|
|
1316
1455
|
|
|
1317
1456
|
// src/transaction/signTransaction.ts
|
|
1318
|
-
import { assertEx as
|
|
1457
|
+
import { assertEx as assertEx14, hexFromArrayBuffer, toArrayBuffer } from "@xylabs/sdk-js";
|
|
1319
1458
|
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1320
1459
|
async function signTransaction(tx, account) {
|
|
1321
|
-
|
|
1460
|
+
assertEx14(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
1322
1461
|
const unsignedTx = structuredClone(tx);
|
|
1323
1462
|
unsignedTx.addresses = [
|
|
1324
1463
|
account.address
|
|
@@ -1340,7 +1479,7 @@ async function signTransaction(tx, account) {
|
|
|
1340
1479
|
__name(signTransaction, "signTransaction");
|
|
1341
1480
|
|
|
1342
1481
|
// src/transaction/TransactionBuilder.ts
|
|
1343
|
-
import { assertEx as
|
|
1482
|
+
import { assertEx as assertEx15, Base } from "@xylabs/sdk-js";
|
|
1344
1483
|
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
|
|
1345
1484
|
import { asXL1BlockNumber as asXL1BlockNumber3, defaultTransactionFees as defaultTransactionFees3, isAllowedBlockPayload as isAllowedBlockPayload4, minTransactionFees, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
1346
1485
|
var TransactionBuilder = class extends Base {
|
|
@@ -1357,9 +1496,9 @@ var TransactionBuilder = class extends Base {
|
|
|
1357
1496
|
super(options);
|
|
1358
1497
|
}
|
|
1359
1498
|
async build() {
|
|
1360
|
-
const chain =
|
|
1361
|
-
const fees =
|
|
1362
|
-
const blockRange =
|
|
1499
|
+
const chain = assertEx15(this._chain, () => "Chain must be set before building the transaction");
|
|
1500
|
+
const fees = assertEx15(this._fees, () => "Fees must be set before building the transaction");
|
|
1501
|
+
const blockRange = assertEx15(this._blockRange, () => "Block range must be set before building the transaction");
|
|
1363
1502
|
return await buildTransaction(chain, this._elevatedPayloads, this._payloads, this._signers, asXL1BlockNumber3(blockRange[0], true), asXL1BlockNumber3(blockRange[1], true), this._signers[0]?.address, fees);
|
|
1364
1503
|
}
|
|
1365
1504
|
chain(chain) {
|
|
@@ -1371,7 +1510,7 @@ var TransactionBuilder = class extends Base {
|
|
|
1371
1510
|
}
|
|
1372
1511
|
elevatedPayload(payload) {
|
|
1373
1512
|
const allowedPayload = isAllowedBlockPayload4(payload) ? payload : void 0;
|
|
1374
|
-
const allowPayloadExists =
|
|
1513
|
+
const allowPayloadExists = assertEx15(allowedPayload, () => "Payload must be an AllowedBlockPayload");
|
|
1375
1514
|
this._elevatedPayloads.push(allowPayloadExists);
|
|
1376
1515
|
return this;
|
|
1377
1516
|
}
|
|
@@ -1467,25 +1606,13 @@ var bundle2 = /* @__PURE__ */ __name((root, transaction) => {
|
|
|
1467
1606
|
}, "bundle");
|
|
1468
1607
|
|
|
1469
1608
|
// src/model/Provider.ts
|
|
1470
|
-
import { assertEx as
|
|
1609
|
+
import { assertEx as assertEx16, isString } from "@xylabs/sdk-js";
|
|
1471
1610
|
var asProviderMoniker = /* @__PURE__ */ __name((value) => {
|
|
1472
1611
|
const moniker = isString(value) ? value : void 0;
|
|
1473
|
-
return
|
|
1612
|
+
return assertEx16(moniker);
|
|
1474
1613
|
}, "asProviderMoniker");
|
|
1475
1614
|
var DefaultProviderMoniker = "Provider";
|
|
1476
1615
|
|
|
1477
|
-
// src/model/Qualified.ts
|
|
1478
|
-
import { HashZod } from "@xylabs/sdk-js";
|
|
1479
|
-
import { XL1BlockRangeZod } from "@xyo-network/xl1-protocol";
|
|
1480
|
-
import z from "zod";
|
|
1481
|
-
var QualifiedZod = /* @__PURE__ */ __name((zodType) => {
|
|
1482
|
-
return z.tuple([
|
|
1483
|
-
zodType,
|
|
1484
|
-
XL1BlockRangeZod,
|
|
1485
|
-
HashZod
|
|
1486
|
-
]);
|
|
1487
|
-
}, "QualifiedZod");
|
|
1488
|
-
|
|
1489
1616
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
1490
1617
|
async function blockFromBlockNumber(context, blockNumber) {
|
|
1491
1618
|
const cacheKey = `${blockNumber}`;
|
|
@@ -2059,12 +2186,14 @@ var RewardRedemptionApiConfigZod = z10.object({
|
|
|
2059
2186
|
import { globalRegistry as globalRegistry9 } from "zod";
|
|
2060
2187
|
import * as z11 from "zod";
|
|
2061
2188
|
var ServicesConfigZod = z11.object({
|
|
2062
|
-
accountBalanceViewerEndpoint: z11.string().
|
|
2189
|
+
accountBalanceViewerEndpoint: z11.string().default("http://localhost:8080/rpc").register(globalRegistry9, {
|
|
2190
|
+
default: "http://localhost:8080/rpc",
|
|
2063
2191
|
description: "Endpoint of the API to use for instantiating an external AccountBalanceViewer",
|
|
2064
2192
|
title: "services.accountBalanceViewerEndpoint",
|
|
2065
2193
|
type: "string"
|
|
2066
2194
|
}),
|
|
2067
|
-
apiEndpoint: z11.string().
|
|
2195
|
+
apiEndpoint: z11.string().default("http://localhost:8080/rpc").register(globalRegistry9, {
|
|
2196
|
+
default: "http://localhost:8080/rpc",
|
|
2068
2197
|
description: "Endpoint of the API to use for instantiating an external Viewers",
|
|
2069
2198
|
title: "services.apiEndpoint",
|
|
2070
2199
|
type: "string"
|
|
@@ -2240,10 +2369,10 @@ function isUsageMeta(v) {
|
|
|
2240
2369
|
__name(isUsageMeta, "isUsageMeta");
|
|
2241
2370
|
|
|
2242
2371
|
// src/CreatableProvider/AbstractCreatableProvider.ts
|
|
2243
|
-
import { AbstractCreatable, assertEx as
|
|
2372
|
+
import { AbstractCreatable, assertEx as assertEx18 } from "@xylabs/sdk-js";
|
|
2244
2373
|
|
|
2245
2374
|
// src/CreatableProvider/ProviderFactory.ts
|
|
2246
|
-
import { assertEx as
|
|
2375
|
+
import { assertEx as assertEx17 } from "@xylabs/sdk-js";
|
|
2247
2376
|
var ProviderFactory = class _ProviderFactory {
|
|
2248
2377
|
static {
|
|
2249
2378
|
__name(this, "ProviderFactory");
|
|
@@ -2260,7 +2389,7 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2260
2389
|
this.defaultMoniker = creatableProvider2.defaultMoniker;
|
|
2261
2390
|
this.monikers = creatableProvider2.monikers;
|
|
2262
2391
|
this.scope = scope;
|
|
2263
|
-
|
|
2392
|
+
assertEx17(this.monikers.includes(this.defaultMoniker), () => "defaultMoniker must be in monikers");
|
|
2264
2393
|
this.labels = Object.assign({}, creatableProvider2.labels ?? {}, labels ?? {});
|
|
2265
2394
|
}
|
|
2266
2395
|
get resolvedMoniker() {
|
|
@@ -2289,7 +2418,7 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2289
2418
|
break;
|
|
2290
2419
|
}
|
|
2291
2420
|
case "context": {
|
|
2292
|
-
const context =
|
|
2421
|
+
const context = assertEx17(params?.context, () => "Context is required for context-scoped providers");
|
|
2293
2422
|
if (context.singletons === void 0) {
|
|
2294
2423
|
context.singletons = {};
|
|
2295
2424
|
}
|
|
@@ -2313,11 +2442,12 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
2313
2442
|
}
|
|
2314
2443
|
}
|
|
2315
2444
|
};
|
|
2316
|
-
const
|
|
2445
|
+
const resultPromise = scopeObject[this.resolvedMoniker] ?? this.creatableProvider.create(mergedParams);
|
|
2446
|
+
scopeObject[this.resolvedMoniker] = resultPromise;
|
|
2447
|
+
const result = await resultPromise;
|
|
2317
2448
|
if (start) {
|
|
2318
|
-
|
|
2449
|
+
assertEx17(await result.start(), () => "Failed to start provider instance");
|
|
2319
2450
|
}
|
|
2320
|
-
scopeObject[this.resolvedMoniker] = result;
|
|
2321
2451
|
return result;
|
|
2322
2452
|
}
|
|
2323
2453
|
async tryGetInstance(params, start = true) {
|
|
@@ -2336,13 +2466,13 @@ var AbstractCreatableProvider = class extends AbstractCreatable {
|
|
|
2336
2466
|
}
|
|
2337
2467
|
_contextCache;
|
|
2338
2468
|
get config() {
|
|
2339
|
-
return
|
|
2469
|
+
return this.context.config;
|
|
2340
2470
|
}
|
|
2341
2471
|
get context() {
|
|
2342
|
-
return
|
|
2472
|
+
return this.params.context;
|
|
2343
2473
|
}
|
|
2344
2474
|
get locator() {
|
|
2345
|
-
return
|
|
2475
|
+
return this.context.locator;
|
|
2346
2476
|
}
|
|
2347
2477
|
static factory(params) {
|
|
2348
2478
|
const factory = ProviderFactory.withParams(this, params);
|
|
@@ -2352,6 +2482,21 @@ var AbstractCreatableProvider = class extends AbstractCreatable {
|
|
|
2352
2482
|
const instance = await this.create(inParams);
|
|
2353
2483
|
return instance;
|
|
2354
2484
|
}
|
|
2485
|
+
static async paramsHandler(params = {}) {
|
|
2486
|
+
const context = assertEx18(params.context, () => new Error("Context is required"));
|
|
2487
|
+
const config = assertEx18(context.config, () => new Error("Context config is required"));
|
|
2488
|
+
const locator = assertEx18(context.locator, () => new Error("Context locator is required"));
|
|
2489
|
+
return await super.paramsHandler({
|
|
2490
|
+
...params,
|
|
2491
|
+
statusReporter: params.statusReporter ?? context.statusReporter,
|
|
2492
|
+
context: {
|
|
2493
|
+
...context,
|
|
2494
|
+
config,
|
|
2495
|
+
locator
|
|
2496
|
+
},
|
|
2497
|
+
name: params.name ?? this.defaultMoniker
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2355
2500
|
static async tryGetInstance(inParams) {
|
|
2356
2501
|
try {
|
|
2357
2502
|
return await this.create(inParams);
|
|
@@ -2384,6 +2529,7 @@ var buildProviderFactory = /* @__PURE__ */ __name((provider, labels) => {
|
|
|
2384
2529
|
const factory = {
|
|
2385
2530
|
monikers: provider.monikers,
|
|
2386
2531
|
// Copy static methods
|
|
2532
|
+
// eslint-disable-next-line sonarjs/deprecation
|
|
2387
2533
|
create: provider.create.bind(provider),
|
|
2388
2534
|
// Merge module & supplied labels
|
|
2389
2535
|
labels: {
|
|
@@ -2460,7 +2606,7 @@ __name(labeledCreatableProviderFactory, "labeledCreatableProviderFactory");
|
|
|
2460
2606
|
|
|
2461
2607
|
// src/CreatableProvider/ProviderFactoryLocator.ts
|
|
2462
2608
|
import { hasAllLabels } from "@xylabs/sdk-js";
|
|
2463
|
-
import { assertEx as
|
|
2609
|
+
import { assertEx as assertEx19 } from "@xylabs/sdk-js";
|
|
2464
2610
|
var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
2465
2611
|
static {
|
|
2466
2612
|
__name(this, "ProviderFactoryLocator");
|
|
@@ -2506,7 +2652,8 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
2506
2652
|
}
|
|
2507
2653
|
};
|
|
2508
2654
|
const factory = this.locate(moniker, labels);
|
|
2509
|
-
|
|
2655
|
+
const result = await factory.getInstance(resolvedParams);
|
|
2656
|
+
return result;
|
|
2510
2657
|
}
|
|
2511
2658
|
/**
|
|
2512
2659
|
* Locates a provider factory that matches the supplied moniker and labels
|
|
@@ -2515,7 +2662,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
2515
2662
|
* @returns A provider factory that matches the supplied moniker and labels or throws if one is not found
|
|
2516
2663
|
*/
|
|
2517
2664
|
locate(moniker, labels) {
|
|
2518
|
-
return
|
|
2665
|
+
return assertEx19(this.tryLocate(moniker, labels), () => `No module factory for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
|
|
2519
2666
|
}
|
|
2520
2667
|
merge(locator) {
|
|
2521
2668
|
const registry = {
|
|
@@ -2536,7 +2683,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
2536
2683
|
* @param labels The labels for the module factory
|
|
2537
2684
|
*/
|
|
2538
2685
|
register(factory, labels, primary = false) {
|
|
2539
|
-
|
|
2686
|
+
assertEx19(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
|
|
2540
2687
|
registerCreatableProviderFactory(this._registry, factory, labels, primary);
|
|
2541
2688
|
return this;
|
|
2542
2689
|
}
|
|
@@ -2779,8 +2926,8 @@ var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
|
2779
2926
|
}, "toPositiveBigInt");
|
|
2780
2927
|
|
|
2781
2928
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
2782
|
-
import { asHash as asHash5, assertEx as
|
|
2783
|
-
import { asRange, asXL1BlockNumber as
|
|
2929
|
+
import { asHash as asHash5, assertEx as assertEx23, exists as exists3, isDefined as isDefined13, spanRootAsync as spanRootAsync4, ZERO_ADDRESS } from "@xylabs/sdk-js";
|
|
2930
|
+
import { asRange, asXL1BlockNumber as asXL1BlockNumber5, asXL1BlockRange as asXL1BlockRange7, AttoXL1 as AttoXL12, StepSizes as StepSizes11, TransferSchema as TransferSchema2 } from "@xyo-network/xl1-protocol";
|
|
2784
2931
|
|
|
2785
2932
|
// src/summary/model/BalancesStepSummary.ts
|
|
2786
2933
|
import { AsObjectFactory as AsObjectFactory5 } from "@xylabs/sdk-js";
|
|
@@ -2819,7 +2966,7 @@ var isTransfersStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
|
2819
2966
|
var asTransfersStepSummaryWithStorageMeta = AsObjectFactory7.create(isTransfersStepSummaryWithStorageMeta);
|
|
2820
2967
|
|
|
2821
2968
|
// src/summary/primitives/balances/balancesStepSummaryFromRange.ts
|
|
2822
|
-
import { assertEx as
|
|
2969
|
+
import { assertEx as assertEx20 } from "@xylabs/sdk-js";
|
|
2823
2970
|
import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
|
|
2824
2971
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
2825
2972
|
import { StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol";
|
|
@@ -2843,7 +2990,7 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
2843
2990
|
};
|
|
2844
2991
|
} else {
|
|
2845
2992
|
const step = StepSizes8.indexOf(frameSize);
|
|
2846
|
-
|
|
2993
|
+
assertEx20(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes8.join(", ")}`);
|
|
2847
2994
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
2848
2995
|
if (isAnyPayload(summaryResult)) {
|
|
2849
2996
|
result = summaryResult;
|
|
@@ -2881,21 +3028,23 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
2881
3028
|
__name(balancesStepSummaryFromRange, "balancesStepSummaryFromRange");
|
|
2882
3029
|
|
|
2883
3030
|
// src/summary/primitives/balances/balancesSummary.ts
|
|
2884
|
-
import { asAddress as asAddress3,
|
|
2885
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2,
|
|
2886
|
-
async function balancesSummary(context) {
|
|
3031
|
+
import { asAddress as asAddress3, spanRootAsync } from "@xylabs/sdk-js";
|
|
3032
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockRange as asXL1BlockRange4 } from "@xyo-network/xl1-protocol";
|
|
3033
|
+
async function balancesSummary(context, config) {
|
|
2887
3034
|
return await spanRootAsync("balancesSummary", async () => {
|
|
2888
|
-
const [headHash] =
|
|
3035
|
+
const [headHash] = isChainQualifiedHeadConfig(config) ? [
|
|
3036
|
+
config.head
|
|
3037
|
+
] : await context.head();
|
|
2889
3038
|
const headResult = await context.store.chainMap.get(headHash);
|
|
2890
3039
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
2891
|
-
const
|
|
2892
|
-
|
|
2893
|
-
rangeStart,
|
|
3040
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange4([
|
|
3041
|
+
0,
|
|
2894
3042
|
headBoundWitness.block
|
|
2895
|
-
],
|
|
3043
|
+
], true);
|
|
3044
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange4(range, {
|
|
2896
3045
|
name: "balancesSummary"
|
|
2897
3046
|
}));
|
|
2898
|
-
const summaries = await Promise.all(ranges.map((
|
|
3047
|
+
const summaries = await Promise.all(ranges.map((range2) => balancesStepSummaryFromRange(context, range2)));
|
|
2899
3048
|
const balances = {};
|
|
2900
3049
|
for (let summary of summaries) {
|
|
2901
3050
|
for (const [address, balance] of Object.entries(summary.balances)) {
|
|
@@ -2905,18 +3054,17 @@ async function balancesSummary(context) {
|
|
|
2905
3054
|
}
|
|
2906
3055
|
return [
|
|
2907
3056
|
balances,
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
headHash
|
|
3057
|
+
{
|
|
3058
|
+
range,
|
|
3059
|
+
head: headHash
|
|
3060
|
+
}
|
|
2913
3061
|
];
|
|
2914
3062
|
});
|
|
2915
3063
|
}
|
|
2916
3064
|
__name(balancesSummary, "balancesSummary");
|
|
2917
3065
|
|
|
2918
3066
|
// src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
|
|
2919
|
-
import { assertEx as
|
|
3067
|
+
import { assertEx as assertEx21 } from "@xylabs/sdk-js";
|
|
2920
3068
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
2921
3069
|
import { PayloadBuilder as PayloadBuilder15 } from "@xyo-network/payload-builder";
|
|
2922
3070
|
import { isAnyPayload as isAnyPayload2, isHashMeta } from "@xyo-network/payload-model";
|
|
@@ -2948,7 +3096,7 @@ async function schemasStepSummaryFromRange(context, range) {
|
|
|
2948
3096
|
};
|
|
2949
3097
|
} else {
|
|
2950
3098
|
const step = StepSizes9.indexOf(frameSize);
|
|
2951
|
-
|
|
3099
|
+
assertEx21(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
|
|
2952
3100
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
2953
3101
|
if (isAnyPayload2(summaryResult)) {
|
|
2954
3102
|
result = summaryResult;
|
|
@@ -2981,21 +3129,23 @@ async function schemasStepSummaryFromRange(context, range) {
|
|
|
2981
3129
|
__name(schemasStepSummaryFromRange, "schemasStepSummaryFromRange");
|
|
2982
3130
|
|
|
2983
3131
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
2984
|
-
import {
|
|
2985
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3,
|
|
2986
|
-
async function schemasSummary(context) {
|
|
3132
|
+
import { spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
|
|
3133
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockRange as asXL1BlockRange5 } from "@xyo-network/xl1-protocol";
|
|
3134
|
+
async function schemasSummary(context, config) {
|
|
2987
3135
|
return await spanRootAsync2("schemasSummary", async () => {
|
|
2988
|
-
const [headHash] =
|
|
3136
|
+
const [headHash] = isChainQualifiedHeadConfig(config) ? [
|
|
3137
|
+
config.head
|
|
3138
|
+
] : await context.head();
|
|
2989
3139
|
const headResult = await context.store.chainMap.get(headHash);
|
|
2990
3140
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
2991
|
-
const
|
|
2992
|
-
|
|
2993
|
-
rangeStart,
|
|
3141
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange5([
|
|
3142
|
+
0,
|
|
2994
3143
|
headBoundWitness.block
|
|
2995
|
-
],
|
|
3144
|
+
], true);
|
|
3145
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange5(range, {
|
|
2996
3146
|
name: "schemasSummary"
|
|
2997
3147
|
}));
|
|
2998
|
-
const summaries = await Promise.all(ranges.map((
|
|
3148
|
+
const summaries = await Promise.all(ranges.map((range2) => schemasStepSummaryFromRange(context, range2)));
|
|
2999
3149
|
const results = {};
|
|
3000
3150
|
for (let summary of summaries) {
|
|
3001
3151
|
for (const [schema, count] of Object.entries(summary.schemas)) {
|
|
@@ -3004,38 +3154,39 @@ async function schemasSummary(context) {
|
|
|
3004
3154
|
}
|
|
3005
3155
|
return [
|
|
3006
3156
|
results,
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
headHash
|
|
3157
|
+
{
|
|
3158
|
+
range,
|
|
3159
|
+
head: headHash
|
|
3160
|
+
}
|
|
3012
3161
|
];
|
|
3013
3162
|
});
|
|
3014
3163
|
}
|
|
3015
3164
|
__name(schemasSummary, "schemasSummary");
|
|
3016
3165
|
|
|
3017
3166
|
// src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
3018
|
-
import { assertEx as
|
|
3167
|
+
import { assertEx as assertEx22 } from "@xylabs/sdk-js";
|
|
3019
3168
|
import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/payload-builder";
|
|
3020
3169
|
import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
|
|
3021
3170
|
import { StepSizes as StepSizes10 } from "@xyo-network/xl1-protocol";
|
|
3022
3171
|
|
|
3023
3172
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
3024
|
-
import { asAddress as asAddress4,
|
|
3025
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4,
|
|
3026
|
-
async function transfersSummary(
|
|
3173
|
+
import { asAddress as asAddress4, spanRootAsync as spanRootAsync3 } from "@xylabs/sdk-js";
|
|
3174
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockRange as asXL1BlockRange6 } from "@xyo-network/xl1-protocol";
|
|
3175
|
+
async function transfersSummary(context, config) {
|
|
3027
3176
|
return await spanRootAsync3("transferSummary", async () => {
|
|
3028
|
-
const [headHash] =
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
const
|
|
3032
|
-
const
|
|
3033
|
-
|
|
3177
|
+
const [headHash] = isChainQualifiedHeadConfig(config) ? [
|
|
3178
|
+
config.head
|
|
3179
|
+
] : await context.head();
|
|
3180
|
+
const headResult = await context.store.chainMap.get(headHash);
|
|
3181
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
3182
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange6([
|
|
3183
|
+
0,
|
|
3034
3184
|
headBoundWitness.block
|
|
3035
|
-
],
|
|
3185
|
+
], true);
|
|
3186
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange6(range, {
|
|
3036
3187
|
name: "transfersSummary"
|
|
3037
3188
|
}));
|
|
3038
|
-
const summaries = await Promise.all(ranges.map((
|
|
3189
|
+
const summaries = await Promise.all(ranges.map((range2) => transfersStepSummaryFromRange(context, range2)));
|
|
3039
3190
|
const transfers = {};
|
|
3040
3191
|
for (let summary of summaries) {
|
|
3041
3192
|
for (const [from, toMap] of Object.entries(summary.transfers)) {
|
|
@@ -3049,11 +3200,10 @@ async function transfersSummary(transferContext) {
|
|
|
3049
3200
|
}
|
|
3050
3201
|
return [
|
|
3051
3202
|
transfers,
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
headHash
|
|
3203
|
+
{
|
|
3204
|
+
range,
|
|
3205
|
+
head: headHash
|
|
3206
|
+
}
|
|
3057
3207
|
];
|
|
3058
3208
|
});
|
|
3059
3209
|
}
|
|
@@ -3087,7 +3237,7 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
3087
3237
|
};
|
|
3088
3238
|
} else {
|
|
3089
3239
|
const step = StepSizes10.indexOf(frameSize);
|
|
3090
|
-
|
|
3240
|
+
assertEx22(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes10.join(", ")}`);
|
|
3091
3241
|
const key = transfersSummaryKey(frameHeadHash, frameSize);
|
|
3092
3242
|
const summaryResult = await context.summaryMap.get(key);
|
|
3093
3243
|
if (isAnyPayload3(summaryResult)) {
|
|
@@ -3132,6 +3282,7 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
3132
3282
|
__name(transfersStepSummaryFromRange, "transfersStepSummaryFromRange");
|
|
3133
3283
|
|
|
3134
3284
|
// src/viewers/AccountBalance.ts
|
|
3285
|
+
import { zodIsFactory as zodIsFactory2 } from "@xylabs/zod";
|
|
3135
3286
|
import { WithHashMetaZod } from "@xyo-network/payload-model";
|
|
3136
3287
|
import { TransferZod } from "@xyo-network/xl1-protocol";
|
|
3137
3288
|
import { BlockBoundWitnessZod, TransactionBoundWitnessZod } from "@xyo-network/xl1-protocol";
|
|
@@ -3141,6 +3292,10 @@ var AccountBalanceHistoryItemZod = z21.tuple([
|
|
|
3141
3292
|
WithHashMetaZod(TransactionBoundWitnessZod).nullable(),
|
|
3142
3293
|
WithHashMetaZod(TransferZod)
|
|
3143
3294
|
]);
|
|
3295
|
+
var AccountBalanceQualificationZod = ChainQualificationZod;
|
|
3296
|
+
var isAccountBalanceQualification = zodIsFactory2(AccountBalanceQualificationZod);
|
|
3297
|
+
var AccountBalanceConfigZod = ChainQualifiedConfigZod;
|
|
3298
|
+
var isAccountBalanceCOnfig = zodIsFactory2(AccountBalanceConfigZod);
|
|
3144
3299
|
var AccountBalanceViewerMoniker = "AccountBalanceViewer";
|
|
3145
3300
|
|
|
3146
3301
|
// src/viewers/Block.ts
|
|
@@ -3149,6 +3304,24 @@ var BlockViewerMoniker = "BlockViewer";
|
|
|
3149
3304
|
// src/viewers/BlockReward.ts
|
|
3150
3305
|
var BlockRewardViewerMoniker = "BlockRewardViewer";
|
|
3151
3306
|
|
|
3307
|
+
// src/viewers/BlockValidation.ts
|
|
3308
|
+
import { zodIsFactory as zodIsFactory3 } from "@xylabs/zod";
|
|
3309
|
+
import z22 from "zod";
|
|
3310
|
+
var BlockValidationQualificationZod = ChainQualificationZod;
|
|
3311
|
+
var isBlockValidationQualification = zodIsFactory3(BlockValidationQualificationZod);
|
|
3312
|
+
var BlockValidationConfigFieldsZod = z22.object({
|
|
3313
|
+
value: z22.boolean().optional(),
|
|
3314
|
+
state: z22.boolean().optional()
|
|
3315
|
+
});
|
|
3316
|
+
var BlockValidationConfigZod = z22.union([
|
|
3317
|
+
BlockValidationConfigFieldsZod.extend(ChainQualifiedHeadConfigZod.shape),
|
|
3318
|
+
BlockValidationConfigFieldsZod.extend(ChainQualifiedRangeConfigZod.shape),
|
|
3319
|
+
BlockValidationConfigFieldsZod,
|
|
3320
|
+
z22.object({})
|
|
3321
|
+
]);
|
|
3322
|
+
var isBlockValidationConfig = zodIsFactory3(BlockValidationConfigZod);
|
|
3323
|
+
var BlockValidationViewerMoniker = "BlockValidationViewer";
|
|
3324
|
+
|
|
3152
3325
|
// src/viewers/ChainContract.ts
|
|
3153
3326
|
var ChainContractViewerMoniker = "ChainContractViewer";
|
|
3154
3327
|
|
|
@@ -3158,15 +3331,15 @@ var ChainStakeViewerMoniker = "ChainStakeViewer";
|
|
|
3158
3331
|
// src/viewers/Mempool.ts
|
|
3159
3332
|
import { HashZod as HashZod3 } from "@xylabs/sdk-js";
|
|
3160
3333
|
import { XL1BlockRangeZod as XL1BlockRangeZod2 } from "@xyo-network/xl1-protocol";
|
|
3161
|
-
import
|
|
3162
|
-
var PendingTransactionsOptionsZod =
|
|
3334
|
+
import z23 from "zod";
|
|
3335
|
+
var PendingTransactionsOptionsZod = z23.object({
|
|
3163
3336
|
cursor: HashZod3.optional(),
|
|
3164
|
-
limit:
|
|
3337
|
+
limit: z23.number().int().positive().optional(),
|
|
3165
3338
|
window: XL1BlockRangeZod2.optional()
|
|
3166
3339
|
});
|
|
3167
|
-
var PendingBlocksOptionsZod =
|
|
3340
|
+
var PendingBlocksOptionsZod = z23.object({
|
|
3168
3341
|
cursor: HashZod3.optional(),
|
|
3169
|
-
limit:
|
|
3342
|
+
limit: z23.number().int().positive().optional(),
|
|
3170
3343
|
window: XL1BlockRangeZod2.optional()
|
|
3171
3344
|
});
|
|
3172
3345
|
var MempoolViewerMoniker = "MempoolViewer";
|
|
@@ -3198,6 +3371,14 @@ var StepViewerMoniker = "StepViewer";
|
|
|
3198
3371
|
// src/viewers/TimeSync.ts
|
|
3199
3372
|
var TimeSyncViewerMoniker = "TimeSyncViewer";
|
|
3200
3373
|
|
|
3374
|
+
// src/viewers/TransactionValidation.ts
|
|
3375
|
+
import { zodIsFactory as zodIsFactory4 } from "@xylabs/zod";
|
|
3376
|
+
var TransactionValidationQualificationZod = ChainQualificationZod;
|
|
3377
|
+
var isTransactionValidationQualification = zodIsFactory4(TransactionValidationQualificationZod);
|
|
3378
|
+
var TransactionValidationConfigZod = ChainQualifiedConfigZod;
|
|
3379
|
+
var isTransactionValidationConfig = zodIsFactory4(TransactionValidationConfigZod);
|
|
3380
|
+
var TransactionValidationViewerMoniker = "TransactionValidationViewer";
|
|
3381
|
+
|
|
3201
3382
|
// src/viewers/TransferBalance.ts
|
|
3202
3383
|
var TransferBalanceViewerMoniker = "TransferBalanceViewer";
|
|
3203
3384
|
|
|
@@ -3229,36 +3410,36 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3229
3410
|
return this.params.transfersSummaryContext;
|
|
3230
3411
|
}
|
|
3231
3412
|
static async paramsHandler(params = {}) {
|
|
3232
|
-
|
|
3233
|
-
|
|
3413
|
+
assertEx23(params.transfersSummaryContext, () => "transfersSummaryContext is required");
|
|
3414
|
+
assertEx23(params.balanceSummaryContext, () => "balanceSummaryContext is required");
|
|
3234
3415
|
return await super.paramsHandler({
|
|
3235
3416
|
...params
|
|
3236
3417
|
});
|
|
3237
3418
|
}
|
|
3238
|
-
async accountBalance(address,
|
|
3419
|
+
async accountBalance(address, config) {
|
|
3239
3420
|
const balances = await this.accountBalances([
|
|
3240
3421
|
address
|
|
3241
|
-
],
|
|
3422
|
+
], config);
|
|
3242
3423
|
return balances[address] ?? AttoXL12(0n);
|
|
3243
3424
|
}
|
|
3244
|
-
accountBalanceHistories(
|
|
3245
|
-
|
|
3425
|
+
async accountBalanceHistories(addresses, config = {}) {
|
|
3426
|
+
return (await this.qualifiedAccountBalanceHistories(addresses, config))[0];
|
|
3246
3427
|
}
|
|
3247
|
-
async accountBalanceHistory(address,
|
|
3248
|
-
const range =
|
|
3428
|
+
async accountBalanceHistory(address, config) {
|
|
3429
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : void 0;
|
|
3249
3430
|
const startingRange = asXL1BlockRange7(range ?? [
|
|
3250
3431
|
0,
|
|
3251
3432
|
await this.blockViewer.currentBlockNumber()
|
|
3252
3433
|
], true);
|
|
3253
3434
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
3254
|
-
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(
|
|
3435
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
3255
3436
|
const result = [];
|
|
3256
3437
|
for (const block of blocks) {
|
|
3257
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(
|
|
3438
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
3258
3439
|
const transfers = transferIndexes.map((index) => {
|
|
3259
3440
|
const hash = block[0].payload_hashes[index];
|
|
3260
|
-
return
|
|
3261
|
-
}).filter(
|
|
3441
|
+
return assertEx23(block[1].find((p) => p._hash === hash), () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`);
|
|
3442
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined13(t.transfers[address]));
|
|
3262
3443
|
if (transfers.length === 0) {
|
|
3263
3444
|
continue;
|
|
3264
3445
|
}
|
|
@@ -3276,19 +3457,19 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3276
3457
|
}
|
|
3277
3458
|
return result;
|
|
3278
3459
|
}
|
|
3279
|
-
async accountBalances(address,
|
|
3280
|
-
const [result] = await this.qualifiedAccountBalances(address,
|
|
3460
|
+
async accountBalances(address, config) {
|
|
3461
|
+
const [result] = await this.qualifiedAccountBalances(address, config ?? {});
|
|
3281
3462
|
return result;
|
|
3282
3463
|
}
|
|
3283
3464
|
async createHandler() {
|
|
3284
3465
|
await super.createHandler();
|
|
3285
3466
|
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
|
|
3286
3467
|
}
|
|
3287
|
-
async qualifiedAccountBalanceHistories(addresses,
|
|
3288
|
-
const head =
|
|
3289
|
-
const range =
|
|
3468
|
+
async qualifiedAccountBalanceHistories(addresses, config) {
|
|
3469
|
+
const head = isChainQualifiedHeadConfig(config) ? config.head : await this.blockViewer.currentBlockHash();
|
|
3470
|
+
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange7([
|
|
3290
3471
|
0,
|
|
3291
|
-
|
|
3472
|
+
assertEx23(await this.blockViewer.blockByHash(head), () => `Error: Could not find block with hash ${head}`)[0].block
|
|
3292
3473
|
]);
|
|
3293
3474
|
const qualifiedEntries = await Promise.all(addresses.map(async (address) => [
|
|
3294
3475
|
address,
|
|
@@ -3300,21 +3481,25 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3300
3481
|
history
|
|
3301
3482
|
];
|
|
3302
3483
|
});
|
|
3303
|
-
const qualifiedRange = qualifiedEntries[0][1][1];
|
|
3304
|
-
const qualifiedHeadHash = qualifiedEntries[0][1][
|
|
3305
|
-
for (const [_, [__, range2,
|
|
3306
|
-
|
|
3307
|
-
|
|
3484
|
+
const qualifiedRange = qualifiedEntries[0][1][1].range;
|
|
3485
|
+
const qualifiedHeadHash = qualifiedEntries[0][1][1].head;
|
|
3486
|
+
for (const [_, [__, { range: range2, head: head2 }]] of qualifiedEntries) {
|
|
3487
|
+
assertEx23(range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1], () => "Inconsistent ranges in qualifiedAccountBalanceHistories");
|
|
3488
|
+
assertEx23(head2 === qualifiedHeadHash, () => "Inconsistent head hashes in qualifiedAccountBalanceHistories");
|
|
3308
3489
|
}
|
|
3309
3490
|
return [
|
|
3310
3491
|
Object.fromEntries(entries),
|
|
3311
|
-
|
|
3312
|
-
|
|
3492
|
+
{
|
|
3493
|
+
range: qualifiedRange,
|
|
3494
|
+
head: qualifiedHeadHash
|
|
3495
|
+
}
|
|
3313
3496
|
];
|
|
3314
3497
|
}
|
|
3315
|
-
async qualifiedAccountBalances(address,
|
|
3498
|
+
async qualifiedAccountBalances(address, config) {
|
|
3316
3499
|
return await spanRootAsync4("qualifiedAccountsBalances", async () => {
|
|
3317
|
-
const qualifiedSummary = await balancesSummary(
|
|
3500
|
+
const qualifiedSummary = await balancesSummary({
|
|
3501
|
+
...this.balanceSummaryContext
|
|
3502
|
+
}, config);
|
|
3318
3503
|
const result = {};
|
|
3319
3504
|
for (const addr of address) {
|
|
3320
3505
|
const summaryBalance = qualifiedSummary[0][addr] ?? 0n;
|
|
@@ -3322,16 +3507,22 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3322
3507
|
}
|
|
3323
3508
|
return [
|
|
3324
3509
|
result,
|
|
3325
|
-
qualifiedSummary[1]
|
|
3326
|
-
qualifiedSummary[2]
|
|
3510
|
+
qualifiedSummary[1]
|
|
3327
3511
|
];
|
|
3328
3512
|
});
|
|
3329
3513
|
}
|
|
3514
|
+
async startHandler() {
|
|
3515
|
+
await super.startHandler();
|
|
3516
|
+
await Promise.all([
|
|
3517
|
+
this.accountBalance(ZERO_ADDRESS),
|
|
3518
|
+
this.accountBalanceHistory(ZERO_ADDRESS)
|
|
3519
|
+
]);
|
|
3520
|
+
}
|
|
3330
3521
|
async distillTransferHistory(address, range, max = 50) {
|
|
3331
3522
|
if (range[1] - range[0] <= StepSizes11[0] || max <= 1) {
|
|
3332
3523
|
return Array.from({
|
|
3333
3524
|
length: range[1] - range[0] + 1
|
|
3334
|
-
}, (_, i) => range[1] - i).slice(0, max).map((n) =>
|
|
3525
|
+
}, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber5(n, true));
|
|
3335
3526
|
}
|
|
3336
3527
|
const frames = deepCalculateFramesFromRange(asXL1BlockRange7(range, true));
|
|
3337
3528
|
const transferSummaryPairs = await Promise.all(frames.map(async (frame) => {
|
|
@@ -3371,20 +3562,20 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3371
3562
|
async qualifiedAccountBalanceHistory(address, headOrRange) {
|
|
3372
3563
|
const range = asRange(headOrRange);
|
|
3373
3564
|
const headHash = asHash5(headOrRange);
|
|
3374
|
-
const [head] =
|
|
3565
|
+
const [head] = assertEx23(isDefined13(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
3375
3566
|
const startingRange = asXL1BlockRange7(range ?? [
|
|
3376
3567
|
0,
|
|
3377
3568
|
head.block
|
|
3378
3569
|
], true);
|
|
3379
3570
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
3380
|
-
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(
|
|
3571
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
3381
3572
|
const result = [];
|
|
3382
3573
|
for (const block of blocks) {
|
|
3383
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(
|
|
3574
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists3);
|
|
3384
3575
|
const transfers = transferIndexes.map((index) => {
|
|
3385
3576
|
const hash = block[0].payload_hashes[index];
|
|
3386
|
-
return
|
|
3387
|
-
}).filter(
|
|
3577
|
+
return assertEx23(block[1].find((p) => p._hash === hash), () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`);
|
|
3578
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined13(t.transfers[address]));
|
|
3388
3579
|
if (transfers.length === 0) {
|
|
3389
3580
|
continue;
|
|
3390
3581
|
}
|
|
@@ -3402,8 +3593,10 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
3402
3593
|
}
|
|
3403
3594
|
return [
|
|
3404
3595
|
result,
|
|
3405
|
-
|
|
3406
|
-
|
|
3596
|
+
{
|
|
3597
|
+
range: startingRange,
|
|
3598
|
+
head: head._hash
|
|
3599
|
+
}
|
|
3407
3600
|
];
|
|
3408
3601
|
}
|
|
3409
3602
|
};
|
|
@@ -3412,8 +3605,8 @@ SimpleAccountBalanceViewer = _ts_decorate([
|
|
|
3412
3605
|
], SimpleAccountBalanceViewer);
|
|
3413
3606
|
|
|
3414
3607
|
// src/simple/block/SimpleBlockViewer.ts
|
|
3415
|
-
import { assertEx as
|
|
3416
|
-
import { asSignedHydratedBlockWithHashMeta, asXL1BlockNumber as
|
|
3608
|
+
import { assertEx as assertEx24, exists as exists4, isDefined as isDefined14, isUndefined as isUndefined5, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
|
|
3609
|
+
import { asSignedHydratedBlockWithHashMeta, asXL1BlockNumber as asXL1BlockNumber6 } from "@xyo-network/xl1-protocol";
|
|
3417
3610
|
|
|
3418
3611
|
// src/utils/HydratedCache.ts
|
|
3419
3612
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
@@ -3446,12 +3639,12 @@ var HydratedCache = class {
|
|
|
3446
3639
|
};
|
|
3447
3640
|
|
|
3448
3641
|
// src/utils/isZodError.ts
|
|
3449
|
-
import * as
|
|
3642
|
+
import * as z24 from "zod";
|
|
3450
3643
|
var isZodError = /* @__PURE__ */ __name((error) => {
|
|
3451
|
-
return error instanceof
|
|
3644
|
+
return error instanceof z24.ZodError;
|
|
3452
3645
|
}, "isZodError");
|
|
3453
3646
|
var prettifyZodError = /* @__PURE__ */ __name((error) => {
|
|
3454
|
-
return
|
|
3647
|
+
return z24.prettifyError(error);
|
|
3455
3648
|
}, "prettifyZodError");
|
|
3456
3649
|
|
|
3457
3650
|
// src/simple/block/SimpleBlockViewer.ts
|
|
@@ -3497,7 +3690,7 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3497
3690
|
return this._store;
|
|
3498
3691
|
}
|
|
3499
3692
|
static async paramsHandler(params) {
|
|
3500
|
-
|
|
3693
|
+
assertEx24(params.finalizedArchivist, () => "finalizedArchivist is required");
|
|
3501
3694
|
return {
|
|
3502
3695
|
...await super.paramsHandler(params)
|
|
3503
3696
|
};
|
|
@@ -3529,8 +3722,8 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3529
3722
|
}
|
|
3530
3723
|
async blocksByHash(hash, limit = 50) {
|
|
3531
3724
|
return await spanRootAsync5("blocksByHash", async () => {
|
|
3532
|
-
|
|
3533
|
-
|
|
3725
|
+
assertEx24(limit > 0, () => "limit must be greater than 0");
|
|
3726
|
+
assertEx24(limit <= 100, () => "limit must be less than 100");
|
|
3534
3727
|
const blocks = [];
|
|
3535
3728
|
let current = await this.blockByHash(hash);
|
|
3536
3729
|
while (current && blocks.length < limit) {
|
|
@@ -3544,14 +3737,14 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3544
3737
|
}
|
|
3545
3738
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
3546
3739
|
return await spanRootAsync5("blocksByHash", async () => {
|
|
3547
|
-
|
|
3548
|
-
|
|
3740
|
+
assertEx24(limit > 0, () => "limit must be greater than 0");
|
|
3741
|
+
assertEx24(limit <= 100, () => "limit must be less than 100");
|
|
3549
3742
|
const blocks = [];
|
|
3550
3743
|
let current = await this.blockByNumber(blockNumber);
|
|
3551
3744
|
while (current && blocks.length < limit) {
|
|
3552
3745
|
blocks.push(current);
|
|
3553
3746
|
if (current[0].block === 0) break;
|
|
3554
|
-
const previousNumber =
|
|
3747
|
+
const previousNumber = asXL1BlockNumber6(current[0].block - 1, true);
|
|
3555
3748
|
current = await this.blockByNumber(previousNumber);
|
|
3556
3749
|
}
|
|
3557
3750
|
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
|
|
@@ -3559,7 +3752,7 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3559
3752
|
}
|
|
3560
3753
|
async chainId(blockNumber = "latest") {
|
|
3561
3754
|
return await spanRootAsync5("chainId", async () => {
|
|
3562
|
-
const block =
|
|
3755
|
+
const block = assertEx24(blockNumber === "latest" ? await this.currentBlock() : await this.blockByNumber(blockNumber), () => `Could not find block for block number ${blockNumber}`);
|
|
3563
3756
|
return block[0].chain;
|
|
3564
3757
|
});
|
|
3565
3758
|
}
|
|
@@ -3571,25 +3764,25 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3571
3764
|
}
|
|
3572
3765
|
async currentBlock() {
|
|
3573
3766
|
return await spanRootAsync5("currentBlock", async () => {
|
|
3574
|
-
const currentHead =
|
|
3767
|
+
const currentHead = assertEx24(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
|
|
3575
3768
|
const cache = this.hydratedBlockCache;
|
|
3576
3769
|
const block = await cache.get(currentHead._hash);
|
|
3577
3770
|
if (!block) {
|
|
3578
3771
|
console.log(`Could not find current block with hash ${currentHead._hash}`);
|
|
3579
3772
|
}
|
|
3580
|
-
return
|
|
3773
|
+
return assertEx24(block, () => "Could not find current block");
|
|
3581
3774
|
}, this.tracer);
|
|
3582
3775
|
}
|
|
3583
3776
|
async currentBlockHash() {
|
|
3584
3777
|
return await spanRootAsync5("currentBlockHash", async () => {
|
|
3585
|
-
const currentHead =
|
|
3778
|
+
const currentHead = assertEx24(await this.getCurrentHead(), () => "Could not find most recent block [currentBlockHash]");
|
|
3586
3779
|
return currentHead._hash;
|
|
3587
3780
|
}, this.tracer);
|
|
3588
3781
|
}
|
|
3589
3782
|
async currentBlockNumber() {
|
|
3590
3783
|
return await spanRootAsync5("currentBlockNumber", async () => {
|
|
3591
|
-
const currentHead =
|
|
3592
|
-
return
|
|
3784
|
+
const currentHead = assertEx24(await this.getCurrentHead(), () => "Could not find most recent block [currentBlockNumber]");
|
|
3785
|
+
return asXL1BlockNumber6(currentHead.block, {
|
|
3593
3786
|
name: "currentBlockNumber"
|
|
3594
3787
|
});
|
|
3595
3788
|
}, this.tracer);
|
|
@@ -3602,7 +3795,7 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3602
3795
|
const [result] = await this.finalizedArchivist.get([
|
|
3603
3796
|
hash
|
|
3604
3797
|
]);
|
|
3605
|
-
if (
|
|
3798
|
+
if (isDefined14(result)) {
|
|
3606
3799
|
await this.payloadCache.set(hash, result);
|
|
3607
3800
|
}
|
|
3608
3801
|
return result ?? null;
|
|
@@ -3618,7 +3811,7 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
3618
3811
|
const remainingPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
|
|
3619
3812
|
return [
|
|
3620
3813
|
...cachedPayloads,
|
|
3621
|
-
...remainingPayloads.filter(
|
|
3814
|
+
...remainingPayloads.filter(exists4)
|
|
3622
3815
|
];
|
|
3623
3816
|
}
|
|
3624
3817
|
async getCurrentHead() {
|
|
@@ -3656,9 +3849,9 @@ SimpleBlockRewardViewer = _ts_decorate3([
|
|
|
3656
3849
|
creatableProvider()
|
|
3657
3850
|
], SimpleBlockRewardViewer);
|
|
3658
3851
|
|
|
3659
|
-
// src/simple/
|
|
3660
|
-
import {
|
|
3661
|
-
import {
|
|
3852
|
+
// src/simple/blockValidation/SimpleBlockValidationViewer.ts
|
|
3853
|
+
import { exists as exists5 } from "@xylabs/sdk-js";
|
|
3854
|
+
import { asXL1BlockRange as asXL1BlockRange8 } from "@xyo-network/xl1-protocol";
|
|
3662
3855
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
3663
3856
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3664
3857
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3666,6 +3859,110 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3666
3859
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3667
3860
|
}
|
|
3668
3861
|
__name(_ts_decorate4, "_ts_decorate");
|
|
3862
|
+
var SimpleBlockValidationViewer = class _SimpleBlockValidationViewer extends AbstractCreatableProvider {
|
|
3863
|
+
static {
|
|
3864
|
+
__name(this, "SimpleBlockValidationViewer");
|
|
3865
|
+
}
|
|
3866
|
+
static defaultMoniker = BlockValidationViewerMoniker;
|
|
3867
|
+
static monikers = [
|
|
3868
|
+
BlockValidationViewerMoniker
|
|
3869
|
+
];
|
|
3870
|
+
moniker = _SimpleBlockValidationViewer.defaultMoniker;
|
|
3871
|
+
_accountBalanceViewer;
|
|
3872
|
+
_blockViewer;
|
|
3873
|
+
_uncleWindowedChainCache = null;
|
|
3874
|
+
get blockViewer() {
|
|
3875
|
+
return this._blockViewer;
|
|
3876
|
+
}
|
|
3877
|
+
get maxUncleWindowSize() {
|
|
3878
|
+
return this.params.maxUncleWindowSize;
|
|
3879
|
+
}
|
|
3880
|
+
static async paramsHandler(params) {
|
|
3881
|
+
return {
|
|
3882
|
+
...await super.paramsHandler(params),
|
|
3883
|
+
maxUncleWindowSize: params.maxUncleWindowSize ?? 100
|
|
3884
|
+
};
|
|
3885
|
+
}
|
|
3886
|
+
async createHandler() {
|
|
3887
|
+
await super.createHandler();
|
|
3888
|
+
this._accountBalanceViewer = await this.locator.getInstance(AccountBalanceViewerMoniker);
|
|
3889
|
+
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
|
|
3890
|
+
}
|
|
3891
|
+
async qualifiedValidateBlock(block, config) {
|
|
3892
|
+
return await this.qualifiedValidateBlocks([
|
|
3893
|
+
block
|
|
3894
|
+
], config);
|
|
3895
|
+
}
|
|
3896
|
+
async qualifiedValidateBlocks(blocks, config) {
|
|
3897
|
+
const { value, state } = config ?? {
|
|
3898
|
+
shape: true,
|
|
3899
|
+
links: true,
|
|
3900
|
+
state: true
|
|
3901
|
+
};
|
|
3902
|
+
const [headBlock] = await this.blockViewer.currentBlock();
|
|
3903
|
+
const chainId = headBlock.chain;
|
|
3904
|
+
const validateValue = value ? this.doValidateValue.bind(this) : void 0;
|
|
3905
|
+
const validateState = state ? this.doValidateState.bind(this) : void 0;
|
|
3906
|
+
return [
|
|
3907
|
+
(await Promise.all([
|
|
3908
|
+
validateValue?.(blocks, chainId),
|
|
3909
|
+
validateState?.(blocks, chainId)
|
|
3910
|
+
].filter(exists5))).flat(),
|
|
3911
|
+
{
|
|
3912
|
+
head: headBlock._hash,
|
|
3913
|
+
range: asXL1BlockRange8([
|
|
3914
|
+
0,
|
|
3915
|
+
headBlock.block
|
|
3916
|
+
], true)
|
|
3917
|
+
}
|
|
3918
|
+
];
|
|
3919
|
+
}
|
|
3920
|
+
async validateBlock(block, config) {
|
|
3921
|
+
return await this.validateBlocks([
|
|
3922
|
+
block
|
|
3923
|
+
], config);
|
|
3924
|
+
}
|
|
3925
|
+
async validateBlocks(blocks, config) {
|
|
3926
|
+
return (await this.qualifiedValidateBlocks(blocks, config))[0];
|
|
3927
|
+
}
|
|
3928
|
+
async doValidateState(blocks, chainId) {
|
|
3929
|
+
const windowedUncleChain = await this.updateWindowedChainCache();
|
|
3930
|
+
const uncles = findUncles(this.context, windowedUncleChain, blocks);
|
|
3931
|
+
if (uncles.length !== 1) {
|
|
3932
|
+
throw new Error(`No uncles or greater than one uncle found in block validation, which is not supported [${uncles.length}]`);
|
|
3933
|
+
}
|
|
3934
|
+
return (await Promise.all(uncles[0].map(async (block) => {
|
|
3935
|
+
return await this.params.state(block, chainId, {
|
|
3936
|
+
accountBalance: this._accountBalanceViewer
|
|
3937
|
+
});
|
|
3938
|
+
}))).flat();
|
|
3939
|
+
}
|
|
3940
|
+
async doValidateValue(blocks, chainId) {
|
|
3941
|
+
return (await Promise.all(blocks.map(async (block) => {
|
|
3942
|
+
return await this.params.value(block, chainId);
|
|
3943
|
+
}))).flat();
|
|
3944
|
+
}
|
|
3945
|
+
async updateWindowedChainCache() {
|
|
3946
|
+
this._uncleWindowedChainCache = await getWindowedChain(this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? []);
|
|
3947
|
+
return [
|
|
3948
|
+
...this._uncleWindowedChainCache
|
|
3949
|
+
];
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
SimpleBlockValidationViewer = _ts_decorate4([
|
|
3953
|
+
creatableProvider()
|
|
3954
|
+
], SimpleBlockValidationViewer);
|
|
3955
|
+
|
|
3956
|
+
// src/simple/chainStake/SimpleStakeViewer.ts
|
|
3957
|
+
import { asAddress as asAddress5, toAddress as toAddress9 } from "@xylabs/sdk-js";
|
|
3958
|
+
import { assertEx as assertEx25 } from "@xylabs/sdk-js";
|
|
3959
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
3960
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3961
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3962
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3963
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3964
|
+
}
|
|
3965
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
3669
3966
|
var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvider {
|
|
3670
3967
|
static {
|
|
3671
3968
|
__name(this, "SimpleStakeViewer");
|
|
@@ -3686,7 +3983,7 @@ var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvid
|
|
|
3686
3983
|
return toAddress9(toAddress9(1n));
|
|
3687
3984
|
}
|
|
3688
3985
|
get stakeEvents() {
|
|
3689
|
-
return
|
|
3986
|
+
return assertEx25(this._chainStakeEventsViewer, () => "Stake events viewer not set");
|
|
3690
3987
|
}
|
|
3691
3988
|
get stakingTokenAddress() {
|
|
3692
3989
|
return toAddress9("0x000000000000000000000000000011");
|
|
@@ -3723,7 +4020,7 @@ var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvid
|
|
|
3723
4020
|
}
|
|
3724
4021
|
async createHandler() {
|
|
3725
4022
|
await super.createHandler();
|
|
3726
|
-
this._chainStakeEventsViewer =
|
|
4023
|
+
this._chainStakeEventsViewer = assertEx25(await this.locateAndCreate(StakeEventsViewerMoniker), () => "Failed to create StakeEventsViewer");
|
|
3727
4024
|
}
|
|
3728
4025
|
pending() {
|
|
3729
4026
|
let pending = 0n;
|
|
@@ -3744,7 +4041,7 @@ var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvid
|
|
|
3744
4041
|
return pending;
|
|
3745
4042
|
}
|
|
3746
4043
|
stakeById(id) {
|
|
3747
|
-
return
|
|
4044
|
+
return assertEx25(this.positions[id], () => new Error(`Stake with id ${id} not found`));
|
|
3748
4045
|
}
|
|
3749
4046
|
stakeByStaker(staker, slot) {
|
|
3750
4047
|
return this.positions.filter((s) => asAddress5(s.staker) === asAddress5(staker))[slot];
|
|
@@ -3782,7 +4079,7 @@ var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvid
|
|
|
3782
4079
|
return withdrawn;
|
|
3783
4080
|
}
|
|
3784
4081
|
};
|
|
3785
|
-
SimpleStakeViewer =
|
|
4082
|
+
SimpleStakeViewer = _ts_decorate5([
|
|
3786
4083
|
creatableProvider()
|
|
3787
4084
|
], SimpleStakeViewer);
|
|
3788
4085
|
|
|
@@ -3847,13 +4144,13 @@ var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
|
3847
4144
|
};
|
|
3848
4145
|
|
|
3849
4146
|
// src/simple/datalake/SimpleDataLakeRunner.ts
|
|
3850
|
-
function
|
|
4147
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
3851
4148
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3852
4149
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3853
4150
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3854
4151
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3855
4152
|
}
|
|
3856
|
-
__name(
|
|
4153
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
3857
4154
|
var SimpleDataLakeRunner = class _SimpleDataLakeRunner extends AbstractSimpleDataLake {
|
|
3858
4155
|
static {
|
|
3859
4156
|
__name(this, "SimpleDataLakeRunner");
|
|
@@ -3879,18 +4176,18 @@ var SimpleDataLakeRunner = class _SimpleDataLakeRunner extends AbstractSimpleDat
|
|
|
3879
4176
|
return await this.map.setMany(allowed);
|
|
3880
4177
|
}
|
|
3881
4178
|
};
|
|
3882
|
-
SimpleDataLakeRunner =
|
|
4179
|
+
SimpleDataLakeRunner = _ts_decorate6([
|
|
3883
4180
|
creatableProvider()
|
|
3884
4181
|
], SimpleDataLakeRunner);
|
|
3885
4182
|
|
|
3886
4183
|
// src/simple/datalake/SimpleDataLakeViewer.ts
|
|
3887
|
-
function
|
|
4184
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
3888
4185
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3889
4186
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3890
4187
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3891
4188
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3892
4189
|
}
|
|
3893
|
-
__name(
|
|
4190
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
3894
4191
|
var SimpleDataLakeViewer = class _SimpleDataLakeViewer extends AbstractSimpleDataLake {
|
|
3895
4192
|
static {
|
|
3896
4193
|
__name(this, "SimpleDataLakeViewer");
|
|
@@ -3901,7 +4198,7 @@ var SimpleDataLakeViewer = class _SimpleDataLakeViewer extends AbstractSimpleDat
|
|
|
3901
4198
|
];
|
|
3902
4199
|
moniker = _SimpleDataLakeViewer.defaultMoniker;
|
|
3903
4200
|
};
|
|
3904
|
-
SimpleDataLakeViewer =
|
|
4201
|
+
SimpleDataLakeViewer = _ts_decorate7([
|
|
3905
4202
|
creatableProvider()
|
|
3906
4203
|
], SimpleDataLakeViewer);
|
|
3907
4204
|
|
|
@@ -3931,9 +4228,9 @@ var SimpleXyoGateway = class {
|
|
|
3931
4228
|
};
|
|
3932
4229
|
|
|
3933
4230
|
// src/simple/gateway/SimpleXyoGatewayRunner.ts
|
|
3934
|
-
import { assertEx as
|
|
4231
|
+
import { assertEx as assertEx26, BigIntToJsonZod, isDefined as isDefined15 } from "@xylabs/sdk-js";
|
|
3935
4232
|
import { PayloadBuilder as PayloadBuilder17 } from "@xyo-network/payload-builder";
|
|
3936
|
-
import { asXL1BlockNumber as
|
|
4233
|
+
import { asXL1BlockNumber as asXL1BlockNumber7, TransferSchema as TransferSchema3 } from "@xyo-network/xl1-protocol";
|
|
3937
4234
|
var SimpleXyoGatewayRunner = class {
|
|
3938
4235
|
static {
|
|
3939
4236
|
__name(this, "SimpleXyoGatewayRunner");
|
|
@@ -3962,18 +4259,18 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3962
4259
|
return this._dataLakes.length - 1;
|
|
3963
4260
|
}
|
|
3964
4261
|
async addPayloadsToChain(onChain, offChain, options) {
|
|
3965
|
-
const viewer =
|
|
4262
|
+
const viewer = assertEx26(this.connectionInstance.viewer, () => "No viewer available on connection");
|
|
3966
4263
|
const { nbf, exp, chain, fees } = options ?? {};
|
|
3967
|
-
const resolvedChainId =
|
|
3968
|
-
const resolvedNbf =
|
|
3969
|
-
const resolvedExp =
|
|
4264
|
+
const resolvedChainId = isDefined15(chain) ? chain : await viewer.chainId();
|
|
4265
|
+
const resolvedNbf = asXL1BlockNumber7(isDefined15(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
4266
|
+
const resolvedExp = asXL1BlockNumber7(isDefined15(exp) ? exp : resolvedNbf + 10, true);
|
|
3970
4267
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await (await this.signer()).address(), fees);
|
|
3971
4268
|
return await this.addTransactionToChain(tx);
|
|
3972
4269
|
}
|
|
3973
4270
|
async addTransactionToChain(tx) {
|
|
3974
4271
|
const connection = this.connectionInstance;
|
|
3975
4272
|
const signer = this.signerInstance;
|
|
3976
|
-
const runner =
|
|
4273
|
+
const runner = assertEx26(connection.runner, () => "No runner available on connection");
|
|
3977
4274
|
const signedTx = await signer.signTransaction(tx);
|
|
3978
4275
|
await this.addPayloadsToDataLakes(signedTx[1]);
|
|
3979
4276
|
return [
|
|
@@ -3985,7 +4282,7 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3985
4282
|
];
|
|
3986
4283
|
}
|
|
3987
4284
|
async confirmSubmittedTransaction(txHash, options) {
|
|
3988
|
-
return await confirmSubmittedTransaction(
|
|
4285
|
+
return await confirmSubmittedTransaction(assertEx26(this.connectionInstance.viewer, () => "Connection viewer is undefined"), txHash, options);
|
|
3989
4286
|
}
|
|
3990
4287
|
/** @deprecated use connectionInstance instead */
|
|
3991
4288
|
connection() {
|
|
@@ -4032,13 +4329,13 @@ var SimpleXyoGatewayRunner = class {
|
|
|
4032
4329
|
|
|
4033
4330
|
// src/simple/mempool/SimpleMempoolRunner.ts
|
|
4034
4331
|
import { PayloadBuilder as PayloadBuilder18 } from "@xyo-network/payload-builder";
|
|
4035
|
-
function
|
|
4332
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
4036
4333
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4037
4334
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4038
4335
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4039
4336
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4040
4337
|
}
|
|
4041
|
-
__name(
|
|
4338
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
4042
4339
|
var SimpleMempoolRunner = class _SimpleMempoolRunner extends AbstractCreatableProvider {
|
|
4043
4340
|
static {
|
|
4044
4341
|
__name(this, "SimpleMempoolRunner");
|
|
@@ -4075,20 +4372,20 @@ var SimpleMempoolRunner = class _SimpleMempoolRunner extends AbstractCreatablePr
|
|
|
4075
4372
|
return inserted.map((p) => p._hash);
|
|
4076
4373
|
}
|
|
4077
4374
|
};
|
|
4078
|
-
SimpleMempoolRunner =
|
|
4375
|
+
SimpleMempoolRunner = _ts_decorate8([
|
|
4079
4376
|
creatableProvider()
|
|
4080
4377
|
], SimpleMempoolRunner);
|
|
4081
4378
|
|
|
4082
4379
|
// src/simple/mempool/SimpleMempoolViewer.ts
|
|
4083
|
-
import { creatable, exists as
|
|
4380
|
+
import { creatable, exists as exists6, isDefined as isDefined16, isHash } from "@xylabs/sdk-js";
|
|
4084
4381
|
import { isHashMeta as isHashMeta2, isPayloadBundle } from "@xyo-network/payload-model";
|
|
4085
|
-
function
|
|
4382
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
4086
4383
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4087
4384
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4088
4385
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4089
4386
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4090
4387
|
}
|
|
4091
|
-
__name(
|
|
4388
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
4092
4389
|
var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatableProvider {
|
|
4093
4390
|
static {
|
|
4094
4391
|
__name(this, "SimpleMempoolViewer");
|
|
@@ -4110,7 +4407,7 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
4110
4407
|
const [p] = await this.pendingBlocksArchivist.get([
|
|
4111
4408
|
providedCursor
|
|
4112
4409
|
]);
|
|
4113
|
-
if (
|
|
4410
|
+
if (isDefined16(p)) {
|
|
4114
4411
|
cursor = p._sequence;
|
|
4115
4412
|
}
|
|
4116
4413
|
}
|
|
@@ -4120,7 +4417,7 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
4120
4417
|
cursor
|
|
4121
4418
|
});
|
|
4122
4419
|
const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
|
|
4123
|
-
return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedBlock(bundle3)))).filter(
|
|
4420
|
+
return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedBlock(bundle3)))).filter(exists6);
|
|
4124
4421
|
}
|
|
4125
4422
|
async pendingTransactions({ cursor: providedCursor } = {}) {
|
|
4126
4423
|
let cursor = void 0;
|
|
@@ -4128,7 +4425,7 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
4128
4425
|
const [p] = await this.pendingTransactionsArchivist.get([
|
|
4129
4426
|
providedCursor
|
|
4130
4427
|
]);
|
|
4131
|
-
if (
|
|
4428
|
+
if (isDefined16(p)) {
|
|
4132
4429
|
cursor = p._sequence;
|
|
4133
4430
|
}
|
|
4134
4431
|
}
|
|
@@ -4141,12 +4438,12 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
4141
4438
|
this.logger?.info(`Fetched pending transactions: ${bundles.length} bundles`);
|
|
4142
4439
|
const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
|
|
4143
4440
|
this.logger?.info(`Filtered pending transactions: ${JSON.stringify(bundles, null, 2)} filteredBundles`);
|
|
4144
|
-
const result = (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedTransaction(bundle3)))).filter(
|
|
4441
|
+
const result = (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedTransaction(bundle3)))).filter(exists6);
|
|
4145
4442
|
this.logger?.info(`Converted pending transactions: ${JSON.stringify(result, null, 2)} results`);
|
|
4146
4443
|
return result;
|
|
4147
4444
|
}
|
|
4148
4445
|
};
|
|
4149
|
-
SimpleMempoolViewer =
|
|
4446
|
+
SimpleMempoolViewer = _ts_decorate9([
|
|
4150
4447
|
creatable()
|
|
4151
4448
|
], SimpleMempoolViewer);
|
|
4152
4449
|
|
|
@@ -4223,7 +4520,7 @@ var SimpleXyoNetwork = class {
|
|
|
4223
4520
|
};
|
|
4224
4521
|
|
|
4225
4522
|
// src/simple/permissions/SimpleXyoPermissions.ts
|
|
4226
|
-
import { assertEx as
|
|
4523
|
+
import { assertEx as assertEx27 } from "@xylabs/sdk-js";
|
|
4227
4524
|
var SimpleXyoPermissions = class {
|
|
4228
4525
|
static {
|
|
4229
4526
|
__name(this, "SimpleXyoPermissions");
|
|
@@ -4235,7 +4532,7 @@ var SimpleXyoPermissions = class {
|
|
|
4235
4532
|
this.invoker = store.invoker;
|
|
4236
4533
|
}
|
|
4237
4534
|
get store() {
|
|
4238
|
-
return
|
|
4535
|
+
return assertEx27(this._store, () => "Store must be defined to get permissions");
|
|
4239
4536
|
}
|
|
4240
4537
|
async getPermissions() {
|
|
4241
4538
|
return await this.store.getPermissions();
|
|
@@ -4293,7 +4590,7 @@ var SimpleXyoPermissions = class {
|
|
|
4293
4590
|
};
|
|
4294
4591
|
|
|
4295
4592
|
// src/simple/permissions/store/MemoryPermissions.ts
|
|
4296
|
-
import { assertEx as
|
|
4593
|
+
import { assertEx as assertEx28 } from "@xylabs/sdk-js";
|
|
4297
4594
|
var MemoryPermissionsStore = class {
|
|
4298
4595
|
static {
|
|
4299
4596
|
__name(this, "MemoryPermissionsStore");
|
|
@@ -4304,7 +4601,7 @@ var MemoryPermissionsStore = class {
|
|
|
4304
4601
|
this._invoker = invoker;
|
|
4305
4602
|
}
|
|
4306
4603
|
get invoker() {
|
|
4307
|
-
return
|
|
4604
|
+
return assertEx28(this._invoker, () => "Invoker must be defined to get permissions");
|
|
4308
4605
|
}
|
|
4309
4606
|
async getPermissions() {
|
|
4310
4607
|
await Promise.resolve();
|
|
@@ -4317,7 +4614,7 @@ var MemoryPermissionsStore = class {
|
|
|
4317
4614
|
};
|
|
4318
4615
|
|
|
4319
4616
|
// src/simple/runner/SimpleXyoRunner.ts
|
|
4320
|
-
import { assertEx as
|
|
4617
|
+
import { assertEx as assertEx29 } from "@xylabs/sdk-js";
|
|
4321
4618
|
import { PayloadBuilder as PayloadBuilder19 } from "@xyo-network/payload-builder";
|
|
4322
4619
|
var SimpleXyoRunner = class _SimpleXyoRunner extends AbstractCreatableProvider {
|
|
4323
4620
|
static {
|
|
@@ -4335,7 +4632,7 @@ var SimpleXyoRunner = class _SimpleXyoRunner extends AbstractCreatableProvider {
|
|
|
4335
4632
|
static async paramsHandler(params) {
|
|
4336
4633
|
return {
|
|
4337
4634
|
...await super.paramsHandler(params),
|
|
4338
|
-
pendingTransactionsArchivist:
|
|
4635
|
+
pendingTransactionsArchivist: assertEx29(params?.pendingTransactionsArchivist, () => "A pendingTransactionsArchivist is required to create a SimpleXyoRunner")
|
|
4339
4636
|
};
|
|
4340
4637
|
}
|
|
4341
4638
|
async broadcastTransaction(transaction) {
|
|
@@ -4386,14 +4683,14 @@ var SimpleXyoSigner = class {
|
|
|
4386
4683
|
};
|
|
4387
4684
|
|
|
4388
4685
|
// src/simple/stakeEvents/SimpleStakeEventsViewer.ts
|
|
4389
|
-
import { isDefined as
|
|
4390
|
-
function
|
|
4686
|
+
import { isDefined as isDefined17 } from "@xylabs/sdk-js";
|
|
4687
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
4391
4688
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4392
4689
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4393
4690
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4394
4691
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4395
4692
|
}
|
|
4396
|
-
__name(
|
|
4693
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
4397
4694
|
var SimpleStakeEventsViewer = class _SimpleStakeEventsViewer extends AbstractCreatableProvider {
|
|
4398
4695
|
static {
|
|
4399
4696
|
__name(this, "SimpleStakeEventsViewer");
|
|
@@ -4412,7 +4709,7 @@ var SimpleStakeEventsViewer = class _SimpleStakeEventsViewer extends AbstractCre
|
|
|
4412
4709
|
stakeEvents(range, { name } = {}) {
|
|
4413
4710
|
const positions = this.positionsFromRange(range);
|
|
4414
4711
|
const events = this.eventsFromPositions(positions);
|
|
4415
|
-
if (
|
|
4712
|
+
if (isDefined17(name)) {
|
|
4416
4713
|
return events.filter((event) => event.name === name);
|
|
4417
4714
|
}
|
|
4418
4715
|
return events;
|
|
@@ -4471,13 +4768,13 @@ var SimpleStakeEventsViewer = class _SimpleStakeEventsViewer extends AbstractCre
|
|
|
4471
4768
|
return filteredPositions;
|
|
4472
4769
|
}
|
|
4473
4770
|
};
|
|
4474
|
-
SimpleStakeEventsViewer =
|
|
4771
|
+
SimpleStakeEventsViewer = _ts_decorate10([
|
|
4475
4772
|
creatableProvider()
|
|
4476
4773
|
], SimpleStakeEventsViewer);
|
|
4477
4774
|
|
|
4478
4775
|
// src/simple/timesync/SimpleTimeSyncViewer.ts
|
|
4479
|
-
import { asHash as asHash6, assertEx as
|
|
4480
|
-
import { asTimePayload as asTimePayload2, asXL1BlockNumber as
|
|
4776
|
+
import { asHash as asHash6, assertEx as assertEx30, isDefined as isDefined18 } from "@xylabs/sdk-js";
|
|
4777
|
+
import { asTimePayload as asTimePayload2, asXL1BlockNumber as asXL1BlockNumber8, TimeSchema } from "@xyo-network/xl1-protocol";
|
|
4481
4778
|
var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatableProvider {
|
|
4482
4779
|
static {
|
|
4483
4780
|
__name(this, "SimpleTimeSyncViewer");
|
|
@@ -4497,10 +4794,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
4497
4794
|
async convertTime(fromDomain, toDomain, from) {
|
|
4498
4795
|
switch (fromDomain) {
|
|
4499
4796
|
case "xl1": {
|
|
4500
|
-
const [block, payloads] =
|
|
4797
|
+
const [block, payloads] = assertEx30(await this.blockViewer.blockByNumber(asXL1BlockNumber8(from, true)), () => "Block not found");
|
|
4501
4798
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
4502
4799
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
4503
|
-
const timePayload = asTimePayload2(
|
|
4800
|
+
const timePayload = asTimePayload2(isDefined18(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
4504
4801
|
if (timePayload === void 0) return 0;
|
|
4505
4802
|
switch (toDomain) {
|
|
4506
4803
|
case "xl1": {
|
|
@@ -4567,10 +4864,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
4567
4864
|
];
|
|
4568
4865
|
}
|
|
4569
4866
|
case "ethereum": {
|
|
4570
|
-
const provider =
|
|
4867
|
+
const provider = assertEx30(this.ethProvider, () => "Ethereum provider not configured");
|
|
4571
4868
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
4572
4869
|
const block = await provider.getBlock(blockNumber);
|
|
4573
|
-
const blockHash = asHash6(
|
|
4870
|
+
const blockHash = asHash6(assertEx30(block?.hash, () => "Block hash not found"), true);
|
|
4574
4871
|
return [
|
|
4575
4872
|
blockNumber,
|
|
4576
4873
|
blockHash
|
|
@@ -4588,10 +4885,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
4588
4885
|
// this is for the previous block
|
|
4589
4886
|
xl1,
|
|
4590
4887
|
// this is for the previous block
|
|
4591
|
-
xl1Hash:
|
|
4888
|
+
xl1Hash: assertEx30(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
4592
4889
|
epoch: Date.now()
|
|
4593
4890
|
};
|
|
4594
|
-
if (
|
|
4891
|
+
if (isDefined18(this.ethProvider)) {
|
|
4595
4892
|
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
|
|
4596
4893
|
const ethereumHash = asHash6(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
4597
4894
|
timePayload.ethereum = ethereum;
|
|
@@ -4692,7 +4989,7 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
4692
4989
|
};
|
|
4693
4990
|
|
|
4694
4991
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
4695
|
-
import { assertEx as
|
|
4992
|
+
import { assertEx as assertEx31 } from "@xylabs/sdk-js";
|
|
4696
4993
|
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
4697
4994
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
4698
4995
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
@@ -4700,7 +4997,7 @@ async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
|
4700
4997
|
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), {
|
|
4701
4998
|
required: true
|
|
4702
4999
|
});
|
|
4703
|
-
return
|
|
5000
|
+
return assertEx31(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
4704
5001
|
}
|
|
4705
5002
|
__name(xl1BlockNumberToEthBlockNumber, "xl1BlockNumberToEthBlockNumber");
|
|
4706
5003
|
|
|
@@ -4735,14 +5032,20 @@ export {
|
|
|
4735
5032
|
ACCOUNT_TYPE,
|
|
4736
5033
|
ADDRESS_INDEX,
|
|
4737
5034
|
AbstractCreatableProvider,
|
|
5035
|
+
AccountBalanceConfigZod,
|
|
4738
5036
|
AccountBalanceHistoryItemZod,
|
|
5037
|
+
AccountBalanceQualificationZod,
|
|
4739
5038
|
AccountBalanceViewerMoniker,
|
|
4740
5039
|
AddressPairSchema,
|
|
4741
5040
|
BalancesStepSummarySchema,
|
|
4742
5041
|
BasisPointsZod,
|
|
4743
5042
|
BlockRewardViewerMoniker,
|
|
4744
5043
|
BlockRunnerMoniker,
|
|
5044
|
+
BlockValidationConfigFieldsZod,
|
|
5045
|
+
BlockValidationConfigZod,
|
|
4745
5046
|
BlockValidationError,
|
|
5047
|
+
BlockValidationQualificationZod,
|
|
5048
|
+
BlockValidationViewerMoniker,
|
|
4746
5049
|
BlockViewerMoniker,
|
|
4747
5050
|
BridgeConfigZod,
|
|
4748
5051
|
BridgeSettingsZod,
|
|
@@ -4750,6 +5053,11 @@ export {
|
|
|
4750
5053
|
COIN_TYPES,
|
|
4751
5054
|
ChainContractViewerMoniker,
|
|
4752
5055
|
ChainIndexingServiceStateSchema,
|
|
5056
|
+
ChainQualificationZod,
|
|
5057
|
+
ChainQualifiedConfigZod,
|
|
5058
|
+
ChainQualifiedHeadConfigZod,
|
|
5059
|
+
ChainQualifiedRangeConfigZod,
|
|
5060
|
+
ChainQualifiedZod,
|
|
4753
5061
|
ChainStakeViewerMoniker,
|
|
4754
5062
|
ConfigZod,
|
|
4755
5063
|
DEFAULT_WALLET_PATH,
|
|
@@ -4760,6 +5068,7 @@ export {
|
|
|
4760
5068
|
EIP712DataPayloadSchema,
|
|
4761
5069
|
EIP712SignaturePayloadFieldsZod,
|
|
4762
5070
|
EIP712SignaturePayloadSchema,
|
|
5071
|
+
ExtendChainQualifiedConfigZod,
|
|
4763
5072
|
GlobalMetaSchema,
|
|
4764
5073
|
HydratedBlockStateValidationError,
|
|
4765
5074
|
HydratedBlockValidationError,
|
|
@@ -4783,12 +5092,12 @@ export {
|
|
|
4783
5092
|
PendingTransactionsOptionsZod,
|
|
4784
5093
|
ProviderFactory,
|
|
4785
5094
|
ProviderFactoryLocator,
|
|
4786
|
-
QualifiedZod,
|
|
4787
5095
|
RewardMultipliers,
|
|
4788
5096
|
RuntimeStatusMonitor,
|
|
4789
5097
|
SchemasStepSummarySchema,
|
|
4790
5098
|
SimpleAccountBalanceViewer,
|
|
4791
5099
|
SimpleBlockRewardViewer,
|
|
5100
|
+
SimpleBlockValidationViewer,
|
|
4792
5101
|
SimpleBlockViewer,
|
|
4793
5102
|
SimpleDataLakeRunner,
|
|
4794
5103
|
SimpleDataLakeViewer,
|
|
@@ -4815,6 +5124,9 @@ export {
|
|
|
4815
5124
|
TODO,
|
|
4816
5125
|
TimeSyncViewerMoniker,
|
|
4817
5126
|
TransactionBuilder,
|
|
5127
|
+
TransactionValidationConfigZod,
|
|
5128
|
+
TransactionValidationQualificationZod,
|
|
5129
|
+
TransactionValidationViewerMoniker,
|
|
4818
5130
|
TransferBalanceViewerMoniker,
|
|
4819
5131
|
TransfersStepSummarySchema,
|
|
4820
5132
|
TypedDataDomainZod,
|
|
@@ -4878,7 +5190,9 @@ export {
|
|
|
4878
5190
|
externalBlockRangeFromXL1BlockRange,
|
|
4879
5191
|
extractElevatedHashes,
|
|
4880
5192
|
extractElevatedHashesFromScript,
|
|
5193
|
+
findBestUncle,
|
|
4881
5194
|
findMostRecentBlock,
|
|
5195
|
+
findUncles,
|
|
4882
5196
|
flattenHydratedBlock,
|
|
4883
5197
|
flattenHydratedBlocks,
|
|
4884
5198
|
flattenHydratedTransaction,
|
|
@@ -4886,6 +5200,7 @@ export {
|
|
|
4886
5200
|
generateXyoBaseWalletFromPhrase,
|
|
4887
5201
|
getDefaultConfig,
|
|
4888
5202
|
getUrl,
|
|
5203
|
+
getWindowedChain,
|
|
4889
5204
|
hasLabels,
|
|
4890
5205
|
hasMongoConfig,
|
|
4891
5206
|
hashFromBlockNumber,
|
|
@@ -4895,12 +5210,20 @@ export {
|
|
|
4895
5210
|
hydratedBlockByNumber,
|
|
4896
5211
|
hydratedBlockToPayloadBundle,
|
|
4897
5212
|
hydratedTransactionToPayloadBundle,
|
|
5213
|
+
isAccountBalanceCOnfig,
|
|
5214
|
+
isAccountBalanceQualification,
|
|
4898
5215
|
isAddressPairPayload,
|
|
4899
5216
|
isBalancesStepSummary,
|
|
4900
5217
|
isBalancesStepSummaryWithStorageMeta,
|
|
5218
|
+
isBlockValidationConfig,
|
|
4901
5219
|
isBlockValidationError,
|
|
5220
|
+
isBlockValidationQualification,
|
|
4902
5221
|
isChainIndexingServiceState,
|
|
4903
5222
|
isChainIndexingServiceStateWithStorageMeta,
|
|
5223
|
+
isChainQualification,
|
|
5224
|
+
isChainQualifiedConfig,
|
|
5225
|
+
isChainQualifiedHeadConfig,
|
|
5226
|
+
isChainQualifiedRangeConfig,
|
|
4904
5227
|
isEIP712DataPayload,
|
|
4905
5228
|
isEIP712SignaturePayload,
|
|
4906
5229
|
isHydratedBlockStateValidationError,
|
|
@@ -4912,6 +5235,8 @@ export {
|
|
|
4912
5235
|
isReadWriteArchivist,
|
|
4913
5236
|
isSchemasStepSummary,
|
|
4914
5237
|
isSchemasStepSummaryWithStorageMeta,
|
|
5238
|
+
isTransactionValidationConfig,
|
|
5239
|
+
isTransactionValidationQualification,
|
|
4915
5240
|
isTransfersStepSummary,
|
|
4916
5241
|
isTransfersStepSummaryWithStorageMeta,
|
|
4917
5242
|
isUsageMeta,
|
|
@@ -4935,6 +5260,7 @@ export {
|
|
|
4935
5260
|
rewardFromBlockNumber,
|
|
4936
5261
|
schemasStepSummaryFromRange,
|
|
4937
5262
|
schemasSummary,
|
|
5263
|
+
scoreUncle,
|
|
4938
5264
|
signEIP712Message,
|
|
4939
5265
|
signTransaction,
|
|
4940
5266
|
stepBlockRange,
|