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

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.
@@ -4681,7 +4681,10 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4681
4681
  remainingBlockMap.length === remainingBlocks.length,
4682
4682
  () => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`
4683
4683
  );
4684
- const validationResults = await this.blockValidationViewer.validateBlocks(remainingBlocks, { value: true, state: true });
4684
+ const validationResults = await Promise.all(remainingBlocks.map((remainingBlock) => this.blockValidationViewer.validateBlock(
4685
+ remainingBlock,
4686
+ { value: true, state: true }
4687
+ )));
4685
4688
  for (const [i, r] of validationResults.entries()) {
4686
4689
  const validated = isHydratedBlockWithHashMeta(r);
4687
4690
  if (!validated) {
@@ -4738,7 +4741,10 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4738
4741
  remainingTransactionMap.length === remainingTransactions.length,
4739
4742
  () => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`
4740
4743
  );
4741
- const validationResults = await this.transactionValidationViewer.validateTransactions(remainingTransactions, { value: true, state: true });
4744
+ const validationResults = await Promise.all(remainingTransactions.map((remainingTransaction) => this.transactionValidationViewer.validateTransaction(
4745
+ remainingTransaction,
4746
+ { value: true, state: true }
4747
+ )));
4742
4748
  for (const [i, r] of validationResults.entries()) {
4743
4749
  const validated = isHydratedTransactionWithHashMeta(r);
4744
4750
  if (!validated) {
@@ -5712,16 +5718,133 @@ SimpleTimeSyncViewer = __decorateClass([
5712
5718
  creatableProvider()
5713
5719
  ], SimpleTimeSyncViewer);
5714
5720
 
5721
+ // src/simple/transactionValidation/SimpleTransactionValidationViewer.ts
5722
+ import { assertEx as assertEx45 } from "@xylabs/sdk-js";
5723
+ import { PayloadBuilder as PayloadBuilder23 } from "@xyo-network/sdk-js";
5724
+ import {
5725
+ AccountBalanceViewerMoniker as AccountBalanceViewerMoniker3,
5726
+ asXL1BlockRange as asXL1BlockRange12,
5727
+ BlockViewerMoniker as BlockViewerMoniker5,
5728
+ ChainContractViewerMoniker as ChainContractViewerMoniker5,
5729
+ isChainQualifiedHeadConfig as isChainQualifiedHeadConfig6,
5730
+ isHydratedTransaction,
5731
+ TransactionValidationViewerMoniker as TransactionValidationViewerMoniker2
5732
+ } from "@xyo-network/xl1-protocol-lib";
5733
+ var SimpleTransactionValidationViewer = class extends AbstractCreatableProvider {
5734
+ moniker = SimpleTransactionValidationViewer.defaultMoniker;
5735
+ _accountBalanceViewer;
5736
+ _blockViewer;
5737
+ _chainContractViewer;
5738
+ get blockViewer() {
5739
+ return this._blockViewer;
5740
+ }
5741
+ get chainContractViewer() {
5742
+ return this._chainContractViewer;
5743
+ }
5744
+ get maxUncleWindowSize() {
5745
+ return this.params.maxUncleWindowSize;
5746
+ }
5747
+ static async paramsHandler(params) {
5748
+ return {
5749
+ ...await super.paramsHandler(params),
5750
+ protocol: params.protocol,
5751
+ state: params.state,
5752
+ maxUncleWindowSize: params.maxUncleWindowSize ?? 100
5753
+ };
5754
+ }
5755
+ async createHandler() {
5756
+ await super.createHandler();
5757
+ this._accountBalanceViewer = await this.locator.getInstance(AccountBalanceViewerMoniker3);
5758
+ this._chainContractViewer = await this.locator.getInstance(ChainContractViewerMoniker5);
5759
+ this._blockViewer = await this.locator.getInstance(BlockViewerMoniker5);
5760
+ }
5761
+ async qualifiedValidateTransaction(block, config) {
5762
+ const result = await this.qualifiedValidateTransactions([block], config);
5763
+ return [result[0][0], result[1]];
5764
+ }
5765
+ async qualifiedValidateTransactions(transactions, config) {
5766
+ const { value, state } = config ?? {
5767
+ shape: true,
5768
+ links: true,
5769
+ state: true,
5770
+ head: void 0
5771
+ };
5772
+ const transactionsWithMeta = await Promise.all(transactions.map((b) => Promise.all([PayloadBuilder23.addHashMeta(b[0]), PayloadBuilder23.addHashMeta(b[1])])));
5773
+ const head = isChainQualifiedHeadConfig6(config) ? assertEx45(
5774
+ (await this.blockViewer.blockByHash(config.head))?.[0],
5775
+ () => `Specified a head that is not in the chain [${config.head}]`
5776
+ ) : void 0;
5777
+ const headBlock = head ?? (await this.blockViewer.currentBlock())[0];
5778
+ const validateProtocol = value ? this.doValidateProtocol.bind(this) : void 0;
5779
+ const validateState = state ? this.doValidateState.bind(this) : void 0;
5780
+ const chainId = headBlock.chain;
5781
+ const qualification = { head: headBlock._hash, range: asXL1BlockRange12([0, headBlock.block], true) };
5782
+ const [protocolResults, stateResults] = await Promise.all([
5783
+ validateProtocol?.(transactionsWithMeta, chainId),
5784
+ validateState?.(transactionsWithMeta, chainId)
5785
+ ]);
5786
+ const blockResults = transactionsWithMeta.map((r, i) => {
5787
+ const errors = [];
5788
+ if (protocolResults && !isHydratedTransaction(protocolResults[i])) {
5789
+ errors.push(...protocolResults[i]);
5790
+ }
5791
+ if (stateResults && !isHydratedTransaction(stateResults[i])) {
5792
+ errors.push(...stateResults[i]);
5793
+ }
5794
+ return errors.length === 0 ? r : errors;
5795
+ });
5796
+ return [blockResults, qualification];
5797
+ }
5798
+ qualifiedValidateUncle(_transactions, _config) {
5799
+ throw new Error("Method not implemented.");
5800
+ }
5801
+ async validateTransaction(block, config) {
5802
+ return (await this.validateTransactions([block], config))[0];
5803
+ }
5804
+ async validateTransactions(transactions, config) {
5805
+ return (await this.qualifiedValidateTransactions(transactions, config))[0];
5806
+ }
5807
+ async doValidateProtocol(transactions, chainId) {
5808
+ return await Promise.all(transactions.map(async (tx) => {
5809
+ const errors = await this.params.protocol(
5810
+ { ...this.context, chainId },
5811
+ tx
5812
+ );
5813
+ return errors.length === 0 ? tx : errors;
5814
+ }));
5815
+ }
5816
+ async doValidateState(transactions, chainId) {
5817
+ return await Promise.all(transactions.map(async (tx) => {
5818
+ const errors = await this.params.state(
5819
+ {
5820
+ ...this.context,
5821
+ chainId,
5822
+ accountBalanceViewer: this._accountBalanceViewer,
5823
+ blockViewer: this.blockViewer
5824
+ },
5825
+ tx
5826
+ );
5827
+ return errors.length === 0 ? tx : errors;
5828
+ }));
5829
+ }
5830
+ };
5831
+ __publicField(SimpleTransactionValidationViewer, "defaultMoniker", TransactionValidationViewerMoniker2);
5832
+ __publicField(SimpleTransactionValidationViewer, "dependencies", [AccountBalanceViewerMoniker3, ChainContractViewerMoniker5, BlockViewerMoniker5]);
5833
+ __publicField(SimpleTransactionValidationViewer, "monikers", [TransactionValidationViewerMoniker2]);
5834
+ SimpleTransactionValidationViewer = __decorateClass([
5835
+ creatableProvider()
5836
+ ], SimpleTransactionValidationViewer);
5837
+
5715
5838
  // src/simple/TransactionViewer/SimpleTransactionViewer.ts
5716
5839
  import {
5717
- assertEx as assertEx45,
5840
+ assertEx as assertEx46,
5718
5841
  exists as exists10
5719
5842
  } from "@xylabs/sdk-js";
5720
5843
  import { BoundWitnessSchema } from "@xyo-network/sdk-js";
5721
5844
  import {
5722
5845
  asSignedHydratedTransactionWithHashMeta,
5723
5846
  asSignedTransactionBoundWitness,
5724
- BlockViewerMoniker as BlockViewerMoniker5,
5847
+ BlockViewerMoniker as BlockViewerMoniker6,
5725
5848
  isTransactionBoundWitnessWithHashMeta,
5726
5849
  TransactionViewerMoniker
5727
5850
  } from "@xyo-network/xl1-protocol-lib";
@@ -5733,7 +5856,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5733
5856
  }
5734
5857
  async byBlockHashAndIndex(blockHash, transactionIndex) {
5735
5858
  return await this.spanAsync("byBlockHashAndIndex", async () => {
5736
- assertEx45(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
5859
+ assertEx46(transactionIndex >= 0, () => "transactionIndex must be greater than or equal to 0");
5737
5860
  try {
5738
5861
  const block = await this.blockViewer.blockByHash(blockHash);
5739
5862
  if (!block) return null;
@@ -5776,7 +5899,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5776
5899
  }
5777
5900
  async createHandler() {
5778
5901
  await super.createHandler();
5779
- this._blockViewer = await this.locator.getInstance(BlockViewerMoniker5);
5902
+ this._blockViewer = await this.locator.getInstance(BlockViewerMoniker6);
5780
5903
  }
5781
5904
  async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
5782
5905
  return await this.byBlockHashAndIndex(blockHash, transactionIndex);
@@ -5789,7 +5912,7 @@ var SimpleTransactionViewer = class extends AbstractCreatableProvider {
5789
5912
  }
5790
5913
  };
5791
5914
  __publicField(SimpleTransactionViewer, "defaultMoniker", TransactionViewerMoniker);
5792
- __publicField(SimpleTransactionViewer, "dependencies", [BlockViewerMoniker5]);
5915
+ __publicField(SimpleTransactionViewer, "dependencies", [BlockViewerMoniker6]);
5793
5916
  __publicField(SimpleTransactionViewer, "monikers", [TransactionViewerMoniker]);
5794
5917
  SimpleTransactionViewer = __decorateClass([
5795
5918
  creatableProvider()
@@ -5797,13 +5920,13 @@ SimpleTransactionViewer = __decorateClass([
5797
5920
 
5798
5921
  // src/simple/windowedBlock/SimpleWindowedBlockViewer.ts
5799
5922
  import {
5800
- assertEx as assertEx46,
5923
+ assertEx as assertEx47,
5801
5924
  exists as exists11,
5802
5925
  isNull as isNull2
5803
5926
  } from "@xylabs/sdk-js";
5804
5927
  import {
5805
5928
  asXL1BlockNumber as asXL1BlockNumber12,
5806
- BlockViewerMoniker as BlockViewerMoniker6,
5929
+ BlockViewerMoniker as BlockViewerMoniker7,
5807
5930
  WindowedBlockViewerMoniker as WindowedBlockViewerMoniker2
5808
5931
  } from "@xyo-network/xl1-protocol-lib";
5809
5932
  import { Mutex as Mutex2 } from "async-mutex";
@@ -5868,8 +5991,8 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5868
5991
  }
5869
5992
  async createHandler() {
5870
5993
  await super.createHandler();
5871
- this._blockViewer = assertEx46(
5872
- this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker6),
5994
+ this._blockViewer = assertEx47(
5995
+ this.params.blockViewer ?? await this.locator.getInstance(BlockViewerMoniker7),
5873
5996
  () => "BlockViewer instance is required"
5874
5997
  );
5875
5998
  this._blockHashMap = new MemoryMap();
@@ -5877,13 +6000,13 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5877
6000
  this._transactionHashMap = new MemoryMap();
5878
6001
  }
5879
6002
  currentBlock() {
5880
- return assertEx46(this._chain.at(-1));
6003
+ return assertEx47(this._chain.at(-1));
5881
6004
  }
5882
6005
  currentBlockHash() {
5883
- return assertEx46(this._chain.at(-1)?.[0]._hash);
6006
+ return assertEx47(this._chain.at(-1)?.[0]._hash);
5884
6007
  }
5885
6008
  currentBlockNumber() {
5886
- return assertEx46(this._chain.at(-1)?.[0].block);
6009
+ return assertEx47(this._chain.at(-1)?.[0].block);
5887
6010
  }
5888
6011
  async payloadByHash(hash) {
5889
6012
  const payloads = await this.payloadsByHash([hash]);
@@ -5954,7 +6077,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
5954
6077
  }
5955
6078
  };
5956
6079
  __publicField(SimpleWindowedBlockViewer, "defaultMoniker", WindowedBlockViewerMoniker2);
5957
- __publicField(SimpleWindowedBlockViewer, "dependencies", [BlockViewerMoniker6]);
6080
+ __publicField(SimpleWindowedBlockViewer, "dependencies", [BlockViewerMoniker7]);
5958
6081
  __publicField(SimpleWindowedBlockViewer, "monikers", [WindowedBlockViewerMoniker2]);
5959
6082
  SimpleWindowedBlockViewer = __decorateClass([
5960
6083
  creatableProvider()
@@ -6042,13 +6165,13 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
6042
6165
  };
6043
6166
 
6044
6167
  // src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
6045
- import { assertEx as assertEx47 } from "@xylabs/sdk-js";
6168
+ import { assertEx as assertEx48 } from "@xylabs/sdk-js";
6046
6169
  import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
6047
6170
  async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
6048
6171
  const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
6049
6172
  const hydratedBlock = await hydrateBlock(context, blockHash);
6050
6173
  const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
6051
- return assertEx47(timePayload.ethereum, () => "No ethereum timestamp found on block");
6174
+ return assertEx48(timePayload.ethereum, () => "No ethereum timestamp found on block");
6052
6175
  }
6053
6176
 
6054
6177
  // src/wallet/generateXyoBaseWalletFromPhrase.ts
@@ -6140,6 +6263,7 @@ export {
6140
6263
  SimpleStakeTotalsViewer,
6141
6264
  SimpleStakeViewer,
6142
6265
  SimpleTimeSyncViewer,
6266
+ SimpleTransactionValidationViewer,
6143
6267
  SimpleTransactionViewer,
6144
6268
  SimpleWindowedBlockViewer,
6145
6269
  SimpleXyoClient,