@xyo-network/xl1-protocol-sdk 3.0.15 → 3.1.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.
@@ -3101,7 +3101,7 @@ import {
3101
3101
  } from "@xylabs/sdk-js";
3102
3102
  import { CachingContextZod } from "@xyo-network/xl1-protocol-lib";
3103
3103
  import { z as z19 } from "zod/mini";
3104
- var RuntimeStatusMonitorZod = z19.custom((val) => val !== null && val !== void 0 && typeof val === "object");
3104
+ var SystemStatusRunnerZod = z19.custom((val) => val !== null && val !== void 0 && typeof val === "object");
3105
3105
  var ProviderFactoryLocatorZod = z19.lazy(() => z19.custom((val) => val !== null && val !== void 0 && typeof val === "object" && "context" in val && "registry" in val));
3106
3106
  var BaseConfigContextZod = z19.extend(CachingContextZod, {
3107
3107
  config: z19.looseObject(BaseConfigZod.shape),
@@ -3110,7 +3110,7 @@ var BaseConfigContextZod = z19.extend(CachingContextZod, {
3110
3110
  var CreatableProviderContextZod = z19.lazy(() => z19.extend(BaseConfigContextZod, {
3111
3111
  _id: z19.optional(z19.string()),
3112
3112
  locator: ProviderFactoryLocatorZod,
3113
- statusReporter: z19.optional(RuntimeStatusMonitorZod)
3113
+ statusReporter: z19.optional(SystemStatusRunnerZod)
3114
3114
  }));
3115
3115
  var isBaseConfigContext = zodIsFactory4(BaseConfigContextZod);
3116
3116
  var asBaseConfigContext = zodAsFactory5(BaseConfigContextZod, "asBaseConfigContext");
@@ -6781,10 +6781,43 @@ RestSyncViewer = __decorateClass([
6781
6781
  creatableProvider()
6782
6782
  ], RestSyncViewer);
6783
6783
 
6784
+ // src/simple/systemStatus/SimpleSystemStatusViewer.ts
6785
+ import { assertEx as assertEx50 } from "@xylabs/sdk-js";
6786
+ import { SystemStatusViewerMoniker } from "@xyo-network/xl1-protocol-lib";
6787
+ var SimpleSystemStatusViewer = class extends AbstractCreatableProvider {
6788
+ moniker = SimpleSystemStatusViewer.defaultMoniker;
6789
+ get runner() {
6790
+ return assertEx50(this.context.statusReporter, () => "SystemStatusViewer requires a SystemStatusRunner (context.statusReporter)");
6791
+ }
6792
+ getGlobalStatus() {
6793
+ return this.runner.getGlobalStatus();
6794
+ }
6795
+ getStatus(name) {
6796
+ return this.runner.getStatus(name);
6797
+ }
6798
+ isReady() {
6799
+ return this.runner.isReady();
6800
+ }
6801
+ isShuttingDown() {
6802
+ return this.runner.isShuttingDown();
6803
+ }
6804
+ snapshot() {
6805
+ return this.runner.snapshot();
6806
+ }
6807
+ };
6808
+ __publicField(SimpleSystemStatusViewer, "connectionTypes", ["memory"]);
6809
+ __publicField(SimpleSystemStatusViewer, "defaultMoniker", SystemStatusViewerMoniker);
6810
+ __publicField(SimpleSystemStatusViewer, "dependencies", []);
6811
+ __publicField(SimpleSystemStatusViewer, "monikers", [SystemStatusViewerMoniker]);
6812
+ __publicField(SimpleSystemStatusViewer, "surface", "node");
6813
+ SimpleSystemStatusViewer = __decorateClass([
6814
+ creatableProvider()
6815
+ ], SimpleSystemStatusViewer);
6816
+
6784
6817
  // src/simple/timeSync2/SimpleTimeSyncViewer.ts
6785
6818
  import {
6786
6819
  asHash as asHash5,
6787
- assertEx as assertEx50,
6820
+ assertEx as assertEx51,
6788
6821
  isDefined as isDefined22
6789
6822
  } from "@xylabs/sdk-js";
6790
6823
  import {
@@ -6806,7 +6839,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
6806
6839
  async convertTime(fromDomain, toDomain, from) {
6807
6840
  switch (fromDomain) {
6808
6841
  case "xl1": {
6809
- const [block, payloads] = assertEx50(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
6842
+ const [block, payloads] = assertEx51(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
6810
6843
  const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
6811
6844
  const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
6812
6845
  const timePayload = asTimePayload2(isDefined22(hash) ? payloads.find((p) => p._hash === hash) : void 0);
@@ -6862,10 +6895,10 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
6862
6895
  return [Date.now(), null];
6863
6896
  }
6864
6897
  case "ethereum": {
6865
- const provider = assertEx50(this.ethProvider, () => "Ethereum provider not configured");
6898
+ const provider = assertEx51(this.ethProvider, () => "Ethereum provider not configured");
6866
6899
  const blockNumber = await provider.getBlockNumber() ?? 0;
6867
6900
  const block = await provider.getBlock(blockNumber);
6868
- const blockHash = asHash5(assertEx50(block?.hash, () => "Block hash not found"), true);
6901
+ const blockHash = asHash5(assertEx51(block?.hash, () => "Block hash not found"), true);
6869
6902
  return [blockNumber, blockHash];
6870
6903
  }
6871
6904
  default: {
@@ -6880,7 +6913,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
6880
6913
  // this is for the previous block
6881
6914
  xl1,
6882
6915
  // this is for the previous block
6883
- xl1Hash: assertEx50(xl1Hash, () => "No xl1 hash available from time sync service"),
6916
+ xl1Hash: assertEx51(xl1Hash, () => "No xl1 hash available from time sync service"),
6884
6917
  epoch: Date.now()
6885
6918
  };
6886
6919
  if (isDefined22(this.ethProvider)) {
@@ -6902,7 +6935,7 @@ SimpleTimeSyncViewer = __decorateClass([
6902
6935
  ], SimpleTimeSyncViewer);
6903
6936
 
6904
6937
  // src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
6905
- import { assertEx as assertEx51 } from "@xylabs/sdk-js";
6938
+ import { assertEx as assertEx52 } from "@xylabs/sdk-js";
6906
6939
  import { PayloadBuilder as PayloadBuilder24 } from "@xyo-network/sdk-js";
6907
6940
  import {
6908
6941
  AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
@@ -6956,7 +6989,7 @@ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider
6956
6989
  let head;
6957
6990
  if (isChainQualifiedHeadConfig6(config)) {
6958
6991
  const headBlockResult = await this.blockViewer.blockByHash(config.head);
6959
- head = headBlockResult == null ? assertEx51(
6992
+ head = headBlockResult == null ? assertEx52(
6960
6993
  void 0,
6961
6994
  () => `Specified a head that is not in the chain [${config.head}]`
6962
6995
  ) : headBlockResult[0];
@@ -7028,7 +7061,7 @@ SimpleTransactionValidationViewer = __decorateClass([
7028
7061
  ], SimpleTransactionValidationViewer);
7029
7062
 
7030
7063
  // src/simple/TransactionViewer/SimpleTransactionViewer.ts
7031
- import { assertEx as assertEx52, exists as exists10 } from "@xylabs/sdk-js";
7064
+ import { assertEx as assertEx53, exists as exists10 } from "@xylabs/sdk-js";
7032
7065
  import { BoundWitnessSchema } from "@xyo-network/sdk-js";
7033
7066
  import {
7034
7067
  asSignedHydratedTransactionWithHashMeta as asSignedHydratedTransactionWithHashMeta2,
@@ -7045,7 +7078,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
7045
7078
  }
7046
7079
  async byBlockHashAndIndex(blockHash, transactionIndex) {
7047
7080
  return await this.spanAsync("byBlockHashAndIndex", async () => {
7048
- assertEx52(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
7081
+ assertEx53(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
7049
7082
  try {
7050
7083
  const block = await this.blockViewer.blockByHash(blockHash);
7051
7084
  if (!block) return null;
@@ -7110,7 +7143,7 @@ SimpleTransactionViewer = __decorateClass([
7110
7143
 
7111
7144
  // src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
7112
7145
  import {
7113
- assertEx as assertEx53,
7146
+ assertEx as assertEx54,
7114
7147
  exists as exists11,
7115
7148
  isNull as isNull2
7116
7149
  } from "@xylabs/sdk-js";
@@ -7192,7 +7225,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
7192
7225
  }
7193
7226
  async createHandler() {
7194
7227
  await super.createHandler();
7195
- this._blockViewer = assertEx53(
7228
+ this._blockViewer = assertEx54(
7196
7229
  this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
7197
7230
  () => "BlockViewer instance is required"
7198
7231
  );
@@ -7201,13 +7234,13 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
7201
7234
  this._transactionHashMap = new MemoryMap2();
7202
7235
  }
7203
7236
  currentBlock() {
7204
- return assertEx53(this._chain.at(-1));
7237
+ return assertEx54(this._chain.at(-1));
7205
7238
  }
7206
7239
  currentBlockHash() {
7207
- return assertEx53(this._chain.at(-1)?.[0]._hash);
7240
+ return assertEx54(this._chain.at(-1)?.[0]._hash);
7208
7241
  }
7209
7242
  currentBlockNumber() {
7210
- return assertEx53(this._chain.at(-1)?.[0].block);
7243
+ return assertEx54(this._chain.at(-1)?.[0].block);
7211
7244
  }
7212
7245
  async payloadByHash(hash) {
7213
7246
  const payloads = await this.payloadsByHash([hash]);
@@ -7301,7 +7334,17 @@ var LoggerStatusReporter = class {
7301
7334
  }
7302
7335
  };
7303
7336
 
7304
- // src/status/RuntimeStatusMonitor.ts
7337
+ // src/status/SimpleSystemStatusRunner.ts
7338
+ import {
7339
+ SystemStatusPublisherMoniker,
7340
+ SystemStatusRunnerMoniker,
7341
+ SystemStatusViewerMoniker as SystemStatusViewerMoniker2
7342
+ } from "@xyo-network/xl1-protocol-lib";
7343
+ var STATUS_INFRASTRUCTURE_NAMES = /* @__PURE__ */ new Set([
7344
+ SystemStatusRunnerMoniker,
7345
+ SystemStatusViewerMoniker2,
7346
+ SystemStatusPublisherMoniker
7347
+ ]);
7305
7348
  var statusPriority = {
7306
7349
  error: 0,
7307
7350
  stopped: 1,
@@ -7324,22 +7367,35 @@ var reduceToMinimumStatus = (statuses) => {
7324
7367
  }
7325
7368
  return minStatus;
7326
7369
  };
7327
- var RuntimeStatusMonitor = class extends LoggerStatusReporter {
7370
+ var SimpleSystemStatusRunner = class extends LoggerStatusReporter {
7371
+ moniker = SystemStatusRunnerMoniker;
7328
7372
  globalTransitions = [];
7373
+ progressMap = {};
7374
+ readinessMap = {};
7375
+ reportErrorMap = {};
7376
+ shuttingDown = false;
7329
7377
  transitions = [];
7378
+ updatedAtMap = {};
7330
7379
  getGlobalStatus() {
7331
- if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS;
7332
- return reduceToMinimumStatus(Object.values(this.statusMap));
7380
+ const statuses = Object.entries(this.statusMap).filter(([name]) => !STATUS_INFRASTRUCTURE_NAMES.has(name)).map(([, status]) => status);
7381
+ if (statuses.length === 0) return SENTINEL_STATUS;
7382
+ return reduceToMinimumStatus(statuses);
7333
7383
  }
7334
7384
  getStatus(name) {
7335
7385
  return this.statusMap[name];
7336
7386
  }
7387
+ isReady() {
7388
+ if (this.shuttingDown) return false;
7389
+ const entries = Object.values(this.readinessMap);
7390
+ if (entries.length === 0) return false;
7391
+ return entries.every((entry) => entry?.readiness === "ready");
7392
+ }
7393
+ isShuttingDown() {
7394
+ return this.shuttingDown;
7395
+ }
7337
7396
  onGlobalTransition(match, handler) {
7338
7397
  this.globalTransitions.push({ ...match, handler });
7339
7398
  }
7340
- /**
7341
- * Register a callback to be called on a specific transition.
7342
- */
7343
7399
  onTransition(match, handler) {
7344
7400
  this.transitions.push({ ...match, handler });
7345
7401
  }
@@ -7347,12 +7403,45 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
7347
7403
  const previous = this.statusMap[name];
7348
7404
  const previousGlobal = this.getGlobalStatus();
7349
7405
  super.report(name, status, progress);
7406
+ this.updatedAtMap[name] = Date.now();
7407
+ if (progress instanceof Error) {
7408
+ this.reportErrorMap[name] = progress.message;
7409
+ } else if (typeof progress === "number") {
7410
+ this.progressMap[name] = progress;
7411
+ }
7350
7412
  if (previous === status) return;
7351
- this.runTransitions(this.transitions, previous, status, name);
7413
+ this.runTransitions(this.transitions, previous ?? status, status, name);
7352
7414
  const globalStatus = this.getGlobalStatus();
7353
7415
  if (previousGlobal === globalStatus) return;
7354
7416
  this.runTransitions(this.globalTransitions, previousGlobal, globalStatus);
7355
7417
  }
7418
+ reportReady(name, readiness, error) {
7419
+ const message = error instanceof Error ? error.message : error;
7420
+ this.readinessMap[name] = { readiness, error: message };
7421
+ this.updatedAtMap[name] = Date.now();
7422
+ }
7423
+ setShuttingDown(shuttingDown) {
7424
+ this.shuttingDown = shuttingDown;
7425
+ }
7426
+ snapshot() {
7427
+ const components = Object.entries(this.statusMap).map(([name, lifecycle]) => {
7428
+ const readinessEntry = this.readinessMap[name];
7429
+ return {
7430
+ name,
7431
+ lifecycle,
7432
+ readiness: readinessEntry?.readiness,
7433
+ progress: this.progressMap[name],
7434
+ error: readinessEntry?.error ?? this.reportErrorMap[name],
7435
+ updatedAt: this.updatedAtMap[name] ?? 0
7436
+ };
7437
+ });
7438
+ return {
7439
+ components,
7440
+ globalStatus: this.getGlobalStatus(),
7441
+ isReady: this.isReady(),
7442
+ isShuttingDown: this.shuttingDown
7443
+ };
7444
+ }
7356
7445
  runTransitions(transitions, prev, next, name) {
7357
7446
  for (const {
7358
7447
  from,
@@ -7368,7 +7457,7 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
7368
7457
  };
7369
7458
 
7370
7459
  // src/test/buildRandomChain.ts
7371
- import { asAddress as asAddress2, assertEx as assertEx56 } from "@xylabs/sdk-js";
7460
+ import { asAddress as asAddress2, assertEx as assertEx57 } from "@xylabs/sdk-js";
7372
7461
  import {
7373
7462
  Account as Account4,
7374
7463
  asSchema as asSchema9,
@@ -7387,7 +7476,7 @@ import {
7387
7476
  } from "@xyo-network/xl1-protocol-lib";
7388
7477
 
7389
7478
  // src/test/buildBlock.ts
7390
- import { assertEx as assertEx54, isDefined as isDefined23 } from "@xylabs/sdk-js";
7479
+ import { assertEx as assertEx55, isDefined as isDefined23 } from "@xylabs/sdk-js";
7391
7480
  import {
7392
7481
  asAnyPayload as asAnyPayload5,
7393
7482
  BoundWitnessBuilder as BoundWitnessBuilder4,
@@ -7470,7 +7559,7 @@ function buildStepHashes(blockNumber, inStepHashes, previousBlockHash, chainStep
7470
7559
  const completedStepReward = calculateCompletedStepReward(i, stepRewardPoolBalance);
7471
7560
  completedStepRewardTransfers.push(createTransferPayload(chainStepRewardAddress2, { [completedStepRewardHolderAddress]: completedStepReward }));
7472
7561
  }
7473
- step_hashes.push(assertEx54(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`));
7562
+ step_hashes.push(assertEx55(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`));
7474
7563
  } else if (isDefined23(inStepHashes.at(i))) {
7475
7564
  step_hashes.push(inStepHashes[i]);
7476
7565
  }
@@ -7524,7 +7613,7 @@ async function buildBlock(options) {
7524
7613
  protocol
7525
7614
  }).meta({ $epoch: Date.now(), $signatures: [] }).signers(signers).payloads(await PayloadBuilder25.addStorageMeta(payloads));
7526
7615
  const [bw, txPayloads] = await builder.build();
7527
- assertEx54(isBlockBoundWitness(bw), () => "Build of BlockBoundWitness failed");
7616
+ assertEx55(isBlockBoundWitness(bw), () => "Build of BlockBoundWitness failed");
7528
7617
  return [await PayloadBuilder25.addStorageMeta(bw), txPayloads.map((p) => asAnyPayload5(p, true))];
7529
7618
  }
7530
7619
 
@@ -7545,7 +7634,7 @@ async function buildNextBlock(previousBlock, txs, blockPayloads, signers, chainS
7545
7634
  }
7546
7635
 
7547
7636
  // src/test/buildRandomGenesisBlock.ts
7548
- import { asAddress, assertEx as assertEx55 } from "@xylabs/sdk-js";
7637
+ import { asAddress, assertEx as assertEx56 } from "@xylabs/sdk-js";
7549
7638
  import {
7550
7639
  Account as Account3,
7551
7640
  asAnyPayload as asAnyPayload6,
@@ -7589,7 +7678,7 @@ var buildRandomTransaction = async (chain, payloads, account, nbf = asXL1BlockNu
7589
7678
  };
7590
7679
 
7591
7680
  // src/test/buildRandomGenesisBlock.ts
7592
- var TestChainId = assertEx55(asAddress("c5fe2e6F6841Cbab12d8C0618Be2DF8C6156cC44"));
7681
+ var TestChainId = assertEx56(asAddress("c5fe2e6F6841Cbab12d8C0618Be2DF8C6156cC44"));
7593
7682
 
7594
7683
  // src/test/createGenesisBlock.ts
7595
7684
  import { PayloadBuilder as PayloadBuilder28 } from "@xyo-network/sdk-js";
@@ -7644,7 +7733,7 @@ var createGenesisBlock = async (initialBlockProducer, nextContractAddress, genes
7644
7733
  };
7645
7734
 
7646
7735
  // src/test/buildRandomChain.ts
7647
- var TestGenesisBlockRewardAddress = assertEx56(asAddress2("fa7f0bb865a4bfff3d5e2c726d3e063297014da9"));
7736
+ var TestGenesisBlockRewardAddress = assertEx57(asAddress2("fa7f0bb865a4bfff3d5e2c726d3e063297014da9"));
7648
7737
  var buildRandomChain = async (blockProducer, count = 10, previousBlock, chainId, transactionAccount, receiverAddresses) => {
7649
7738
  const chainIdToUse = chainId ?? TestChainId;
7650
7739
  const blocks = [];
@@ -7688,7 +7777,7 @@ var buildRandomChain = async (blockProducer, count = 10, previousBlock, chainId,
7688
7777
  receiverAddress
7689
7778
  ));
7690
7779
  }
7691
- const previousBlock2 = assertEx56(lastBlock?.[0], () => new Error("No last block"));
7780
+ const previousBlock2 = assertEx57(lastBlock?.[0], () => new Error("No last block"));
7692
7781
  const block = await buildNextBlock(previousBlock2, txs, [], [blockProducer], transactionAccountToUse.address);
7693
7782
  blocks.push(block);
7694
7783
  remaining = remaining - 1;
@@ -7749,13 +7838,13 @@ function getTestProviderContext2(config) {
7749
7838
  }
7750
7839
 
7751
7840
  // src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
7752
- import { assertEx as assertEx57 } from "@xylabs/sdk-js";
7841
+ import { assertEx as assertEx58 } from "@xylabs/sdk-js";
7753
7842
  import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
7754
7843
  async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
7755
7844
  const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
7756
7845
  const hydratedBlock = await hydrateBlock(context, blockHash);
7757
7846
  const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
7758
- return assertEx57(timePayload.ethereum, () => "No ethereum timestamp found on block");
7847
+ return assertEx58(timePayload.ethereum, () => "No ethereum timestamp found on block");
7759
7848
  }
7760
7849
 
7761
7850
  // src/validation/lib/isLocalhost.ts
@@ -7871,8 +7960,6 @@ export {
7871
7960
  RpcConnectionConfigZod,
7872
7961
  RpcRemoteConfigBaseZod,
7873
7962
  RpcRemoteConfigZod,
7874
- RuntimeStatusMonitor,
7875
- RuntimeStatusMonitorZod,
7876
7963
  S3BucketConfigZod,
7877
7964
  S3ConnectionConfigZod,
7878
7965
  SchemasStepSummarySchema,
@@ -7891,6 +7978,8 @@ export {
7891
7978
  SimpleStakeEventsViewer,
7892
7979
  SimpleStakeTotalsViewer,
7893
7980
  SimpleStakeViewer,
7981
+ SimpleSystemStatusRunner,
7982
+ SimpleSystemStatusViewer,
7894
7983
  SimpleTimeSyncViewer,
7895
7984
  SimpleTransactionValidationViewer,
7896
7985
  SimpleTransactionViewer,
@@ -7902,6 +7991,7 @@ export {
7902
7991
  SimpleXyoPermissions,
7903
7992
  SimpleXyoRunner,
7904
7993
  SimpleXyoSigner,
7994
+ SystemStatusRunnerZod,
7905
7995
  TODO,
7906
7996
  TestGenesisBlockRewardAddress,
7907
7997
  TransactionBuilder,