@xyo-network/chain-services 1.8.3 → 1.8.4

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.
@@ -743,11 +743,188 @@ XyoValidator = _ts_decorate7([
743
743
  creatable7()
744
744
  ], XyoValidator);
745
745
 
746
- // src/Election/BaseElectionService.ts
746
+ // src/DataLake/AbstractXyoDataLake.ts
747
+ import { ObjectHasher } from "@xyo-network/hash";
748
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
749
+ import { isAnyPayload } from "@xyo-network/payload-model";
750
+ import { isHashPayload } from "@xyo-network/xl1-protocol";
751
+ var AbstractXyoDataLake = class {
752
+ static {
753
+ __name(this, "AbstractXyoDataLake");
754
+ }
755
+ async fetch(hashes, maxDepth = 10) {
756
+ const results = await this.get(hashes);
757
+ if (maxDepth > 0) {
758
+ const hashPayloads = results.filter(isHashPayload);
759
+ const otherPayloads = results.filter((item) => !isHashPayload(item));
760
+ const found = await this.fetch(hashPayloads.map((item) => item.hash), maxDepth - 1);
761
+ const foundHashes = await Promise.all(found.map(async (item) => isAnyPayload(item) ? await PayloadBuilder4.hash(item) : ObjectHasher.hashBytes(item)));
762
+ const notFound = hashPayloads.filter((item) => !foundHashes.includes(item.hash));
763
+ return [
764
+ ...otherPayloads,
765
+ ...found,
766
+ ...notFound
767
+ ];
768
+ }
769
+ return results;
770
+ }
771
+ async trace(hash) {
772
+ const [result] = await this.get([
773
+ hash
774
+ ]);
775
+ if (isHashPayload(result)) {
776
+ const [payload, route] = await this.trace(result.hash);
777
+ return [
778
+ payload,
779
+ [
780
+ result,
781
+ ...route
782
+ ]
783
+ ];
784
+ }
785
+ return [
786
+ result,
787
+ []
788
+ ];
789
+ }
790
+ };
791
+
792
+ // src/DataLake/ArchivistXyoDataLake.ts
747
793
  import { assertEx as assertEx8 } from "@xylabs/assert";
794
+ import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
795
+ var ArchivistXyoDataLake = class extends AbstractXyoDataLake {
796
+ static {
797
+ __name(this, "ArchivistXyoDataLake");
798
+ }
799
+ _archivist;
800
+ constructor(archivist) {
801
+ super();
802
+ this._archivist = archivist;
803
+ }
804
+ async add(items) {
805
+ const payloads = items.filter(isAnyPayload2);
806
+ assertEx8(payloads.length === items.length, () => "Some items are not payloads");
807
+ return await this._archivist.insert(payloads);
808
+ }
809
+ async get(hashes) {
810
+ return await this._archivist.get(hashes);
811
+ }
812
+ };
813
+
814
+ // src/DataLake/HttpXyoDataLake.ts
815
+ import { assertEx as assertEx9 } from "@xylabs/assert";
816
+ import { AxiosJson } from "@xylabs/axios";
817
+ import { exists as exists3 } from "@xylabs/exists";
818
+ import { isArrayBuffer, isDefined as isDefined2 } from "@xylabs/typeof";
819
+ import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
820
+ import { isHashPayload as isHashPayload2 } from "@xyo-network/xl1-protocol";
821
+ import { Axios } from "axios";
822
+ var HttpXyoDataLake = class extends AbstractXyoDataLake {
823
+ static {
824
+ __name(this, "HttpXyoDataLake");
825
+ }
826
+ _axiosGet;
827
+ _axiosInsertBlob;
828
+ _axiosInsertJson;
829
+ _endpoint;
830
+ constructor(endpoint) {
831
+ super();
832
+ this._endpoint = endpoint;
833
+ this._axiosInsertJson = new AxiosJson({
834
+ baseURL: endpoint
835
+ });
836
+ this._axiosInsertBlob = new Axios({
837
+ baseURL: endpoint,
838
+ headers: {
839
+ "Content-Type": "application/octet-stream",
840
+ "Accept": "application/octet-stream"
841
+ }
842
+ });
843
+ this._axiosGet = new Axios({
844
+ baseURL: endpoint,
845
+ headers: {
846
+ "Content-Type": "application/json",
847
+ "Accept": "application/octet-stream, application/json"
848
+ }
849
+ });
850
+ }
851
+ get endpoint() {
852
+ return this._endpoint;
853
+ }
854
+ async add(items) {
855
+ const results = [];
856
+ for (const item of items) {
857
+ if (isAnyPayload3(item)) {
858
+ const result = await this.addPayload(item);
859
+ if (isAnyPayload3(result)) {
860
+ results.push(result);
861
+ } else if (isDefined2(result)) {
862
+ assertEx9(false, () => "Expected result to be a Payload");
863
+ }
864
+ } else if (isArrayBuffer(item)) {
865
+ const result = await this.addArrayBuffer(item);
866
+ if (isAnyPayload3(result)) {
867
+ results.push(result);
868
+ } else if (isDefined2(result)) {
869
+ assertEx9(false, () => "Expected result to be a Payload");
870
+ }
871
+ }
872
+ }
873
+ return results;
874
+ }
875
+ async get(hashes) {
876
+ return (await Promise.all(hashes.map(async (hash) => {
877
+ return await this.getOne(hash);
878
+ }))).filter(exists3);
879
+ }
880
+ async addArrayBuffer(item) {
881
+ const result = await this._axiosInsertBlob.post("/insert", item);
882
+ if (result.status < 200 || result.status >= 300) {
883
+ throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
884
+ }
885
+ if (!isArrayBuffer(result.data)) {
886
+ throw new Error("Invalid response from server (expected a ArrayBuffer)");
887
+ }
888
+ return result.data;
889
+ }
890
+ async addPayload(item) {
891
+ const result = await this._axiosInsertJson.post("/insert", item);
892
+ if (result.status < 200 || result.status >= 300) {
893
+ throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
894
+ }
895
+ if (!isAnyPayload3(result.data)) {
896
+ throw new Error("Invalid response from server (expected a Payload)");
897
+ }
898
+ return result.data;
899
+ }
900
+ async fetchOne(hash, maxDepth = Number.MAX_SAFE_INTEGER) {
901
+ if (maxDepth <= 0) {
902
+ return void 0;
903
+ }
904
+ const result = await this.getOne(hash);
905
+ if (isHashPayload2(result)) {
906
+ return await this.fetchOne(result.hash, maxDepth - 1);
907
+ }
908
+ return result;
909
+ }
910
+ getOne(hash) {
911
+ return this._axiosGet.get(`/get/${hash}`).then((response) => {
912
+ if (response.status < 200 || response.status >= 300) {
913
+ throw new Error(`Failed to get item [${response.status}]: ${response.statusText}`);
914
+ }
915
+ if (!isAnyPayload3(response.data)) {
916
+ throw new Error("Invalid response from server (expected a Payload)");
917
+ }
918
+ return response.data;
919
+ });
920
+ }
921
+ };
922
+
923
+ // src/Election/BaseElectionService.ts
924
+ import { assertEx as assertEx10 } from "@xylabs/assert";
748
925
  import { creatable as creatable8 } from "@xylabs/creatable";
749
926
  import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
750
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
927
+ import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
751
928
  function _ts_decorate8(decorators, target, key, desc) {
752
929
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
753
930
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -760,19 +937,19 @@ var BaseElectionService = class extends BaseService {
760
937
  __name(this, "BaseElectionService");
761
938
  }
762
939
  get chainIterator() {
763
- return assertEx8(this.params.chainIterator, () => "No chain iterator");
940
+ return assertEx10(this.params.chainIterator, () => "No chain iterator");
764
941
  }
765
942
  get chainStakeViewer() {
766
- return assertEx8(this.params.chainStakeViewer, () => "No chain stake viewer");
943
+ return assertEx10(this.params.chainStakeViewer, () => "No chain stake viewer");
767
944
  }
768
945
  get stakeIntentService() {
769
- return assertEx8(this.params.stakeIntentService, () => "No staked intent service");
946
+ return assertEx10(this.params.stakeIntentService, () => "No staked intent service");
770
947
  }
771
948
  async getCreatorCommitteeForNextBlock(current) {
772
949
  return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
773
950
  const nextBlock = current.block + 1;
774
951
  const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
775
- const previousBlockHash = await PayloadBuilder4.hash(current);
952
+ const previousBlockHash = await PayloadBuilder5.hash(current);
776
953
  return this.generateCreatorCommittee(candidates, previousBlockHash);
777
954
  });
778
955
  }
@@ -790,11 +967,11 @@ BaseElectionService = _ts_decorate8([
790
967
  // src/PendingTransactions/BasePendingTransactions.ts
791
968
  import { ValueType } from "@opentelemetry/api";
792
969
  import { filterAs, filterAsync } from "@xylabs/array";
793
- import { assertEx as assertEx9 } from "@xylabs/assert";
970
+ import { assertEx as assertEx11 } from "@xylabs/assert";
794
971
  import { creatable as creatable9 } from "@xylabs/creatable";
795
- import { exists as exists3 } from "@xylabs/exists";
972
+ import { exists as exists4 } from "@xylabs/exists";
796
973
  import { forget } from "@xylabs/forget";
797
- import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
974
+ import { isDefined as isDefined3, isUndefined } from "@xylabs/typeof";
798
975
  import { MemoryArchivist } from "@xyo-network/archivist-memory";
799
976
  import { findMostRecentBlock } from "@xyo-network/chain-protocol";
800
977
  import { asBlockBoundWitnessWithHashStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
@@ -802,10 +979,10 @@ import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-networ
802
979
  import { Mutex as Mutex2 } from "async-mutex";
803
980
 
804
981
  // src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
805
- import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
982
+ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
806
983
  import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
807
984
  var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
808
- const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
985
+ const withStorageMeta = await PayloadBuilder6.addStorageMeta(payload.payloads);
809
986
  const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
810
987
  if (tx) {
811
988
  return [
@@ -816,7 +993,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
816
993
  }, "bundledPayloadToHydratedTransaction");
817
994
 
818
995
  // src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
819
- import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
996
+ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
820
997
  import { PayloadBundleSchema } from "@xyo-network/payload-model";
821
998
  import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
822
999
  var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
@@ -824,8 +1001,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
824
1001
  return bundle(root, transaction);
825
1002
  }, "hydratedTransactionToPayloadBundle");
826
1003
  var bundle = /* @__PURE__ */ __name((root, transaction) => {
827
- const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
828
- return new PayloadBuilder6({
1004
+ const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder7.omitStorageMeta(p));
1005
+ return new PayloadBuilder7({
829
1006
  schema: PayloadBundleSchema
830
1007
  }).fields({
831
1008
  payloads,
@@ -885,23 +1062,23 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
885
1062
  */
886
1063
  _updateCuratedPendingTransactionsArchivistMutex = new Mutex2();
887
1064
  get chainArchivist() {
888
- return assertEx9(this.params.chainArchivist, () => "No completed blocks with data archivist");
1065
+ return assertEx11(this.params.chainArchivist, () => "No completed blocks with data archivist");
889
1066
  }
890
1067
  get chainId() {
891
- return assertEx9(this.params.chainId, () => "No chain id");
1068
+ return assertEx11(this.params.chainId, () => "No chain id");
892
1069
  }
893
1070
  get pendingBundledTransactionsArchivist() {
894
- return assertEx9(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
1071
+ return assertEx11(this.params.pendingBundledTransactionsArchivist, () => "No pending bundled transactions archivist");
895
1072
  }
896
1073
  get pendingBundledTransactionsLocalArchivist() {
897
- return assertEx9(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
1074
+ return assertEx11(this._curatedPendingBundledTransactionsArchivist, () => "No pending bundled transactions curated archivist");
898
1075
  }
899
1076
  get pendingTransactionsCount() {
900
1077
  forget(this.countPendingTransactions());
901
1078
  return this._pendingTransactionsCount;
902
1079
  }
903
1080
  get rejectedTransactionsArchivist() {
904
- return assertEx9(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
1081
+ return assertEx11(this.params.rejectedTransactionsArchivist, () => "No rejected transactions archivist");
905
1082
  }
906
1083
  async createHandler() {
907
1084
  await super.createHandler();
@@ -947,7 +1124,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
947
1124
  if (pendingBundledTransactions.length === 0) break;
948
1125
  cursor = pendingBundledTransactions.at(-1)?._sequence;
949
1126
  const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
950
- const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists3);
1127
+ const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists4);
951
1128
  const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1));
952
1129
  foundPendingTransactions.push(...activeTransactions);
953
1130
  }
@@ -964,7 +1141,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
964
1141
  async cleanupWorker() {
965
1142
  return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
966
1143
  const lastHead = await findMostRecentBlock(this.chainArchivist);
967
- if (isDefined2(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
1144
+ if (isDefined3(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash);
968
1145
  }, _BasePendingTransactionsService.MutexPriority.PurgeTransactions);
969
1146
  }
970
1147
  async countPendingTransactions() {
@@ -988,7 +1165,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
988
1165
  const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
989
1166
  const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
990
1167
  return await bundledPayloadToHydratedTransaction(tx);
991
- }))).filter(exists3);
1168
+ }))).filter(exists4);
992
1169
  const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
993
1170
  const errors = await validateTransaction(tx, this.chainId, [
994
1171
  TransactionJsonSchemaValidator
@@ -1024,7 +1201,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
1024
1201
  let [lastHead] = filterAs(await this.chainArchivist.get([
1025
1202
  head
1026
1203
  ]), asBlockBoundWitnessWithHashStorageMeta);
1027
- while (isDefined2(lastHead)) {
1204
+ while (isDefined3(lastHead)) {
1028
1205
  const pendingBundledTransactions = await this.pendingBundledTransactionsLocalArchivist.next({
1029
1206
  limit: 100,
1030
1207
  order: "asc",
@@ -1035,14 +1212,14 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
1035
1212
  }
1036
1213
  cursor = pendingBundledTransactions.at(-1)?._sequence;
1037
1214
  const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
1038
- foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists3));
1215
+ foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists4));
1039
1216
  const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
1040
- const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists3);
1217
+ const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists4);
1041
1218
  const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1));
1042
1219
  const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
1043
1220
  // Find the corresponding payload bundle hash for the expired transaction
1044
1221
  pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
1045
- )).filter(exists3);
1222
+ )).filter(exists4);
1046
1223
  foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
1047
1224
  }
1048
1225
  const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
@@ -1066,7 +1243,7 @@ var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf
1066
1243
 
1067
1244
  // src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
1068
1245
  import { filterAs as filterAs2 } from "@xylabs/array";
1069
- import { exists as exists4 } from "@xylabs/exists";
1246
+ import { exists as exists5 } from "@xylabs/exists";
1070
1247
  import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
1071
1248
  import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
1072
1249
  import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
@@ -1077,7 +1254,7 @@ var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archi
1077
1254
  const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
1078
1255
  const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
1079
1256
  return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
1080
- const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists4);
1257
+ const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists5);
1081
1258
  const payloads = await archivist.get(stakeIntentHashes);
1082
1259
  const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
1083
1260
  return stakeIntents;
@@ -1093,13 +1270,13 @@ var mapBoundWitnessToStakeIntentHashes = /* @__PURE__ */ __name((bw) => {
1093
1270
 
1094
1271
  // src/StakeIntent/XyoStakeIntentService.ts
1095
1272
  import { filterAs as filterAs3 } from "@xylabs/array";
1096
- import { assertEx as assertEx10 } from "@xylabs/assert";
1273
+ import { assertEx as assertEx12 } from "@xylabs/assert";
1097
1274
  import { creatable as creatable10 } from "@xylabs/creatable";
1098
1275
  import { asAddress } from "@xylabs/hex";
1099
1276
  import { isUndefined as isUndefined2 } from "@xylabs/typeof";
1100
1277
  import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
1101
1278
  import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
1102
- import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
1279
+ import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
1103
1280
  import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
1104
1281
  import { Mutex as Mutex3 } from "async-mutex";
1105
1282
  import { LRUCache as LRUCache3 } from "lru-cache";
@@ -1132,16 +1309,16 @@ var XyoStakeIntentService = class extends BaseService {
1132
1309
  });
1133
1310
  _updateMutex = new Mutex3();
1134
1311
  get chainArchivist() {
1135
- return assertEx10(this.params.chainArchivist, () => "chainArchivist not set");
1312
+ return assertEx12(this.params.chainArchivist, () => "chainArchivist not set");
1136
1313
  }
1137
1314
  get chainIterator() {
1138
- return assertEx10(this.params.chainIterator, () => "chainIterator not set");
1315
+ return assertEx12(this.params.chainIterator, () => "chainIterator not set");
1139
1316
  }
1140
1317
  get chainStakeViewer() {
1141
- return assertEx10(this.params.chainStakeViewer, () => "chainStakeViewer not set");
1318
+ return assertEx12(this.params.chainStakeViewer, () => "chainStakeViewer not set");
1142
1319
  }
1143
1320
  get stakeIntentStateArchivist() {
1144
- return assertEx10(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
1321
+ return assertEx12(this.params.stakeIntentStateArchivist, () => "stakeIntentStateArchivist not set");
1145
1322
  }
1146
1323
  async createHandler() {
1147
1324
  this.chainIterator.on("headUpdated", async () => {
@@ -1149,18 +1326,18 @@ var XyoStakeIntentService = class extends BaseService {
1149
1326
  });
1150
1327
  const head = await this.chainIterator.head();
1151
1328
  if (isUndefined2(head)) return;
1152
- const headHash = await PayloadBuilder7.hash(head);
1329
+ const headHash = await PayloadBuilder8.hash(head);
1153
1330
  await this.recoverState(headHash);
1154
1331
  }
1155
1332
  async getDeclaredCandidateRanges(address, intent) {
1156
1333
  await Promise.resolve();
1157
- assertEx10(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1334
+ assertEx12(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1158
1335
  const results = this._producers.get(address);
1159
1336
  return results ?? [];
1160
1337
  }
1161
1338
  async getDeclaredCandidatesForBlock(block, intent) {
1162
1339
  return await this.spanAsync("getDeclaredCandidatesForBlock", async () => {
1163
- assertEx10(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1340
+ assertEx12(intent === "producer", () => `Error: Support not yet added for intent ${intent}`);
1164
1341
  const results = this._producers.findAllContaining(block);
1165
1342
  const candidates = [
1166
1343
  ...results
@@ -1214,7 +1391,7 @@ var XyoStakeIntentService = class extends BaseService {
1214
1391
  }
1215
1392
  async persistState(current) {
1216
1393
  const state = this._producers.serialize();
1217
- const payload = new PayloadBuilder7({
1394
+ const payload = new PayloadBuilder8({
1218
1395
  schema: ChainIndexingServiceStateSchema
1219
1396
  }).fields({
1220
1397
  endBlockHash: current,
@@ -1225,7 +1402,7 @@ var XyoStakeIntentService = class extends BaseService {
1225
1402
  ]);
1226
1403
  }
1227
1404
  async recoverState(current) {
1228
- const currentBlock = assertEx10(asBlockBoundWitness3((await this.chainArchivist.get([
1405
+ const currentBlock = assertEx12(asBlockBoundWitness3((await this.chainArchivist.get([
1229
1406
  current
1230
1407
  ]))?.[0]), () => `Block ${current} not found`);
1231
1408
  const currentBlockNum = currentBlock.block;
@@ -1266,7 +1443,7 @@ var XyoStakeIntentService = class extends BaseService {
1266
1443
  return await this.spanAsync("updateIndex", async () => {
1267
1444
  const currentHead = await this.chainIterator.head();
1268
1445
  if (isUndefined2(currentHead)) return;
1269
- const currentHeadHash = await PayloadBuilder7.hash(currentHead);
1446
+ const currentHeadHash = await PayloadBuilder8.hash(currentHead);
1270
1447
  const result = await analyzeChain(this.chainArchivist, [
1271
1448
  new ChainStakeIntentAnalyzer("producer")
1272
1449
  ], currentHeadHash, this._lastIndexedBlockHash);
@@ -1291,137 +1468,9 @@ var XyoStakeIntentService = class extends BaseService {
1291
1468
  XyoStakeIntentService = _ts_decorate10([
1292
1469
  creatable10()
1293
1470
  ], XyoStakeIntentService);
1294
-
1295
- // src/XyoDataLake.ts
1296
- import { assertEx as assertEx11 } from "@xylabs/assert";
1297
- import { AxiosJson } from "@xylabs/axios";
1298
- import { exists as exists5 } from "@xylabs/exists";
1299
- import { isArrayBuffer, isDefined as isDefined3 } from "@xylabs/typeof";
1300
- import { isAnyPayload } from "@xyo-network/payload-model";
1301
- import { isHashPayload } from "@xyo-network/xl1-protocol";
1302
- import { Axios } from "axios";
1303
- var XyoDataLake = class {
1304
- static {
1305
- __name(this, "XyoDataLake");
1306
- }
1307
- _axiosGet;
1308
- _axiosInsertBlob;
1309
- _axiosInsertJson;
1310
- _endpoint;
1311
- constructor(endpoint) {
1312
- this._endpoint = endpoint;
1313
- this._axiosInsertJson = new AxiosJson({
1314
- baseURL: endpoint
1315
- });
1316
- this._axiosInsertBlob = new Axios({
1317
- baseURL: endpoint,
1318
- headers: {
1319
- "Content-Type": "application/octet-stream",
1320
- "Accept": "application/octet-stream"
1321
- }
1322
- });
1323
- this._axiosGet = new Axios({
1324
- baseURL: endpoint,
1325
- headers: {
1326
- "Content-Type": "application/json",
1327
- "Accept": "application/octet-stream, application/json"
1328
- }
1329
- });
1330
- }
1331
- get endpoint() {
1332
- return this._endpoint;
1333
- }
1334
- async add(items) {
1335
- const results = [];
1336
- for (const item of items) {
1337
- if (isAnyPayload(item)) {
1338
- const result = await this.addPayload(item);
1339
- if (isAnyPayload(result)) {
1340
- results.push(result);
1341
- } else if (isDefined3(result)) {
1342
- assertEx11(false, () => "Expected result to be a Payload");
1343
- }
1344
- } else if (isArrayBuffer(item)) {
1345
- const result = await this.addArrayBuffer(item);
1346
- if (isAnyPayload(result)) {
1347
- results.push(result);
1348
- } else if (isDefined3(result)) {
1349
- assertEx11(false, () => "Expected result to be a Payload");
1350
- }
1351
- }
1352
- }
1353
- return results;
1354
- }
1355
- async fetch(hashes, maxDepth) {
1356
- return (await Promise.all(hashes.map(async (hash) => {
1357
- return await this.fetchOne(hash, maxDepth);
1358
- }))).filter(exists5);
1359
- }
1360
- async get(hashes) {
1361
- return (await Promise.all(hashes.map(async (hash) => {
1362
- return await this.getOne(hash);
1363
- }))).filter(exists5);
1364
- }
1365
- async trace(hash) {
1366
- const result = await this.getOne(hash);
1367
- if (isHashPayload(result)) {
1368
- const [payload, route] = await this.trace(result.hash);
1369
- return [
1370
- payload,
1371
- [
1372
- result,
1373
- ...route
1374
- ]
1375
- ];
1376
- }
1377
- return [
1378
- result,
1379
- []
1380
- ];
1381
- }
1382
- async addArrayBuffer(item) {
1383
- const result = await this._axiosInsertBlob.post("/insert", item);
1384
- if (result.status < 200 || result.status >= 300) {
1385
- throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
1386
- }
1387
- if (!isArrayBuffer(result.data)) {
1388
- throw new Error("Invalid response from server (expected a ArrayBuffer)");
1389
- }
1390
- return result.data;
1391
- }
1392
- async addPayload(item) {
1393
- const result = await this._axiosInsertJson.post("/insert", item);
1394
- if (result.status < 200 || result.status >= 300) {
1395
- throw new Error(`Failed to add items [${result.status}]: ${result.statusText}`);
1396
- }
1397
- if (!isAnyPayload(result.data)) {
1398
- throw new Error("Invalid response from server (expected a Payload)");
1399
- }
1400
- return result.data;
1401
- }
1402
- async fetchOne(hash, maxDepth = Number.MAX_SAFE_INTEGER) {
1403
- if (maxDepth <= 0) {
1404
- return void 0;
1405
- }
1406
- const result = await this.getOne(hash);
1407
- if (isHashPayload(result)) {
1408
- return await this.fetchOne(result.hash, maxDepth - 1);
1409
- }
1410
- return result;
1411
- }
1412
- getOne(hash) {
1413
- return this._axiosGet.get(`/get/${hash}`).then((response) => {
1414
- if (response.status < 200 || response.status >= 300) {
1415
- throw new Error(`Failed to get item [${response.status}]: ${response.statusText}`);
1416
- }
1417
- if (!isAnyPayload(response.data)) {
1418
- throw new Error("Invalid response from server (expected a Payload)");
1419
- }
1420
- return response.data;
1421
- });
1422
- }
1423
- };
1424
1471
  export {
1472
+ AbstractXyoDataLake,
1473
+ ArchivistXyoDataLake,
1425
1474
  BaseAccountBalanceService,
1426
1475
  BaseAccountableService,
1427
1476
  BaseBlockProducerService,
@@ -1433,11 +1482,11 @@ export {
1433
1482
  DEFAULT_BLOCK_SIZE,
1434
1483
  EvmBlockRewardService,
1435
1484
  EvmChainService,
1485
+ HttpXyoDataLake,
1436
1486
  MemoryBlockRewardService,
1437
1487
  MemoryChainService,
1438
1488
  XYO_PRODUCER_REDECLARATION_DURATION,
1439
1489
  XYO_PRODUCER_REDECLARATION_WINDOW,
1440
- XyoDataLake,
1441
1490
  XyoStakeIntentService,
1442
1491
  XyoValidator,
1443
1492
  accountBalanceServiceFromArchivist,