@xyo-network/xl1-rpc 1.2.3 → 1.2.5

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.
@@ -749,8 +749,8 @@ var JsonRpcXyoRunner = class {
749
749
 
750
750
  // src/provider/runner/MemoryXyoRunner.ts
751
751
  import { MemoryArchivist } from "@xyo-network/archivist-memory";
752
- import { flattenHydratedTransaction } from "@xyo-network/chain-protocol";
753
752
  import { PayloadBuilder } from "@xyo-network/payload-builder";
753
+ import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol";
754
754
  var MemoryXyoRunner = class {
755
755
  static {
756
756
  __name(this, "MemoryXyoRunner");
@@ -774,8 +774,8 @@ var MemoryXyoRunner = class {
774
774
  // src/provider/runner/NodeXyoRunner.ts
775
775
  import { assertEx as assertEx2 } from "@xylabs/assert";
776
776
  import { asArchivistInstance } from "@xyo-network/archivist-model";
777
- import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/chain-protocol";
778
777
  import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
778
+ import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/xl1-protocol";
779
779
  var NodeXyoRunner = class {
780
780
  static {
781
781
  __name(this, "NodeXyoRunner");
@@ -911,153 +911,6 @@ var JsonRpcXyoViewer = class {
911
911
  }
912
912
  };
913
913
 
914
- // src/provider/viewer/NodeXyoViewer.ts
915
- import { filterAs } from "@xylabs/array";
916
- import { assertEx as assertEx3 } from "@xylabs/assert";
917
- import { exists } from "@xylabs/exists";
918
- import { asAddress } from "@xylabs/hex";
919
- import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
920
- import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
921
- import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
922
- import { analyzeChain, BalanceAnalyzer, findMostRecentBlock, hydrateBlock, hydrateTransaction, isChainSummaryBalances } from "@xyo-network/chain-protocol";
923
- import { asDivinerInstance } from "@xyo-network/diviner-model";
924
- import { asOptionalBlockBoundWitnessWithStorageMeta, asOptionalTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-model";
925
- var WindowLimit = 1e3;
926
- var WindowLimitBigInt = BigInt(WindowLimit);
927
- var NodeXyoViewer = class {
928
- static {
929
- __name(this, "NodeXyoViewer");
930
- }
931
- // TODO: Make configurable with defaults
932
- finalizedArchivistPath = "XYOChain:Chain:Finalized";
933
- headValidationDivinerPath = "XYOChain:Chain:HeadValidationDiviner";
934
- node;
935
- _chainId;
936
- _finalizedArchivist;
937
- _headValidationDiviner;
938
- constructor(node) {
939
- this.node = node;
940
- }
941
- async accountBalance(address, blockNumber, full) {
942
- const head = await this.blockByNumber(blockNumber);
943
- if (!head) {
944
- throw new Error(`Error: Could not find block ${blockNumber}`);
945
- }
946
- const analysis = await analyzeChain(await this.getFinalizedArchivist(), [
947
- new BalanceAnalyzer()
948
- ], head, null, full ? -1n : WindowLimitBigInt);
949
- const balances = assertEx3(analysis.find(isChainSummaryBalances)?.balances, () => "Failed to sync balances");
950
- return balances[address] ? hexToBigInt2(balances[address]) : 0n;
951
- }
952
- async blockByHash(hash) {
953
- const finalizedArchivist = await this.getFinalizedArchivist();
954
- return await hydrateBlock(finalizedArchivist, hash);
955
- }
956
- async blockByNumber(blockNumber) {
957
- const finalizedArchivist = await this.getFinalizedArchivist();
958
- const result = await this.currentBlock();
959
- let currentBlock = result[0];
960
- if (currentBlock.block === blockNumber) return result;
961
- if (blockNumber > currentBlock.block) throw new Error(`Error: Block number ${blockNumber} is greater than current block number ${currentBlock.block}`);
962
- if (blockNumber < 0) throw new Error(`Error: Block number ${blockNumber} is less than 0`);
963
- if (blockNumber - currentBlock.block > WindowLimit) throw new Error(`Error: Block number ${blockNumber} is too far in the past`);
964
- do {
965
- const { previous } = currentBlock;
966
- if (previous === null) return null;
967
- const nextBlock = asOptionalBlockBoundWitnessWithStorageMeta((await finalizedArchivist.get([
968
- previous
969
- ]))[0]);
970
- if (!nextBlock) return null;
971
- currentBlock = nextBlock;
972
- } while (blockNumber != currentBlock.block);
973
- return currentBlock.block === blockNumber ? await hydrateBlock(finalizedArchivist, currentBlock._hash) : null;
974
- }
975
- async blocksByHash(hash, limit = 10) {
976
- assertEx3(limit > 0, () => "Error: limit must be greater than 0");
977
- assertEx3(limit <= 100, () => "Error: limit must be less than 100");
978
- const blocks = [];
979
- let current = await this.blockByHash(hash);
980
- while (current && blocks.length < limit) {
981
- blocks.push(current);
982
- const previousHash = current[0].previous;
983
- if (!previousHash) break;
984
- current = await this.blockByHash(previousHash);
985
- }
986
- return blocks;
987
- }
988
- async chainId() {
989
- if (this._chainId) return this._chainId;
990
- const headValidationDiviner = await this.getHeadValidationDiviner();
991
- this._chainId = assertEx3(asAddress(headValidationDiviner.params.chainIdentification?.id), () => "HeadValidationDiviner.params.chainIdentification.id is required and must be an Address");
992
- return await Promise.resolve(this._chainId);
993
- }
994
- async currentBlock() {
995
- const finalizedArchivist = await this.getFinalizedArchivist();
996
- return await hydrateBlock(finalizedArchivist, await this.currentBlockHash());
997
- }
998
- async currentBlockHash() {
999
- const finalizedArchivist = await this.getFinalizedArchivist();
1000
- const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
1001
- return block._hash;
1002
- }
1003
- async currentBlockNumber() {
1004
- const finalizedArchivist = await this.getFinalizedArchivist();
1005
- const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
1006
- return block.block;
1007
- }
1008
- async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
1009
- assertEx3(transactionIndex >= 0, () => "Error: transactionIndex must be greater than or equal to 0");
1010
- try {
1011
- const block = await this.blockByHash(blockHash);
1012
- if (!block) return null;
1013
- const blockBoundWitnessIndexes = block[0].payload_schemas.map((schema, index) => schema === BoundWitnessSchema2 ? index : void 0).filter(exists);
1014
- const blockBoundWitnessHashes = new Set(blockBoundWitnessIndexes.map((index) => block[0].payload_hashes[index]));
1015
- const blockBoundWitnesses = block[1].filter((payload) => blockBoundWitnessHashes.has(payload._hash) || blockBoundWitnessHashes.has(payload._dataHash));
1016
- const blockTransactionBoundWitnesses = filterAs(blockBoundWitnesses, asOptionalTransactionBoundWitnessWithStorageMeta);
1017
- const transaction = blockTransactionBoundWitnesses.at(transactionIndex);
1018
- if (!transaction) return null;
1019
- return await this.transactionByHash(transaction._hash);
1020
- } catch {
1021
- return null;
1022
- }
1023
- }
1024
- async transactionByBlockNumberAndIndex(blockNumber, transactionIndex = 0) {
1025
- try {
1026
- const block = await this.blockByNumber(blockNumber);
1027
- if (!block) return null;
1028
- return await this.transactionByBlockHashAndIndex(block[0]._hash, transactionIndex);
1029
- } catch {
1030
- return null;
1031
- }
1032
- }
1033
- async transactionByHash(transactionHash) {
1034
- try {
1035
- const finalizedArchivist = await this.getFinalizedArchivist();
1036
- return await hydrateTransaction(finalizedArchivist, transactionHash);
1037
- } catch {
1038
- return null;
1039
- }
1040
- }
1041
- getArchivist = /* @__PURE__ */ __name(async (identifier) => {
1042
- const diviner = await this.node.resolve(identifier);
1043
- return assertEx3(asArchivistInstance2(diviner), () => `Error: Could not resolve ${identifier} to an archivist instance`);
1044
- }, "getArchivist");
1045
- getDiviner = /* @__PURE__ */ __name(async (identifier) => {
1046
- const diviner = await this.node.resolve(identifier);
1047
- return assertEx3(asDivinerInstance(diviner), () => `Error: Could not resolve ${identifier} to a diviner instance`);
1048
- }, "getDiviner");
1049
- getFinalizedArchivist = /* @__PURE__ */ __name(async () => {
1050
- if (this._finalizedArchivist) return this._finalizedArchivist;
1051
- this._finalizedArchivist = await this.getArchivist(this.finalizedArchivistPath);
1052
- return this._finalizedArchivist;
1053
- }, "getFinalizedArchivist");
1054
- getHeadValidationDiviner = /* @__PURE__ */ __name(async () => {
1055
- if (this._headValidationDiviner) return this._headValidationDiviner;
1056
- this._headValidationDiviner = await this.getDiviner(this.headValidationDivinerPath);
1057
- return this._headValidationDiviner;
1058
- }, "getHeadValidationDiviner");
1059
- };
1060
-
1061
914
  // src/provider/wallet/JsonRpcXyoWallet.ts
1062
915
  var JsonRpcXyoWallet = class {
1063
916
  static {
@@ -1103,7 +956,7 @@ var JsonRpcXyoWallet = class {
1103
956
  };
1104
957
 
1105
958
  // src/provider/wallet/MemoryXyoWallet.ts
1106
- import { assertEx as assertEx4 } from "@xylabs/assert";
959
+ import { assertEx as assertEx3 } from "@xylabs/assert";
1107
960
  var MemoryXyoWallet = class {
1108
961
  static {
1109
962
  __name(this, "MemoryXyoWallet");
@@ -1124,7 +977,7 @@ var MemoryXyoWallet = class {
1124
977
  return this.chains();
1125
978
  }
1126
979
  chain() {
1127
- return assertEx4(this._chain, () => "Chain not set");
980
+ return assertEx3(this._chain, () => "Chain not set");
1128
981
  }
1129
982
  chains() {
1130
983
  return this._chains;
@@ -1233,7 +1086,6 @@ export {
1233
1086
  MemoryXyoSigner,
1234
1087
  MemoryXyoWallet,
1235
1088
  NodeXyoRunner,
1236
- NodeXyoViewer,
1237
1089
  XyoProviderRpcSchemas,
1238
1090
  XyoRunnerRpcSchemas,
1239
1091
  XyoSignerRpcSchemas,