@subql/node-stellar 3.10.1 → 3.10.2-1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/configure/SubqueryProject.d.ts +7 -8
  4. package/dist/configure/SubqueryProject.js.map +1 -1
  5. package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +5 -6
  6. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +5 -8
  7. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
  8. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +5 -5
  9. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +4 -5
  10. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
  11. package/dist/indexer/ds-processor.service.d.ts +1 -5
  12. package/dist/indexer/ds-processor.service.js +1 -22
  13. package/dist/indexer/ds-processor.service.js.map +1 -1
  14. package/dist/indexer/dynamic-ds.service.d.ts +4 -4
  15. package/dist/indexer/dynamic-ds.service.js +2 -20
  16. package/dist/indexer/dynamic-ds.service.js.map +1 -1
  17. package/dist/indexer/fetch.module.js +4 -13
  18. package/dist/indexer/fetch.module.js.map +1 -1
  19. package/dist/indexer/fetch.service.d.ts +1 -5
  20. package/dist/indexer/fetch.service.js +1 -9
  21. package/dist/indexer/fetch.service.js.map +1 -1
  22. package/dist/indexer/indexer.manager.d.ts +5 -10
  23. package/dist/indexer/indexer.manager.js +2 -10
  24. package/dist/indexer/indexer.manager.js.map +1 -1
  25. package/dist/indexer/project.service.d.ts +3 -4
  26. package/dist/indexer/project.service.js +0 -1
  27. package/dist/indexer/project.service.js.map +1 -1
  28. package/dist/indexer/worker/worker-fetch.module.js +2 -4
  29. package/dist/indexer/worker/worker-fetch.module.js.map +1 -1
  30. package/dist/indexer/worker/worker.service.d.ts +2 -3
  31. package/dist/indexer/worker/worker.service.js.map +1 -1
  32. package/dist/stellar/api.connection.spec.js +3 -6
  33. package/dist/stellar/api.connection.spec.js.map +1 -1
  34. package/dist/stellar/api.service.stellar.js +1 -6
  35. package/dist/stellar/api.service.stellar.js.map +1 -1
  36. package/dist/stellar/api.stellar.d.ts +0 -1
  37. package/dist/stellar/api.stellar.js.map +1 -1
  38. package/dist/stellar/api.stellar.spec.js +2 -2
  39. package/dist/stellar/api.stellar.spec.js.map +1 -1
  40. package/dist/stellar/utils.stellar.js.map +1 -1
  41. package/dist/subcommands/forceClean.init.d.ts +1 -1
  42. package/dist/subcommands/forceClean.init.js +1 -15
  43. package/dist/subcommands/forceClean.init.js.map +1 -1
  44. package/dist/subcommands/reindex.init.d.ts +1 -1
  45. package/dist/subcommands/reindex.init.js +1 -20
  46. package/dist/subcommands/reindex.init.js.map +1 -1
  47. package/dist/subcommands/testing.init.js.map +1 -1
  48. package/dist/subcommands/testing.module.js +1 -2
  49. package/dist/subcommands/testing.module.js.map +1 -1
  50. package/dist/subcommands/testing.service.d.ts +4 -4
  51. package/dist/subcommands/testing.service.js.map +1 -1
  52. package/package.json +7 -12
  53. package/dist/indexer/sandbox.service.d.ts +0 -13
  54. package/dist/indexer/sandbox.service.js +0 -65
  55. package/dist/indexer/sandbox.service.js.map +0 -1
  56. package/dist/indexer/worker/worker.unfinalizedBlocks.service.d.ts +0 -12
  57. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js +0 -47
  58. package/dist/indexer/worker/worker.unfinalizedBlocks.service.js.map +0 -1
@@ -22,7 +22,6 @@ const block_stellar_1 = require("../stellar/block.stellar");
22
22
  const ds_processor_service_1 = require("./ds-processor.service");
23
23
  const dynamic_ds_service_1 = require("./dynamic-ds.service");
24
24
  const project_service_1 = require("./project.service");
25
- const sandbox_service_1 = require("./sandbox.service");
26
25
  const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
27
26
  const logger = (0, node_core_1.getLogger)('indexer');
28
27
  let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager {
@@ -31,7 +30,6 @@ let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager
31
30
  this.projectService = projectService;
32
31
  this.isRuntimeDs = common_stellar_1.isRuntimeDs;
33
32
  this.isCustomDs = common_stellar_1.isCustomDs;
34
- this.updateCustomProcessor = ds_processor_service_1.asSecondLayerHandlerProcessor_1_0_0;
35
33
  }
36
34
  async start() {
37
35
  await this.projectService.init();
@@ -40,15 +38,9 @@ let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager
40
38
  async indexBlock(block, dataSources) {
41
39
  return super.internalIndexBlock(block, dataSources, () => this.getApi(block.block));
42
40
  }
43
- getBlockHeight(block) {
44
- return block.block.sequence;
45
- }
46
- getBlockHash(block) {
47
- return block.block.hash;
48
- }
49
41
  // eslint-disable-next-line @typescript-eslint/require-await
50
42
  async getApi(block) {
51
- // return this.apiService.safeApi(this.getBlockHeight(block));
43
+ // return this.apiService.safeApi(block.block.sequence);
52
44
  return null;
53
45
  }
54
46
  async indexBlockData({ block, effects, operations, transactions }, dataSources, getVM) {
@@ -109,7 +101,7 @@ IndexerManager = __decorate([
109
101
  __param(6, (0, common_1.Inject)('IProjectService')),
110
102
  __metadata("design:paramtypes", [node_core_1.ApiService,
111
103
  node_core_1.NodeConfig,
112
- sandbox_service_1.SandboxService,
104
+ node_core_1.SandboxService,
113
105
  ds_processor_service_1.DsProcessorService,
114
106
  dynamic_ds_service_1.DynamicDsService,
115
107
  unfinalizedBlocks_service_1.UnfinalizedBlocksService,
@@ -1 +1 @@
1
- {"version":3,"file":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,0DAa+B;AAC/B,gDAS0B;AAiB1B,4DAA+D;AAE/D,iEAGgC;AAChC,6DAAwD;AACxD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AAEvE,MAAM,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A;KAAA;IAEH,CAAC,mCAAkB,CAAC,OAAO,CAAC,EAAE,CAC5B,IAAmB,EACnB,MAA2B,EAC3B,EAA0B,EAC1B,EAAE;;QACF,OAAA,mCAAmB,CAAC,qBAAqB,CACvC,IAAI,EACJ,MAAM,EACN,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CACpB,CAAA;KAAA;IAEH,CAAC,mCAAkB,CAAC,KAAK,CAAC,EAAE,CAC1B,IAAkB,EAClB,MAA0B,EAC1B,EAA0B,EAC1B,EAAE,WACF,OAAA,mCAAmB,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAA,EAAA;CAC9E,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n isCustomDs,\n isRuntimeDs,\n SubqlStellarCustomDataSource,\n StellarHandlerKind,\n StellarRuntimeHandlerInputMap,\n SubqlStellarDataSource,\n isBlockHandlerProcessor,\n isTransactionHandlerProcessor,\n isOperationHandlerProcessor,\n isEffectHandlerProcessor,\n isEventHandlerProcessor,\n isSorobanTransactionHandlerProcessor,\n} from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n ApiService,\n IBlock,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n StellarTransaction,\n StellarOperation,\n StellarEffect,\n StellarBlock,\n StellarBlockFilter,\n StellarTransactionFilter,\n StellarOperationFilter,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n} from '@subql/types-stellar';\nimport { StellarProjectDs } from '../configure/SubqueryProject';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport {\n asSecondLayerHandlerProcessor_1_0_0,\n DsProcessorService,\n} from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport { SandboxService } from './sandbox.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('indexer');\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n SafeStellarProvider,\n StellarApi,\n StellarBlockWrapper,\n ApiService,\n SubqlStellarDataSource,\n SubqlStellarCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n StellarRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n protected updateCustomProcessor = asSecondLayerHandlerProcessor_1_0_0;\n\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IProjectService') private projectService: ProjectService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n async start(): Promise<void> {\n await this.projectService.init();\n logger.info('indexer manager started');\n }\n\n @profiler()\n async indexBlock(\n block: IBlock<StellarBlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block.block),\n );\n }\n\n getBlockHeight(block: StellarBlockWrapper): number {\n return block.block.sequence;\n }\n\n getBlockHash(block: StellarBlockWrapper): string {\n return block.block.hash;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(\n block: StellarBlockWrapper,\n ): Promise<SafeStellarProvider> {\n // return this.apiService.safeApi(this.getBlockHeight(block));\n return null;\n }\n\n protected async indexBlockData(\n { block, effects, operations, transactions }: StellarBlockWrapper,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const operation of tx.operations) {\n await this.indexOperation(operation, dataSources, getVM);\n\n for (const effect of operation.effects) {\n await this.indexEffect(effect, dataSources, getVM);\n }\n for (const event of operation.events) {\n await this.indexEvent(event, dataSources, getVM);\n }\n }\n }\n }\n\n private async indexBlockContent(\n block: StellarBlock,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n transaction: StellarTransaction,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(\n StellarHandlerKind.Transaction,\n transaction,\n ds,\n getVM,\n );\n\n if (\n transaction.operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n )\n ) {\n await this.indexData(\n StellarHandlerKind.SorobanTransaction,\n transaction,\n ds,\n getVM,\n );\n }\n }\n }\n\n private async indexOperation(\n operation: StellarOperation,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Operation, operation, ds, getVM);\n }\n }\n\n private async indexEffect(\n effect: StellarEffect,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Effects, effect, ds, getVM);\n }\n }\n\n private async indexEvent(\n event: SorobanEvent,\n dataSources: StellarProjectDs[],\n getVM: (d: StellarProjectDs) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Event, event, ds, getVM);\n }\n }\n\n protected async prepareFilteredData<T = any>(\n kind: StellarHandlerKind,\n data: T,\n ds: SubqlDatasource,\n ): Promise<T> {\n return Promise.resolve(data);\n }\n}\n\ntype ProcessorTypeMap = {\n [StellarHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [StellarHandlerKind.Transaction]: typeof isTransactionHandlerProcessor;\n [StellarHandlerKind.SorobanTransaction]: typeof isSorobanTransactionHandlerProcessor;\n [StellarHandlerKind.Operation]: typeof isOperationHandlerProcessor;\n [StellarHandlerKind.Effects]: typeof isEffectHandlerProcessor;\n [StellarHandlerKind.Event]: typeof isEventHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [StellarHandlerKind.Block]: isBlockHandlerProcessor,\n [StellarHandlerKind.Transaction]: isTransactionHandlerProcessor,\n [StellarHandlerKind.SorobanTransaction]: isSorobanTransactionHandlerProcessor,\n [StellarHandlerKind.Operation]: isOperationHandlerProcessor,\n [StellarHandlerKind.Effects]: isEffectHandlerProcessor,\n [StellarHandlerKind.Event]: isEventHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [StellarHandlerKind.Block]: (\n data: StellarBlock,\n filter: StellarBlockFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterBlocksProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Transaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.SorobanTransaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Operation]: (\n data: StellarOperation,\n filter: StellarOperationFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterOperationProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Effects]: (\n data: StellarEffect,\n filter: StellarEffectFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEffectProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Event]: (\n data: SorobanEvent,\n filter: SorobanEventFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEventProcessor(data, filter, ds.options?.address),\n};\n"]}
1
+ {"version":3,"file":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,0DAa+B;AAC/B,gDAU0B;AAgB1B,4DAA+D;AAE/D,iEAA4D;AAC5D,6DAAwD;AACxD,uDAAmD;AACnD,2EAAuE;AAEvE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAUnC;IAIC,YACE,UAAsB,EACtB,UAAsB,EACtB,cAA+D,EAC/D,kBAAsC,EACtC,gBAAkC,EAClC,wBAAkD,EACf,cAA8B;QAEjE,KAAK,CACH,UAAU,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,CACjB,CAAC;QAXiC,mBAAc,GAAd,cAAc,CAAgB;QAVzD,gBAAW,GAAG,4BAAW,CAAC;QAC1B,eAAU,GAAG,2BAAU,CAAC;IAqBlC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CACd,KAAkC,EAClC,WAAqC;QAErC,OAAO,KAAK,CAAC,kBAAkB,CAAC,K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B,EAC1B,EAAE;;QACF,OAAA,mCAAmB,CAAC,0BAA0B,CAC5C,IAAI,EACJ,MAAM,EACN,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CACpB,CAAA;KAAA;IAEH,CAAC,mCAAkB,CAAC,SAAS,CAAC,EAAE,CAC9B,IAAsB,EACtB,MAA8B,EAC9B,EAA0B,EAC1B,EAAE;;QACF,OAAA,mCAAmB,CAAC,wBAAwB,CAC1C,IAAI,EACJ,MAAM,EACN,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CACpB,CAAA;KAAA;IAEH,CAAC,mCAAkB,CAAC,OAAO,CAAC,EAAE,CAC5B,IAAmB,EACnB,MAA2B,EAC3B,EAA0B,EAC1B,EAAE;;QACF,OAAA,mCAAmB,CAAC,qBAAqB,CACvC,IAAI,EACJ,MAAM,EACN,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CACpB,CAAA;KAAA;IAEH,CAAC,mCAAkB,CAAC,KAAK,CAAC,EAAE,CAC1B,IAAkB,EAClB,MAA0B,EAC1B,EAA0B,EAC1B,EAAE,WACF,OAAA,mCAAmB,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAA,EAAA;CAC9E,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n isCustomDs,\n isRuntimeDs,\n SubqlStellarCustomDataSource,\n StellarHandlerKind,\n StellarRuntimeHandlerInputMap,\n SubqlStellarDataSource,\n isBlockHandlerProcessor,\n isTransactionHandlerProcessor,\n isOperationHandlerProcessor,\n isEffectHandlerProcessor,\n isEventHandlerProcessor,\n isSorobanTransactionHandlerProcessor,\n} from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n ApiService,\n IBlock,\n SandboxService,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n StellarTransaction,\n StellarOperation,\n StellarEffect,\n StellarBlock,\n StellarBlockFilter,\n StellarTransactionFilter,\n StellarOperationFilter,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n} from '@subql/types-stellar';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('indexer');\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n StellarApi,\n SafeStellarProvider,\n StellarBlockWrapper,\n ApiService,\n SubqlStellarDataSource,\n SubqlStellarCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n StellarRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService<SafeStellarProvider, StellarApi>,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IProjectService') private projectService: ProjectService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n async start(): Promise<void> {\n await this.projectService.init();\n logger.info('indexer manager started');\n }\n\n @profiler()\n async indexBlock(\n block: IBlock<StellarBlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block.block),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(\n block: StellarBlockWrapper,\n ): Promise<SafeStellarProvider> {\n // return this.apiService.safeApi(block.block.sequence);\n return null;\n }\n\n protected async indexBlockData(\n { block, effects, operations, transactions }: StellarBlockWrapper,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const operation of tx.operations) {\n await this.indexOperation(operation, dataSources, getVM);\n\n for (const effect of operation.effects) {\n await this.indexEffect(effect, dataSources, getVM);\n }\n for (const event of operation.events) {\n await this.indexEvent(event, dataSources, getVM);\n }\n }\n }\n }\n\n private async indexBlockContent(\n block: StellarBlock,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n transaction: StellarTransaction,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(\n StellarHandlerKind.Transaction,\n transaction,\n ds,\n getVM,\n );\n\n if (\n transaction.operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n )\n ) {\n await this.indexData(\n StellarHandlerKind.SorobanTransaction,\n transaction,\n ds,\n getVM,\n );\n }\n }\n }\n\n private async indexOperation(\n operation: StellarOperation,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Operation, operation, ds, getVM);\n }\n }\n\n private async indexEffect(\n effect: StellarEffect,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Effects, effect, ds, getVM);\n }\n }\n\n private async indexEvent(\n event: SorobanEvent,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Event, event, ds, getVM);\n }\n }\n\n protected async prepareFilteredData<T = any>(\n kind: StellarHandlerKind,\n data: T,\n ds: SubqlDatasource,\n ): Promise<T> {\n return Promise.resolve(data);\n }\n}\n\ntype ProcessorTypeMap = {\n [StellarHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [StellarHandlerKind.Transaction]: typeof isTransactionHandlerProcessor;\n [StellarHandlerKind.SorobanTransaction]: typeof isSorobanTransactionHandlerProcessor;\n [StellarHandlerKind.Operation]: typeof isOperationHandlerProcessor;\n [StellarHandlerKind.Effects]: typeof isEffectHandlerProcessor;\n [StellarHandlerKind.Event]: typeof isEventHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [StellarHandlerKind.Block]: isBlockHandlerProcessor,\n [StellarHandlerKind.Transaction]: isTransactionHandlerProcessor,\n [StellarHandlerKind.SorobanTransaction]: isSorobanTransactionHandlerProcessor,\n [StellarHandlerKind.Operation]: isOperationHandlerProcessor,\n [StellarHandlerKind.Effects]: isEffectHandlerProcessor,\n [StellarHandlerKind.Event]: isEventHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [StellarHandlerKind.Block]: (\n data: StellarBlock,\n filter: StellarBlockFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterBlocksProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Transaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.SorobanTransaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Operation]: (\n data: StellarOperation,\n filter: StellarOperationFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterOperationProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Effects]: (\n data: StellarEffect,\n filter: StellarEffectFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEffectProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Event]: (\n data: SorobanEvent,\n filter: SorobanEventFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEventProcessor(data, filter, ds.options?.address),\n};\n"]}
@@ -1,15 +1,14 @@
1
1
  import { EventEmitter2 } from '@nestjs/event-emitter';
2
2
  import { PoiService, PoiSyncService, BaseProjectService, StoreService, NodeConfig, ApiService, IProjectUpgradeService } from '@subql/node-core';
3
- import { StellarBlockWrapper } from '@subql/types-stellar';
3
+ import { StellarBlockWrapper, SubqlDatasource } from '@subql/types-stellar';
4
4
  import { Sequelize } from '@subql/x-sequelize';
5
- import { StellarProjectDs, SubqueryProject } from '../configure/SubqueryProject';
5
+ import { SubqueryProject } from '../configure/SubqueryProject';
6
6
  import { StellarApi } from '../stellar';
7
7
  import SafeStellarProvider from '../stellar/safe-api';
8
8
  import { DsProcessorService } from './ds-processor.service';
9
9
  import { DynamicDsService } from './dynamic-ds.service';
10
10
  import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
11
- export declare class ProjectService extends BaseProjectService<ApiService<StellarApi, SafeStellarProvider, StellarBlockWrapper[]>, StellarProjectDs> {
12
- protected readonly projectUpgradeService: IProjectUpgradeService<SubqueryProject>;
11
+ export declare class ProjectService extends BaseProjectService<ApiService<StellarApi, SafeStellarProvider, StellarBlockWrapper[]>, SubqlDatasource> {
13
12
  protected packageVersion: any;
14
13
  constructor(dsProcessorService: DsProcessorService, apiService: ApiService, poiService: PoiService, poiSyncService: PoiSyncService, sequelize: Sequelize, project: SubqueryProject, projectUpgradeService: IProjectUpgradeService<SubqueryProject>, storeService: StoreService, nodeConfig: NodeConfig, dynamicDsService: DynamicDsService, eventEmitter: EventEmitter2, unfinalizedBlockService: UnfinalizedBlocksService);
15
14
  init(startHeight?: number): Promise<void>;
@@ -29,7 +29,6 @@ const { version: packageVersion } = require('../../package.json');
29
29
  let ProjectService = class ProjectService extends node_core_1.BaseProjectService {
30
30
  constructor(dsProcessorService, apiService, poiService, poiSyncService, sequelize, project, projectUpgradeService, storeService, nodeConfig, dynamicDsService, eventEmitter, unfinalizedBlockService) {
31
31
  super(dsProcessorService, apiService, poiService, poiSyncService, sequelize, project, projectUpgradeService, storeService, nodeConfig, dynamicDsService, eventEmitter, unfinalizedBlockService);
32
- this.projectUpgradeService = projectUpgradeService;
33
32
  this.packageVersion = packageVersion;
34
33
  }
35
34
  async init(startHeight) {
@@ -1 +1 @@
1
- {"version":3,"file":"project.service.js","sourceRoot":"","sources":["../../src/indexer/project.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,mDAA8C;AAC9C,2CAAoD;AACpD,yDAAsD;AACtD,gDAS0B;AAE1B,oDAA+C;AAE/C,kEAIsC;AAGtC,iEAA4D;AAC5D,6DAAwD;AACxD,2EAAuE;AAEvE,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAG3D,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAGnC;IAGC,YACE,kBAAsC,EACtC,UAAsB,EACsB,UAAsB,EAElE,cAA8B,EACa,SAAoB,EACnC,OAAwB,EAEjC,qBAA8D,EACnC,YAA0B,EACxE,UAAsB,EACtB,gBAAkC,EAClC,YAA2B,EAC3B,uBAAiD;QAEjD,KAAK,CACH,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,qB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BAAU;QACkC,sBAAU;QAElD,0BAAc;QACwB,uBAAS;QAC1B,iCAAe,UAGQ,wBAAY;QAC5D,sBAAU;QACJ,qCAAgB;QACpB,6BAAa;QACF,oDAAwB;GApBxC,cAAc,CAwD1B;AAxDY,wCAAc","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { isMainThread } from 'worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n PoiService,\n PoiSyncService,\n BaseProjectService,\n StoreService,\n NodeConfig,\n ApiService,\n IProjectUpgradeService,\n profiler,\n} from '@subql/node-core';\nimport { StellarBlockWrapper } from '@subql/types-stellar';\nimport { Sequelize } from '@subql/x-sequelize';\nimport { ServerApi } from 'stellar-sdk/lib/horizon';\nimport {\n // generateTimestampReferenceForBlockFilters,\n StellarProjectDs,\n SubqueryProject,\n} from '../configure/SubqueryProject';\nimport { StellarApi } from '../stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\n@Injectable()\nexport class ProjectService extends BaseProjectService<\n ApiService<StellarApi, SafeStellarProvider, StellarBlockWrapper[]>,\n StellarProjectDs\n> {\n protected packageVersion = packageVersion;\n\n constructor(\n dsProcessorService: DsProcessorService,\n apiService: ApiService,\n @Inject(isMainThread ? PoiService : 'Null') poiService: PoiService,\n @Inject(isMainThread ? PoiSyncService : 'Null')\n poiSyncService: PoiSyncService,\n @Inject(isMainThread ? Sequelize : 'Null') sequelize: Sequelize,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n protected readonly projectUpgradeService: IProjectUpgradeService<SubqueryProject>,\n @Inject(isMainThread ? StoreService : 'Null') storeService: StoreService,\n nodeConfig: NodeConfig,\n dynamicDsService: DynamicDsService,\n eventEmitter: EventEmitter2,\n unfinalizedBlockService: UnfinalizedBlocksService,\n ) {\n super(\n dsProcessorService,\n apiService,\n poiService,\n poiSyncService,\n sequelize,\n project,\n projectUpgradeService,\n storeService,\n nodeConfig,\n dynamicDsService,\n eventEmitter,\n unfinalizedBlockService,\n );\n }\n\n @profiler()\n async init(startHeight?: number): Promise<void> {\n return super.init(startHeight);\n }\n\n protected async getBlockTimestamp(height: number): Promise<Date> {\n const block = await this.apiService.unsafeApi.api\n .ledgers()\n .ledger(height)\n .call();\n\n return new Date((block as unknown as ServerApi.LedgerRecord).closed_at); // TODO test and make sure its in MS not S\n }\n\n protected onProjectChange(project: SubqueryProject): void | Promise<void> {\n // TODO update this when implementing skipBlock feature for Eth\n // this.apiService.updateBlockFetching();\n }\n}\n"]}
1
+ {"version":3,"file":"project.service.js","sourceRoot":"","sources":["../../src/indexer/project.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,mDAA8C;AAC9C,2CAAoD;AACpD,yDAAsD;AACtD,gDAS0B;AAE1B,oDAA+C;AAE/C,kEAA+D;AAG/D,iEAA4D;AAC5D,6DAAwD;AACxD,2EAAuE;AAEvE,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAG3D,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAGnC;IAGC,YACE,kBAAsC,EACtC,UAAsB,EACsB,UAAsB,EAElE,cAA8B,EACa,SAAoB,EACnC,OAAwB,EAEpD,qBAA8D,EAChB,YAA0B,EACxE,UAAsB,EACtB,gBAAkC,EAClC,YAA2B,EAC3B,uBAAiD;QAEjD,KAAK,CACH,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,qBAAqB,EACrB,Y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B,iCAAe,UAGQ,wBAAY;QAC5D,sBAAU;QACJ,qCAAgB;QACpB,6BAAa;QACF,oDAAwB;GApBxC,cAAc,CAwD1B;AAxDY,wCAAc","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { isMainThread } from 'worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n PoiService,\n PoiSyncService,\n BaseProjectService,\n StoreService,\n NodeConfig,\n ApiService,\n IProjectUpgradeService,\n profiler,\n} from '@subql/node-core';\nimport { StellarBlockWrapper, SubqlDatasource } from '@subql/types-stellar';\nimport { Sequelize } from '@subql/x-sequelize';\nimport { ServerApi } from 'stellar-sdk/lib/horizon';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApi } from '../stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\n@Injectable()\nexport class ProjectService extends BaseProjectService<\n ApiService<StellarApi, SafeStellarProvider, StellarBlockWrapper[]>,\n SubqlDatasource\n> {\n protected packageVersion = packageVersion;\n\n constructor(\n dsProcessorService: DsProcessorService,\n apiService: ApiService,\n @Inject(isMainThread ? PoiService : 'Null') poiService: PoiService,\n @Inject(isMainThread ? PoiSyncService : 'Null')\n poiSyncService: PoiSyncService,\n @Inject(isMainThread ? Sequelize : 'Null') sequelize: Sequelize,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService<SubqueryProject>,\n @Inject(isMainThread ? StoreService : 'Null') storeService: StoreService,\n nodeConfig: NodeConfig,\n dynamicDsService: DynamicDsService,\n eventEmitter: EventEmitter2,\n unfinalizedBlockService: UnfinalizedBlocksService,\n ) {\n super(\n dsProcessorService,\n apiService,\n poiService,\n poiSyncService,\n sequelize,\n project,\n projectUpgradeService,\n storeService,\n nodeConfig,\n dynamicDsService,\n eventEmitter,\n unfinalizedBlockService,\n );\n }\n\n @profiler()\n async init(startHeight?: number): Promise<void> {\n return super.init(startHeight);\n }\n\n protected async getBlockTimestamp(height: number): Promise<Date> {\n const block = await this.apiService.unsafeApi.api\n .ledgers()\n .ledger(height)\n .call();\n\n return new Date((block as unknown as ServerApi.LedgerRecord).closed_at); // TODO test and make sure its in MS not S\n }\n\n protected onProjectChange(project: SubqueryProject): void | Promise<void> {\n // TODO update this when implementing skipBlock feature for Eth\n // this.apiService.updateBlockFetching();\n }\n}\n"]}
@@ -18,10 +18,8 @@ const ds_processor_service_1 = require("../ds-processor.service");
18
18
  const dynamic_ds_service_1 = require("../dynamic-ds.service");
19
19
  const indexer_manager_1 = require("../indexer.manager");
20
20
  const project_service_1 = require("../project.service");
21
- const sandbox_service_1 = require("../sandbox.service");
22
21
  const unfinalizedBlocks_service_1 = require("../unfinalizedBlocks.service");
23
22
  const worker_service_1 = require("./worker.service");
24
- const worker_unfinalizedBlocks_service_1 = require("./worker.unfinalizedBlocks.service");
25
23
  let WorkerFetchModule = class WorkerFetchModule {
26
24
  };
27
25
  WorkerFetchModule = __decorate([
@@ -52,7 +50,7 @@ WorkerFetchModule = __decorate([
52
50
  event_emitter_1.EventEmitter2,
53
51
  ],
54
52
  },
55
- sandbox_service_1.SandboxService,
53
+ node_core_1.SandboxService,
56
54
  ds_processor_service_1.DsProcessorService,
57
55
  {
58
56
  provide: dynamic_ds_service_1.DynamicDsService,
@@ -74,7 +72,7 @@ WorkerFetchModule = __decorate([
74
72
  if (worker_threads_1.isMainThread) {
75
73
  throw new Error('Expected to be worker thread');
76
74
  }
77
- return new worker_unfinalizedBlocks_service_1.WorkerUnfinalizedBlocksService(global.host);
75
+ return new node_core_1.WorkerUnfinalizedBlocksService(global.host);
78
76
  },
79
77
  },
80
78
  {
@@ -1 +1 @@
1
- {"version":3,"file":"worker-fetch.module.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker-fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,mDAA8C;AAC9C,2CAAwC;AACxC,yDAAsD;AACtD,gDAS0B;AAE1B,2CAAkD;AAElD,kEAA6D;AAC7D,8DAAyD;AACzD,wDAAoD;AACpD,wDAAoD;AACpD,wDAAoD;AACpD,4EAAwE;AACxE,qDAAiD;AACjD,yFAAoF;AAsE7E,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,iBAAiB;IApE7B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,gCAAc;YACd;gBACE,OAAO,EAAE,sCAA0B;gBACnC,UAAU,EAAE,GAAG,EAAE;oBACf,IAAI,6BAAY,EAAE;wBAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;qBACjD;oBACD,OAAO,IAAI,4CAAgC,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC;gBACpE,CAAC;aACF;YACD,iCAAqB;YACrB;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAA4C,EAC5C,qBAAkE,EAClE,YAA2B,EAC3B,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,2BAAiB,CACtC,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,CACb,CAAC;oBACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;oBACxB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,MAAM,EAAE;oBACN,kBAAkB;oBAClB,wBAAwB;oBACxB,iCAAqB;oBACrB,6BAAa;iBACd;aACF;YACD,gCAAc;YACd,yCAAkB;YAClB;gBACE,OAAO,EAAE,qCAAgB;gBACzB,UAAU,EAAE,GAAG,EAAE;oBACf,IAAI,6BAAY,EAAE;wBAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;qBACjD;oBACD,OAAO,IAAI,kCAAsB,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC;gBAC1D,CAAC;aACF;YACD;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,gCAAc;aACzB;YACD,8BAAa;YACb;gBACE,OAAO,EAAE,oDAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE;oBACf,IAAI,6BAAY,EAAE;wBAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;qBACjD;oBACD,OAAO,IAAI,iEAA8B,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC;gBAClE,CAAC;aACF;YACD;gBACE,OAAO,EAAE,gCAAoB;gBAC7B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,sCAA0B,CAAE,MAAc,CAAC,IAAI,CAAC;aACvE;SACF;KACF,CAAC;GACW,iBAAiB,CAAG;AAApB,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { isMainThread } from 'worker_threads';\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n WorkerDynamicDsService,\n ConnectionPoolStateManager,\n WorkerConnectionPoolStateManager,\n ProjectUpgradeService,\n InMemoryCacheService,\n WorkerInMemoryCacheService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../../configure/SubqueryProject';\nimport { StellarApiService } from '../../stellar';\nimport { StellarApiConnection } from '../../stellar/api.connection';\nimport { DsProcessorService } from '../ds-processor.service';\nimport { DynamicDsService } from '../dynamic-ds.service';\nimport { IndexerManager } from '../indexer.manager';\nimport { ProjectService } from '../project.service';\nimport { SandboxService } from '../sandbox.service';\nimport { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';\nimport { WorkerService } from './worker.service';\nimport { WorkerUnfinalizedBlocksService } from './worker.unfinalizedBlocks.service';\n\n@Module({\n providers: [\n IndexerManager,\n {\n provide: ConnectionPoolStateManager,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerConnectionPoolStateManager((global as any).host);\n },\n },\n ConnectionPoolService,\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n projectUpgradeService: ProjectUpgradeService,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) => {\n const apiService = new StellarApiService(\n project,\n projectUpgradeService,\n connectionPoolService,\n eventEmitter,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n 'IProjectUpgradeService',\n ConnectionPoolService,\n EventEmitter2,\n ],\n },\n SandboxService,\n DsProcessorService,\n {\n provide: DynamicDsService,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerDynamicDsService((global as any).host);\n },\n },\n {\n provide: 'IProjectService',\n useClass: ProjectService,\n },\n WorkerService,\n {\n provide: UnfinalizedBlocksService,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerUnfinalizedBlocksService((global as any).host);\n },\n },\n {\n provide: InMemoryCacheService,\n useFactory: () => new WorkerInMemoryCacheService((global as any).host),\n },\n ],\n})\nexport class WorkerFetchModule {}\n"]}
1
+ {"version":3,"file":"worker-fetch.module.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker-fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,mDAA8C;AAC9C,2CAAwC;AACxC,yDAAsD;AACtD,gDAW0B;AAE1B,2CAAkD;AAElD,kEAA6D;AAC7D,8DAAyD;AACzD,wDAAoD;AACpD,wDAAoD;AACpD,4EAAwE;AACxE,qDAAiD;AAsE1C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,iBAAiB;IApE7B,IAAA,e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aACF;YACD;gBACE,OAAO,EAAE,gCAAoB;gBAC7B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,sCAA0B,CAAE,MAAc,CAAC,IAAI,CAAC;aACvE;SACF;KACF,CAAC;GACW,iBAAiB,CAAG;AAApB,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { isMainThread } from 'worker_threads';\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n WorkerDynamicDsService,\n ConnectionPoolStateManager,\n WorkerConnectionPoolStateManager,\n ProjectUpgradeService,\n InMemoryCacheService,\n WorkerInMemoryCacheService,\n SandboxService,\n WorkerUnfinalizedBlocksService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../../configure/SubqueryProject';\nimport { StellarApiService } from '../../stellar';\nimport { StellarApiConnection } from '../../stellar/api.connection';\nimport { DsProcessorService } from '../ds-processor.service';\nimport { DynamicDsService } from '../dynamic-ds.service';\nimport { IndexerManager } from '../indexer.manager';\nimport { ProjectService } from '../project.service';\nimport { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';\nimport { WorkerService } from './worker.service';\n\n@Module({\n providers: [\n IndexerManager,\n {\n provide: ConnectionPoolStateManager,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerConnectionPoolStateManager((global as any).host);\n },\n },\n ConnectionPoolService,\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n projectUpgradeService: ProjectUpgradeService,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) => {\n const apiService = new StellarApiService(\n project,\n projectUpgradeService,\n connectionPoolService,\n eventEmitter,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n 'IProjectUpgradeService',\n ConnectionPoolService,\n EventEmitter2,\n ],\n },\n SandboxService,\n DsProcessorService,\n {\n provide: DynamicDsService,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerDynamicDsService((global as any).host);\n },\n },\n {\n provide: 'IProjectService',\n useClass: ProjectService,\n },\n WorkerService,\n {\n provide: UnfinalizedBlocksService,\n useFactory: () => {\n if (isMainThread) {\n throw new Error('Expected to be worker thread');\n }\n return new WorkerUnfinalizedBlocksService((global as any).host);\n },\n },\n {\n provide: InMemoryCacheService,\n useFactory: () => new WorkerInMemoryCacheService((global as any).host),\n },\n ],\n})\nexport class WorkerFetchModule {}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { SubqlStellarDataSource } from '@subql/common-stellar';
2
2
  import { NodeConfig, IProjectService, ProcessBlockResponse, ApiService, BaseWorkerService, IProjectUpgradeService, IBlock } from '@subql/node-core';
3
- import { BlockWrapper } from '@subql/types-stellar';
4
- import { StellarProjectDs } from '../../configure/SubqueryProject';
3
+ import { BlockWrapper, SubqlDatasource } from '@subql/types-stellar';
5
4
  import { IndexerManager } from '../indexer.manager';
6
5
  export type FetchBlockResponse = {
7
6
  parentHash: string;
@@ -15,7 +14,7 @@ export type WorkerStatusResponse = {
15
14
  export declare class WorkerService extends BaseWorkerService<BlockWrapper, FetchBlockResponse, SubqlStellarDataSource, {}> {
16
15
  private apiService;
17
16
  private indexerManager;
18
- constructor(apiService: ApiService, indexerManager: IndexerManager, projectService: IProjectService<StellarProjectDs>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
17
+ constructor(apiService: ApiService, indexerManager: IndexerManager, projectService: IProjectService<SubqlDatasource>, projectUpgradeService: IProjectUpgradeService, nodeConfig: NodeConfig);
19
18
  protected fetchChainBlock(heights: number, extra: {}): Promise<IBlock<BlockWrapper>>;
20
19
  protected toBlockResponse(block: BlockWrapper): {
21
20
  parentHash: string;
@@ -1 +1 @@
1
- {"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,6DAA+C;AAC/C,2CAAoD;AAEpD,gDAS0B;AAG1B,wDAAoD;AAWpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,8BAAQ,EAAE,CAAC,CAAC;AAGjD,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,6BAKlC;IACC,YACU,UAAsB,EACtB,cAA8B,EAEtC,cAAiD,EAEjD,qBAA6C,EAC7C,UAAsB;QAEtB,KAAK,CAAC,cAAc,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;QARjD,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;IAQxC,CAAC;IACS,KAAK,CAAC,eAAe,CAC7B,OAAe,EACf,KAAS;QAET,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAmB;QAC3C,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB,CACjC,KAA2B,EAC3B,WAAqC;QAErC,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AArCY,aAAa;IADzB,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCAJb,sBAAU;QACN,gCAAc,kBAK1B,sBAAU;GAbb,aAAa,CAqCzB;AArCY,sCAAa","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { threadId } from 'node:worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { SubqlStellarDataSource } from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n IProjectService,\n ProcessBlockResponse,\n ApiService,\n BaseWorkerService,\n IProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { BlockWrapper } from '@subql/types-stellar';\nimport { StellarProjectDs } from '../../configure/SubqueryProject';\nimport { IndexerManager } from '../indexer.manager';\n\nexport type FetchBlockResponse = { parentHash: string } | undefined;\n\nexport type WorkerStatusResponse = {\n threadId: number;\n isIndexing: boolean;\n fetchedBlocks: number;\n toFetchBlocks: number;\n};\n\nconst logger = getLogger(`Worker Service #${threadId}`);\n\n@Injectable()\nexport class WorkerService extends BaseWorkerService<\n BlockWrapper,\n FetchBlockResponse,\n SubqlStellarDataSource,\n {}\n> {\n constructor(\n private apiService: ApiService,\n private indexerManager: IndexerManager,\n @Inject('IProjectService')\n projectService: IProjectService<StellarProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n nodeConfig: NodeConfig,\n ) {\n super(projectService, projectUpgradeService, nodeConfig);\n }\n protected async fetchChainBlock(\n heights: number,\n extra: {},\n ): Promise<IBlock<BlockWrapper>> {\n const [block] = await this.apiService.fetchBlocks([heights]);\n return block;\n }\n\n protected toBlockResponse(block: BlockWrapper): { parentHash: string } {\n return {\n parentHash: block.block.prev_hash,\n };\n }\n\n protected async processFetchedBlock(\n block: IBlock<BlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(block, dataSources);\n }\n}\n"]}
1
+ {"version":3,"file":"worker.service.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,6DAA+C;AAC/C,2CAAoD;AAEpD,gDAS0B;AAE1B,wDAAoD;AAWpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,8BAAQ,EAAE,CAAC,CAAC;AAGjD,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,6BAKlC;IACC,YACU,UAAsB,EACtB,cAA8B,EAEtC,cAAgD,EAEhD,qBAA6C,EAC7C,UAAsB;QAEtB,KAAK,CAAC,cAAc,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;QARjD,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;IAQxC,CAAC;IACS,KAAK,CAAC,eAAe,CAC7B,OAAe,EACf,KAAS;QAET,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAmB;QAC3C,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,mBAAmB,CACjC,KAA2B,EAC3B,WAAqC;QAErC,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AArCY,aAAa;IADzB,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCAJb,sBAAU;QACN,gCAAc,kBAK1B,sBAAU;GAbb,aAAa,CAqCzB;AArCY,sCAAa","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { threadId } from 'node:worker_threads';\nimport { Inject, Injectable } from '@nestjs/common';\nimport { SubqlStellarDataSource } from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n IProjectService,\n ProcessBlockResponse,\n ApiService,\n BaseWorkerService,\n IProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { BlockWrapper, SubqlDatasource } from '@subql/types-stellar';\nimport { IndexerManager } from '../indexer.manager';\n\nexport type FetchBlockResponse = { parentHash: string } | undefined;\n\nexport type WorkerStatusResponse = {\n threadId: number;\n isIndexing: boolean;\n fetchedBlocks: number;\n toFetchBlocks: number;\n};\n\nconst logger = getLogger(`Worker Service #${threadId}`);\n\n@Injectable()\nexport class WorkerService extends BaseWorkerService<\n BlockWrapper,\n FetchBlockResponse,\n SubqlStellarDataSource,\n {}\n> {\n constructor(\n private apiService: ApiService,\n private indexerManager: IndexerManager,\n @Inject('IProjectService')\n projectService: IProjectService<SubqlDatasource>,\n @Inject('IProjectUpgradeService')\n projectUpgradeService: IProjectUpgradeService,\n nodeConfig: NodeConfig,\n ) {\n super(projectService, projectUpgradeService, nodeConfig);\n }\n protected async fetchChainBlock(\n heights: number,\n extra: {},\n ): Promise<IBlock<BlockWrapper>> {\n const [block] = await this.apiService.fetchBlocks([heights]);\n return block;\n }\n\n protected toBlockResponse(block: BlockWrapper): { parentHash: string } {\n return {\n parentHash: block.block.prev_hash,\n };\n }\n\n protected async processFetchedBlock(\n block: IBlock<BlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return this.indexerManager.indexBlock(block, dataSources);\n }\n}\n"]}
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ const event_emitter_1 = require("@nestjs/event-emitter");
8
6
  const node_core_1 = require("@subql/node-core");
9
- const eventemitter2_1 = __importDefault(require("eventemitter2"));
10
7
  const api_connection_1 = require("./api.connection");
11
8
  const api_stellar_1 = require("./api.stellar");
12
9
  const soroban_server_1 = require("./soroban.server");
@@ -33,12 +30,12 @@ describe('StellarApiConnection', () => {
33
30
  const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);
34
31
  beforeEach(async () => {
35
32
  sorobanApi = new soroban_server_1.SorobanServer(SOROBAN_ENDPOINT);
36
- unsafeApi = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new eventemitter2_1.default(), sorobanApi);
33
+ unsafeApi = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new event_emitter_1.EventEmitter2(), sorobanApi);
37
34
  await unsafeApi.init();
38
35
  apiConnection = new api_connection_1.StellarApiConnection(unsafeApi, fetchBlockBatches);
39
36
  });
40
37
  it('creates a connection', async () => {
41
- expect(await api_connection_1.StellarApiConnection.create(HTTP_ENDPOINT, fetchBlockBatches, new eventemitter2_1.default(), sorobanApi)).toBeInstanceOf(api_connection_1.StellarApiConnection);
38
+ expect(await api_connection_1.StellarApiConnection.create(HTTP_ENDPOINT, fetchBlockBatches, new event_emitter_1.EventEmitter2(), sorobanApi)).toBeInstanceOf(api_connection_1.StellarApiConnection);
42
39
  });
43
40
  it('fetches blocks', async () => {
44
41
  const result = await apiConnection.fetchBlocks([1, 2]);
@@ -1 +1 @@
1
- {"version":3,"file":"api.connection.spec.js","sourceRoot":"","sources":["../../src/stellar/api.connection.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAO0B;AAE1B,kEAA0C;AAC1C,qDAAwD;AACxD,+CAA2C;AAE3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,SAAqB,CAAC;IAC1B,IAAI,UAAyB,CAAC;IAC9B,MAAM,UAAU,GAA0B;QACxC;YACE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAA6B;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ACzC,MAAM,YAAY,GAAG,qCAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC7D,MAAM,CAAC,YAAY,CAAC,CAAC,cAAc,CAAC,8BAAkB,CAAC,CAAC;YACxD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,wBAAY,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n RateLimitError,\n TimeoutError,\n} from '@subql/node-core';\nimport { StellarBlock, StellarBlockWrapper } from '@subql/types-stellar';\nimport EventEmitter2 from 'eventemitter2';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\ndescribe('StellarApiConnection', () => {\n let apiConnection: StellarApiConnection;\n let unsafeApi: StellarApi;\n let sorobanApi: SorobanServer;\n const mockBlocks: StellarBlockWrapper[] = [\n {\n block: { sequence: 1, hash: 'hash1' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n {\n block: { sequence: 2, hash: 'hash2' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n ];\n\n const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);\n\n beforeEach(async () => {\n sorobanApi = new SorobanServer(SOROBAN_ENDPOINT);\n unsafeApi = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), sorobanApi);\n await unsafeApi.init();\n apiConnection = new StellarApiConnection(unsafeApi, fetchBlockBatches);\n });\n\n it('creates a connection', async () => {\n expect(\n await StellarApiConnection.create(\n HTTP_ENDPOINT,\n fetchBlockBatches,\n new EventEmitter2(),\n sorobanApi,\n ),\n ).toBeInstanceOf(StellarApiConnection);\n });\n\n it('fetches blocks', async () => {\n const result = await apiConnection.fetchBlocks([1, 2]);\n expect(result).toEqual(mockBlocks);\n expect(fetchBlockBatches).toHaveBeenCalledWith(unsafeApi, [1, 2]);\n });\n\n describe('Error handling', () => {\n it('handles timeout errors', () => {\n const error = new Error('Timeout');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(TimeoutError);\n });\n\n it('handles disconnection errors', () => {\n const error = new Error('disconnected from ');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(DisconnectionError);\n });\n\n it('handles rate limit errors', () => {\n const error = new Error('Rate Limit Exceeded');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(RateLimitError);\n });\n\n it('handles large response errors', () => {\n const error = new Error('limit must not exceed');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(LargeResponseError);\n });\n\n it('handles default errors', () => {\n const error = new Error('default error');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(ApiConnectionError);\n expect(handledError.errorType).toEqual(ApiErrorType.Default);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"api.connection.spec.js","sourceRoot":"","sources":["../../src/stellar/api.connection.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,gDAO0B;AAE1B,qDAAwD;AACxD,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,SAAqB,CAAC;IAC1B,IAAI,UAAyB,CAAC;IAC9B,MAAM,UAAU,GAA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wB,EAAE,GAAG,EAAE;YAChC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;YACzC,MAAM,YAAY,GAAG,qCAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC7D,MAAM,CAAC,YAAY,CAAC,CAAC,cAAc,CAAC,8BAAkB,CAAC,CAAC;YACxD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,wBAAY,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n RateLimitError,\n TimeoutError,\n} from '@subql/node-core';\nimport { StellarBlock, StellarBlockWrapper } from '@subql/types-stellar';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\ndescribe('StellarApiConnection', () => {\n let apiConnection: StellarApiConnection;\n let unsafeApi: StellarApi;\n let sorobanApi: SorobanServer;\n const mockBlocks: StellarBlockWrapper[] = [\n {\n block: { sequence: 1, hash: 'hash1' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n {\n block: { sequence: 2, hash: 'hash2' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n ];\n\n const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);\n\n beforeEach(async () => {\n sorobanApi = new SorobanServer(SOROBAN_ENDPOINT);\n unsafeApi = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), sorobanApi);\n await unsafeApi.init();\n apiConnection = new StellarApiConnection(unsafeApi, fetchBlockBatches);\n });\n\n it('creates a connection', async () => {\n expect(\n await StellarApiConnection.create(\n HTTP_ENDPOINT,\n fetchBlockBatches,\n new EventEmitter2(),\n sorobanApi,\n ),\n ).toBeInstanceOf(StellarApiConnection);\n });\n\n it('fetches blocks', async () => {\n const result = await apiConnection.fetchBlocks([1, 2]);\n expect(result).toEqual(mockBlocks);\n expect(fetchBlockBatches).toHaveBeenCalledWith(unsafeApi, [1, 2]);\n });\n\n describe('Error handling', () => {\n it('handles timeout errors', () => {\n const error = new Error('Timeout');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(TimeoutError);\n });\n\n it('handles disconnection errors', () => {\n const error = new Error('disconnected from ');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(DisconnectionError);\n });\n\n it('handles rate limit errors', () => {\n const error = new Error('Rate Limit Exceeded');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(RateLimitError);\n });\n\n it('handles large response errors', () => {\n const error = new Error('limit must not exceed');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(LargeResponseError);\n });\n\n it('handles default errors', () => {\n const error = new Error('default error');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(ApiConnectionError);\n expect(handledError.errorType).toEqual(ApiErrorType.Default);\n });\n });\n});\n"]}
@@ -54,12 +54,7 @@ let StellarApiService = class StellarApiService extends node_core_1.ApiService {
54
54
  const sorobanClient = sorobanEndpoint
55
55
  ? new soroban_server_1.SorobanServer(sorobanEndpoint)
56
56
  : undefined;
57
- await this.createConnections(network, (endpoint) => api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter, sorobanClient),
58
- //eslint-disable-next-line @typescript-eslint/require-await
59
- async (connection) => {
60
- const api = connection.unsafeApi;
61
- return api.getChainId();
62
- });
57
+ await this.createConnections(network, (endpoint) => api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter, sorobanClient));
63
58
  return this;
64
59
  }
65
60
  get api() {
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AAKtD,gDAM0B;AAE1B,kEAIsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,sBAItC;IACC,YACsC,OAAwB,EAEpD,qBAA4C,EACpD,qBAAkE,EAClE,YAA2B;QAE3B,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QANP,YAAO,GAAP,OAAO,CAAiB;QAEpD,0BAAqB,GAArB,qBAAqB,CAAuB;IAKtD,CAAC;IAED,KAAK,CAAC,IAAI;;QACR,IAAI,OAAoC,CAAC;QACzC,IAAI;YACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;SAChC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,MAAM,eAAe,GACnB,MAAA,OAAO,CAAC,eAAe,mCAErB,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC;aAC3D,OACJ,CAAC,OAAO,CAAC;QAEZ,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,eAAe,EAAE;YAC/C,4CAA4C;YAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,GAAG,eAAe,CAAC;SACxD;QAED,IACE,IAAA,0CAAwB,EAAC;YACvB,G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OAAO,MAAM,cAAc,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;6BACrD;4BAAC,OAAO,KAAK,EAAE;gCACd,MAAM,CAAC,IAAI,CACT,qCAAqC,MAAM,WAAW,OAAO,MAAM,KAAK,CAAC,OAAO,EAAE,CACnF,CAAC;gCACF,aAAa,GAAG,KAAK,CAAC;gCACtB,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gCAC/C,OAAO,EAAE,CAAC;6BACX;yBACF;wBAED,MAAM,CAAC,KAAK,CACV,oBAAoB,UAAU,gCAAgC,MAAM,EAAE,CACvE,CAAC;wBACF,MAAM,aAAa,CAAC;oBACtB,CAAC,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC;QAEF,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,GAAe,EACf,KAAe;QAEf,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAvHY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCADY,iCAAe;QAE7B,iCAAqB;QAC7B,iCAAqB;QAC9B,6BAAa;GAVlB,iBAAiB,CAuH7B;AAvHY,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StellarProjectNetwork,\n StellarProjectNetworkConfig,\n} from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n ProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { StellarBlockWrapper } from '@subql/types-stellar';\nimport {\n StellarProjectDs,\n SubqueryProject,\n dsHasSorobanEventHandler,\n} from '../configure/SubqueryProject';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class StellarApiService extends ApiService<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n> {\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n private projectUpgradeService: ProjectUpgradeService,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) {\n super(connectionPoolService, eventEmitter);\n }\n\n async init(): Promise<StellarApiService> {\n let network: StellarProjectNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const sorobanEndpoint: string | undefined =\n network.sorobanEndpoint ??\n (\n this.projectUpgradeService.getProject(Number.MAX_SAFE_INTEGER)\n .network as StellarProjectNetwork\n ).soroban;\n\n if (!network.sorobanEndpoint && sorobanEndpoint) {\n //update sorobanEndpoint from parent project\n this.project.network.sorobanEndpoint = sorobanEndpoint;\n }\n\n if (\n dsHasSorobanEventHandler([\n ...this.project.dataSources,\n ...(this.project.templates as StellarProjectDs[]),\n ]) &&\n !sorobanEndpoint\n ) {\n throw new Error(\n `Soroban network endpoint must be provided for network. chainId=\"${this.project.network.chainId}\"`,\n );\n }\n\n const sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint)\n : undefined;\n\n await this.createConnections(\n network,\n (endpoint) =>\n StellarApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n this.eventEmitter,\n sorobanClient,\n ),\n //eslint-disable-next-line @typescript-eslint/require-await\n async (connection: StellarApiConnection) => {\n const api = connection.unsafeApi;\n return api.getChainId();\n },\n );\n\n return this;\n }\n\n get api(): StellarApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeStellarProvider {\n const maxRetries = 5;\n\n const handler: ProxyHandler<SafeStellarProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeStellarProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error) {\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchBlockBatches(\n api: StellarApi,\n batch: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n return api.fetchBlocks(batch);\n }\n}\n"]}
1
+ {"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AAKtD,gDAM0B;AAE1B,kEAGsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,sBAItC;IACC,YACsC,OAAwB,EAEpD,qBAA4C,EACpD,qBAAkE,EAClE,YAA2B;QAE3B,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QANP,YAAO,GAAP,OAAO,CAAiB;QAE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;QAEf,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAhHY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;qCADY,iCAAe;QAE7B,iCAAqB;QAC7B,iCAAqB;QAC9B,6BAAa;GAVlB,iBAAiB,CAgH7B;AAhHY,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StellarProjectNetwork,\n StellarProjectNetworkConfig,\n} from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n ProjectUpgradeService,\n IBlock,\n} from '@subql/node-core';\nimport { StellarBlockWrapper, SubqlDatasource } from '@subql/types-stellar';\nimport {\n SubqueryProject,\n dsHasSorobanEventHandler,\n} from '../configure/SubqueryProject';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class StellarApiService extends ApiService<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n> {\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n @Inject('IProjectUpgradeService')\n private projectUpgradeService: ProjectUpgradeService,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) {\n super(connectionPoolService, eventEmitter);\n }\n\n async init(): Promise<StellarApiService> {\n let network: StellarProjectNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n const sorobanEndpoint: string | undefined =\n network.sorobanEndpoint ??\n (\n this.projectUpgradeService.getProject(Number.MAX_SAFE_INTEGER)\n .network as StellarProjectNetwork\n ).soroban;\n\n if (!network.sorobanEndpoint && sorobanEndpoint) {\n //update sorobanEndpoint from parent project\n this.project.network.sorobanEndpoint = sorobanEndpoint;\n }\n\n if (\n dsHasSorobanEventHandler([\n ...this.project.dataSources,\n ...(this.project.templates as SubqlDatasource[]),\n ]) &&\n !sorobanEndpoint\n ) {\n throw new Error(\n `Soroban network endpoint must be provided for network. chainId=\"${this.project.network.chainId}\"`,\n );\n }\n\n const sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint)\n : undefined;\n\n await this.createConnections(network, (endpoint) =>\n StellarApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n this.eventEmitter,\n sorobanClient,\n ),\n );\n\n return this;\n }\n\n get api(): StellarApi {\n return this.unsafeApi;\n }\n\n safeApi(height: number): SafeStellarProvider {\n const maxRetries = 5;\n\n const handler: ProxyHandler<SafeStellarProvider> = {\n get: (target, prop, receiver) => {\n const originalMethod = target[prop as keyof SafeStellarProvider];\n if (typeof originalMethod === 'function') {\n return async (...args: any[]) => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error) {\n logger.warn(\n `Request failed with api at height ${height} (retry ${retries}): ${error.message}`,\n );\n throwingError = error;\n currentApi = this.unsafeApi.getSafeApi(height);\n retries++;\n }\n }\n\n logger.error(\n `Maximum retries (${maxRetries}) exceeded for api at height ${height}`,\n );\n throw throwingError;\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n };\n\n return new Proxy(this.unsafeApi.getSafeApi(height), handler);\n }\n\n private async fetchBlockBatches(\n api: StellarApi,\n batch: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n return api.fetchBlocks(batch);\n }\n}\n"]}
@@ -10,7 +10,6 @@ export declare class StellarApi implements ApiWrapper {
10
10
  private sorobanClient?;
11
11
  private stellarClient;
12
12
  private chainId;
13
- private genesisHash;
14
13
  private name;
15
14
  constructor(endpoint: string, eventEmitter: EventEmitter2, sorobanClient?: SorobanServer);
16
15
  init(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAAqD;AAUrD,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAkD;AAElD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAgB;QAErC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,aAAa,WAAW,EAAE,CAAC,CAAC;QAC7D,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE;YACrD,MAAM,OAAO,GAAmB;gBAC9B,SAAS,EAAE,WAAW,KAAK,MAAM;aAClC,CAAC;YAEF,IAAI,CAAC,aAAa,GAAG,IAAI,8BAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SAC3D;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;SACtD;IACH,CAAC;I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a,CAAC,OAAO,EACrB,aAAa,CAAC,MAAM,CACrB,CAAC;QAEF,OAAO,IAAA,+BAAe,EAAC,qBAAqB,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,WAAW,CACf,YAAsB;QAEtB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,YAAY,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAClE,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,UAAU,CAAC,WAAmB;QAC5B,8BAA8B;QAC9B,OAAO,IAAI,kBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,WAAW,CAAC,CAAQ,EAAE,MAAc;QAClC,IAAI,CAAC,CAAC,OAAO,KAAK,+BAA+B,EAAE;YACjD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;SAC/E;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA9XD,gCA8XC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private genesisHash: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return formatBlockUtil(wrappedLedgerInstance);\n }\n\n async fetchBlocks(\n bufferBlocks: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
1
+ {"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[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GAAG,CAC/B,YAAY,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAClE,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,UAAU,CAAC,WAAmB;QAC5B,8BAA8B;QAC9B,OAAO,IAAI,kBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,WAAW,CAAC,CAAQ,EAAE,MAAc;QAClC,IAAI,CAAC,CAAC,OAAO,KAAK,+BAA+B,EAAE;YACjD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;SAC/E;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA7XD,gCA6XC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return formatBlockUtil(wrappedLedgerInstance);\n }\n\n async fetchBlocks(\n bufferBlocks: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- const eventemitter2_1 = require("eventemitter2");
5
+ const event_emitter_1 = require("@nestjs/event-emitter");
6
6
  const api_stellar_1 = require("./api.stellar");
7
7
  const soroban_server_1 = require("./soroban.server");
8
8
  const HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';
@@ -10,7 +10,7 @@ const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
10
10
  jest.setTimeout(60000);
11
11
  const prepareStellarApi = async function () {
12
12
  const soroban = new soroban_server_1.SorobanServer(SOROBAN_ENDPOINT);
13
- const api = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new eventemitter2_1.EventEmitter2(), soroban);
13
+ const api = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new event_emitter_1.EventEmitter2(), soroban);
14
14
  await api.init();
15
15
  return api;
16
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,iDAA8C;AAC9C,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,wBAAU,CAAC,aAAa,EAAE,IAAI,6BAAa,EAAE,EAAE,OAAO,CAAC,CAAC;IACxE,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,UAAsB,CAAC;IAE3B,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,UAAU,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CACrC,wC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C;IAEH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACxD,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YACzC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACF,UAAkB,CAAC,wBAAwB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC;YACtE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;SACrD,CAAC,CAAC;QACH,MAAM,MAAM,CAAE,UAAkB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACvE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.getHeader().blockHeight).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).name);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n\n it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /Not Found/,\n );\n });\n});\n"]}
1
+ {"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,+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AAC,CAAC,OAAO,CAAC,OAAO,CACvE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.getHeader().blockHeight).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).name);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n\n it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /Not Found/,\n );\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AASnC,SAAgB,aAAa,CAAC,WAAmB;IAC/C,OAAO;QACL,WAAW,EAAE,WAAW;QACxB,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE;QACjC,UAAU,EAAE,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;KACzC,CAAC;AACJ,CAAC;AAND,sCAMC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;KACrD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function blockToHeader(blockHeight: number): Header {\n return {\n blockHeight: blockHeight,\n blockHash: blockHeight.toString(),\n parentHash: (blockHeight - 1).toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => blockToHeader(block.block.sequence),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n"]}
1
+ {"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAKnC,SAAgB,aAAa,CAAC,WAAmB;IAC/C,OAAO;QACL,WAAW,EAAE,WAAW;QACxB,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE;QACjC,UAAU,EAAE,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;KACzC,CAAC;AACJ,CAAC;AAND,sCAMC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;KACrD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Header, IBlock } from '@subql/node-core';\nimport { ApiWrapper, StellarBlockWrapper } from '@subql/types-stellar';\n\nexport function blockToHeader(blockHeight: number): Header {\n return {\n blockHeight: blockHeight,\n blockHash: blockHeight.toString(),\n parentHash: (blockHeight - 1).toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => blockToHeader(block.block.sequence),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n"]}
@@ -1 +1 @@
1
- export declare function forceCleanInit(): Promise<void>;
1
+ export declare const forceCleanInit: () => Promise<void>;
@@ -3,22 +3,8 @@
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.forceCleanInit = void 0;
6
- const core_1 = require("@nestjs/core");
7
6
  const node_core_1 = require("@subql/node-core");
8
7
  const forceClean_module_1 = require("./forceClean.module");
9
- const logger = (0, node_core_1.getLogger)('CLI');
10
- async function forceCleanInit() {
11
- try {
12
- const app = await core_1.NestFactory.create(forceClean_module_1.ForceCleanModule);
13
- await app.init();
14
- const forceCleanService = app.get(node_core_1.ForceCleanService);
15
- await forceCleanService.forceClean();
16
- }
17
- catch (e) {
18
- logger.error(e, 'Force-clean failed to execute');
19
- process.exit(1);
20
- }
21
- process.exit(0);
22
- }
8
+ const forceCleanInit = () => (0, node_core_1.forceClean)(forceClean_module_1.ForceCleanModule);
23
9
  exports.forceCleanInit = forceCleanInit;
24
10
  //# sourceMappingURL=forceClean.init.js.map