@xyo-network/xl1-protocol-sdk 1.26.6 → 1.26.7

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.
@@ -5712,16 +5712,133 @@ SimpleTimeSyncViewer = __decorateClass([
5712
5712
  creatableProvider()
5713
5713
  ], SimpleTimeSyncViewer);
5714
5714
 
5715
+ // src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
5716
+ import { assertEx as assertEx45 } from "@xylabs/sdk-js";
5717
+ import { PayloadBuilder as PayloadBuilder23 } from "@xyo-network/sdk-js";
5718
+ import {
5719
+ AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
5720
+ asXL1BlockRange as asXL1BlockRange12,
5721
+ BlockViewerMoniker as BlockViewerMoniker5,
5722
+ ChainContractViewerMoniker as ChainContractViewerMoniker5,
5723
+ isChainQualifiedHeadConfig as isChainQualifiedHeadConfig6,
5724
+ isHydratedTransaction,
5725
+ TransactionValidationViewerMoniker as TransactionValidationViewerMoniker2
5726
+ } from "@xyo-network/xl1-protocol-lib";
5727
+ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider {
5728
+ moniker = SimpleTransactionValidationViewer.defaultMoniker;
5729
+ _accountBalanceViewer;
5730
+ _blockViewer;
5731
+ _chainContractViewer;
5732
+ get blockViewer() {
5733
+ return this._blockViewer;
5734
+ }
5735
+ get chainContractViewer() {
5736
+ return this._chainContractViewer;
5737
+ }
5738
+ get maxUncleWindowSize() {
5739
+ return this.params.maxUncleWindowSize;
5740
+ }
5741
+ static async paramsHandler(params) {
5742
+ return {
5743
+ ...await super.paramsHandler(params),
5744
+ protocol: params.protocol,
5745
+ state: params.state,
5746
+ maxUncleWindowSize: params.maxUncleWindowSize ?? 100
5747
+ };
5748
+ }
5749
+ async createHandler() {
5750
+ await super.createHandler();
5751
+ this._accountBalanceViewer = await this.locator.getInstance(AccountBalanceViewerMoniker3);
5752
+ this._chainContractViewer = await this.locator.getInstance(ChainContractViewerMoniker5);
5753
+ this._blockViewer = await this.locator.getInstance(BlockViewerMoniker5);
5754
+ }
5755
+ async qualifiedValidateTransaction(block, config) {
5756
+ const result = await this.qualifiedValidateTransactions([block], config);
5757
+ return [result[0][0], result[1]];
5758
+ }
5759
+ async qualifiedValidateTransactions(transactions, config) {
5760
+ const { value, state } = config ?? {
5761
+ shape: true,
5762
+ links: true,
5763
+ state: true,
5764
+ head: void 0
5765
+ };
5766
+ const transactionsWithMeta = await Promise.all(transactions.map((b) => Promise.all([PayloadBuilder23.addHashMeta(b[0]), PayloadBuilder23.addHashMeta(b[1])])));
5767
+ const head = isChainQualifiedHeadConfig6(config) ? assertEx45(
5768
+ (await this.blockViewer.blockByHash(config.head))?.[0],
5769
+ () => `Specified a head that is not in the chain [${config.head}]`
5770
+ ) : void 0;
5771
+ const headBlock = head ?? (await this.blockViewer.currentBlock())[0];
5772
+ const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
5773
+ const validateState = state ? this.doValidateState.bind(this) : void 0;
5774
+ const chainId = headBlock.chain;
5775
+ const qualification = { head: headBlock._hash, range: asXL1BlockRange12([0, headBlock.block], true) };
5776
+ const [protocolResults, stateResults] = await Promise.all([
5777
+ validateProtocol?.(transactionsWithMeta, chainId),
5778
+ validateState?.(transactionsWithMeta, chainId)
5779
+ ]);
5780
+ const blockResults = transactionsWithMeta.map((r, i) => {
5781
+ const errors = [];
5782
+ if (protocolResults && !isHydratedTransaction(protocolResults[i])) {
5783
+ errors.push(...protocolResults[i]);
5784
+ }
5785
+ if (stateResults && !isHydratedTransaction(stateResults[i])) {
5786
+ errors.push(...stateResults[i]);
5787
+ }
5788
+ return errors.length === 0 ? r : errors;
5789
+ });
5790
+ return [blockResults, qualification];
5791
+ }
5792
+ qualifiedValidateUncle(_transactions, _config) {
5793
+ throw new Error("Method not implemented.");
5794
+ }
5795
+ async validateTransaction(block, config) {
5796
+ return (await this.validateTransactions([block], config))[0];
5797
+ }
5798
+ async validateTransactions(transactions, config) {
5799
+ return (await this.qualifiedValidateTransactions(transactions, config))[0];
5800
+ }
5801
+ async doValidateProtocol(transactions, chainId) {
5802
+ return await Promise.all(transactions.map(async (tx) => {
5803
+ const errors = await this.params.protocol(
5804
+ { ...this.context, chainId },
5805
+ tx
5806
+ );
5807
+ return errors.length === 0 ? tx : errors;
5808
+ }));
5809
+ }
5810
+ async doValidateState(transactions, chainId) {
5811
+ return await Promise.all(transactions.map(async (tx) => {
5812
+ const errors = await this.params.state(
5813
+ {
5814
+ ...this.context,
5815
+ chainId,
5816
+ accountBalanceViewer: this._accountBalanceViewer,
5817
+ blockViewer: this.blockViewer
5818
+ },
5819
+ tx
5820
+ );
5821
+ return errors.length === 0 ? tx : errors;
5822
+ }));
5823
+ }
5824
+ };
5825
+ __publicField(SimpleTransactionValidationViewer, "defaultMoniker", TransactionValidationViewerMoniker2);
5826
+ __publicField(SimpleTransactionValidationViewer, "dependencies", [AccountBalanceViewerMoniker3, ChainContractViewerMoniker5, BlockViewerMoniker5]);
5827
+ __publicField(SimpleTransactionValidationViewer, "monikers", [TransactionValidationViewerMoniker2]);
5828
+ SimpleTransactionValidationViewer = __decorateClass([
5829
+ creatableProvider()
5830
+ ], SimpleTransactionValidationViewer);
5831
+
5715
5832
  // src/simple/TransactionViewer/SimpleTransactionViewer.ts
5716
5833
  import {
5717
- assertEx as assertEx45,
5834
+ assertEx as assertEx46,
5718
5835
  exists as exists10
5719
5836
  } from "@xylabs/sdk-js";
5720
5837
  import { BoundWitnessSchema } from "@xyo-network/sdk-js";
5721
5838
  import {
5722
5839
  asSignedHydratedTransactionWithHashMeta,
5723
5840
  asSignedTransactionBoundWitness,
5724
- BlockViewerMoniker as BlockViewerMoniker5,
5841
+ BlockViewerMoniker as BlockViewerMoniker6,
5725
5842
  isTransactionBoundWitnessWithHashMeta,
5726
5843
  TransactionViewerMoniker
5727
5844
  } from "@xyo-network/xl1-protocol-lib";
@@ -5733,7 +5850,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5733
5850
  }
5734
5851
  async byBlockHashAndIndex(blockHash, transactionIndex) {
5735
5852
  return await this.spanAsync("byBlockHashAndIndex", async () => {
5736
- assertEx45(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
5853
+ assertEx46(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
5737
5854
  try {
5738
5855
  const block = await this.blockViewer.blockByHash(blockHash);
5739
5856
  if (!block) return null;
@@ -5776,7 +5893,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5776
5893
  }
5777
5894
  async createHandler() {
5778
5895
  await super.createHandler();
5779
- this._blockViewer = await this.locator.getInstance(BlockViewerMoniker5);
5896
+ this._blockViewer = await this.locator.getInstance(BlockViewerMoniker6);
5780
5897
  }
5781
5898
  async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
5782
5899
  return await this.byBlockHashAndIndex(blockHash, transactionIndex);
@@ -5789,7 +5906,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5789
5906
  }
5790
5907
  };
5791
5908
  __publicField(SimpleTransactionViewer, "defaultMoniker", TransactionViewerMoniker);
5792
- __publicField(SimpleTransactionViewer, "dependencies", [BlockViewerMoniker5]);
5909
+ __publicField(SimpleTransactionViewer, "dependencies", [BlockViewerMoniker6]);
5793
5910
  __publicField(SimpleTransactionViewer, "monikers", [TransactionViewerMoniker]);
5794
5911
  SimpleTransactionViewer = __decorateClass([
5795
5912
  creatableProvider()
@@ -5797,13 +5914,13 @@ SimpleTransactionViewer = __decorateClass([
5797
5914
 
5798
5915
  // src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
5799
5916
  import {
5800
- assertEx as assertEx46,
5917
+ assertEx as assertEx47,
5801
5918
  exists as exists11,
5802
5919
  isNull as isNull2
5803
5920
  } from "@xylabs/sdk-js";
5804
5921
  import {
5805
5922
  asXL1BlockNumber as asXL1BlockNumber12,
5806
- BlockViewerMoniker as BlockViewerMoniker6,
5923
+ BlockViewerMoniker as BlockViewerMoniker7,
5807
5924
  WindowedBlockViewerMoniker as WindowedBlockViewerMoniker2
5808
5925
  } from "@xyo-network/xl1-protocol-lib";
5809
5926
  import { Mutex as Mutex2 } from "async-mutex";
@@ -5868,8 +5985,8 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5868
5985
  }
5869
5986
  async createHandler() {
5870
5987
  await super.createHandler();
5871
- this._blockViewer = assertEx46(
5872
- this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker6),
5988
+ this._blockViewer = assertEx47(
5989
+ this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
5873
5990
  () => "BlockViewer instance is required"
5874
5991
  );
5875
5992
  this._blockHashMap = new MemoryMap();
@@ -5877,13 +5994,13 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5877
5994
  this._transactionHashMap = new MemoryMap();
5878
5995
  }
5879
5996
  currentBlock() {
5880
- return assertEx46(this._chain.at(-1));
5997
+ return assertEx47(this._chain.at(-1));
5881
5998
  }
5882
5999
  currentBlockHash() {
5883
- return assertEx46(this._chain.at(-1)?.[0]._hash);
6000
+ return assertEx47(this._chain.at(-1)?.[0]._hash);
5884
6001
  }
5885
6002
  currentBlockNumber() {
5886
- return assertEx46(this._chain.at(-1)?.[0].block);
6003
+ return assertEx47(this._chain.at(-1)?.[0].block);
5887
6004
  }
5888
6005
  async payloadByHash(hash) {
5889
6006
  const payloads = await this.payloadsByHash([hash]);
@@ -5954,7 +6071,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5954
6071
  }
5955
6072
  };
5956
6073
  __publicField(SimpleWindowedBlockViewer, "defaultMoniker", WindowedBlockViewerMoniker2);
5957
- __publicField(SimpleWindowedBlockViewer, "dependencies", [BlockViewerMoniker6]);
6074
+ __publicField(SimpleWindowedBlockViewer, "dependencies", [BlockViewerMoniker7]);
5958
6075
  __publicField(SimpleWindowedBlockViewer, "monikers", [WindowedBlockViewerMoniker2]);
5959
6076
  SimpleWindowedBlockViewer = __decorateClass([
5960
6077
  creatableProvider()
@@ -6042,13 +6159,13 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
6042
6159
  };
6043
6160
 
6044
6161
  // src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
6045
- import { assertEx as assertEx47 } from "@xylabs/sdk-js";
6162
+ import { assertEx as assertEx48 } from "@xylabs/sdk-js";
6046
6163
  import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
6047
6164
  async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
6048
6165
  const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
6049
6166
  const hydratedBlock = await hydrateBlock(context, blockHash);
6050
6167
  const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
6051
- return assertEx47(timePayload.ethereum, () => "No ethereum timestamp found on block");
6168
+ return assertEx48(timePayload.ethereum, () => "No ethereum timestamp found on block");
6052
6169
  }
6053
6170
 
6054
6171
  // src/wallet/generateXyoBaseWalletFromPhrase.ts
@@ -6140,6 +6257,7 @@ export {
6140
6257
  SimpleStakeTotalsViewer,
6141
6258
  SimpleStakeViewer,
6142
6259
  SimpleTimeSyncViewer,
6260
+ SimpleTransactionValidationViewer,
6143
6261
  SimpleTransactionViewer,
6144
6262
  SimpleWindowedBlockViewer,
6145
6263
  SimpleXyoClient,