@subql/node-stellar 4.5.1-0 → 4.5.1-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 (90) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/app.module.js +19 -9
  4. package/dist/app.module.js.map +1 -1
  5. package/dist/blockchain.service.d.ts +30 -0
  6. package/dist/blockchain.service.js +113 -0
  7. package/dist/blockchain.service.js.map +1 -0
  8. package/dist/blockchain.service.spec.d.ts +1 -0
  9. package/dist/blockchain.service.spec.js +33 -0
  10. package/dist/blockchain.service.spec.js.map +1 -0
  11. package/dist/configure/SubqueryProject.js +2 -3
  12. package/dist/configure/SubqueryProject.js.map +1 -1
  13. package/dist/configure/configure.module.js +2 -2
  14. package/dist/configure/configure.module.js.map +1 -1
  15. package/dist/indexer/dictionary/stellarDictionary.service.d.ts +1 -2
  16. package/dist/indexer/dictionary/stellarDictionary.service.js +3 -4
  17. package/dist/indexer/dictionary/stellarDictionary.service.js.map +1 -1
  18. package/dist/indexer/dictionary/v1/stellarDictionaryV1.d.ts +1 -2
  19. package/dist/indexer/dictionary/v1/stellarDictionaryV1.js +2 -2
  20. package/dist/indexer/dictionary/v1/stellarDictionaryV1.js.map +1 -1
  21. package/dist/indexer/fetch.module.js +30 -27
  22. package/dist/indexer/fetch.module.js.map +1 -1
  23. package/dist/indexer/indexer.manager.d.ts +3 -8
  24. package/dist/indexer/indexer.manager.js +12 -19
  25. package/dist/indexer/indexer.manager.js.map +1 -1
  26. package/dist/indexer/types.js +1 -2
  27. package/dist/indexer/types.js.map +1 -1
  28. package/dist/indexer/worker/worker-fetch.module.js +10 -32
  29. package/dist/indexer/worker/worker-fetch.module.js.map +1 -1
  30. package/dist/indexer/worker/worker.js.map +1 -1
  31. package/dist/indexer/worker/worker.module.js +2 -2
  32. package/dist/indexer/worker/worker.module.js.map +1 -1
  33. package/dist/indexer/worker/worker.service.js +3 -2
  34. package/dist/indexer/worker/worker.service.js.map +1 -1
  35. package/dist/init.js +2 -4
  36. package/dist/init.js.map +1 -1
  37. package/dist/main.js.map +1 -1
  38. package/dist/stellar/api.connection.js.map +1 -1
  39. package/dist/stellar/api.service.stellar.d.ts +2 -4
  40. package/dist/stellar/api.service.stellar.js +19 -25
  41. package/dist/stellar/api.service.stellar.js.map +1 -1
  42. package/dist/stellar/api.service.stellar.spec.js +10 -2
  43. package/dist/stellar/api.service.stellar.spec.js.map +1 -1
  44. package/dist/stellar/api.stellar.js.map +1 -1
  45. package/dist/stellar/block.stellar.js.map +1 -1
  46. package/dist/stellar/soroban.server.js.map +1 -1
  47. package/dist/stellar/utils.stellar.js +11 -6
  48. package/dist/stellar/utils.stellar.js.map +1 -1
  49. package/dist/subcommands/forceClean.module.js +2 -2
  50. package/dist/subcommands/forceClean.module.js.map +1 -1
  51. package/dist/subcommands/reindex.module.js +15 -17
  52. package/dist/subcommands/reindex.module.js.map +1 -1
  53. package/dist/subcommands/testing.init.js +1 -2
  54. package/dist/subcommands/testing.init.js.map +1 -1
  55. package/dist/subcommands/testing.module.js +18 -38
  56. package/dist/subcommands/testing.module.js.map +1 -1
  57. package/dist/subcommands/testing.service.js +2 -2
  58. package/dist/subcommands/testing.service.js.map +1 -1
  59. package/dist/utils/project.js +3 -4
  60. package/dist/utils/project.js.map +1 -1
  61. package/dist/utils/string.js +1 -2
  62. package/dist/utils/string.js.map +1 -1
  63. package/package.json +14 -17
  64. package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +0 -15
  65. package/dist/indexer/blockDispatcher/block-dispatcher.service.js +0 -51
  66. package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +0 -1
  67. package/dist/indexer/blockDispatcher/index.d.ts +0 -4
  68. package/dist/indexer/blockDispatcher/index.js +0 -10
  69. package/dist/indexer/blockDispatcher/index.js.map +0 -1
  70. package/dist/indexer/blockDispatcher/stellar-block-dispatcher.d.ts +0 -5
  71. package/dist/indexer/blockDispatcher/stellar-block-dispatcher.js +0 -5
  72. package/dist/indexer/blockDispatcher/stellar-block-dispatcher.js.map +0 -1
  73. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +0 -17
  74. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +0 -49
  75. package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +0 -1
  76. package/dist/indexer/ds-processor.service.d.ts +0 -5
  77. package/dist/indexer/ds-processor.service.js +0 -22
  78. package/dist/indexer/ds-processor.service.js.map +0 -1
  79. package/dist/indexer/dynamic-ds.service.d.ts +0 -9
  80. package/dist/indexer/dynamic-ds.service.js +0 -69
  81. package/dist/indexer/dynamic-ds.service.js.map +0 -1
  82. package/dist/indexer/fetch.service.d.ts +0 -21
  83. package/dist/indexer/fetch.service.js +0 -77
  84. package/dist/indexer/fetch.service.js.map +0 -1
  85. package/dist/indexer/project.service.d.ts +0 -17
  86. package/dist/indexer/project.service.js +0 -73
  87. package/dist/indexer/project.service.js.map +0 -1
  88. package/dist/indexer/unfinalizedBlocks.service.d.ts +0 -9
  89. package/dist/indexer/unfinalizedBlocks.service.js +0 -65
  90. package/dist/indexer/unfinalizedBlocks.service.js.map +0 -1
@@ -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;AAEtD,gDAO0B;AAO1B,kEAGsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,sBAMtC;IAGuC;IAF9B,UAAU,CAAa;IAC/B,YACsC,OAAwB,EAC5D,qBAAkE,EAClE,YAA2B,EAC3B,UAAsB;QAEtB,KAAK,CAAC,qBAAqB,EAAE,YAAY,C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CAAgC,MAAM,EAAE,CACvE,CAAC;wBACF,IAAI,CAAC,aAAa,EAAE;4BAClB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;yBACnE;wBACD,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;AA5HY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;6CACJ,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAZb,iBAAiB,CA4H7B;AA5HY,8CAAiB","sourcesContent":["// Copyright 2020-2025 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 { StellarProjectNetworkConfig } from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n IBlock,\n exitWithError,\n NodeConfig,\n} from '@subql/node-core';\nimport { IEndpointConfig } from '@subql/types-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n IStellarEndpointConfig,\n} 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 StellarApiConnection,\n IStellarEndpointConfig\n> {\n private nodeConfig: NodeConfig;\n constructor(\n @Inject('ISubqueryProject') private project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) {\n super(connectionPoolService, eventEmitter);\n this.nodeConfig = nodeConfig;\n }\n\n async init(): Promise<StellarApiService> {\n let network: StellarProjectNetworkConfig;\n try {\n network = this.project.network;\n } catch (e) {\n exitWithError(new Error(`Failed to init api`, { cause: e }), logger);\n }\n\n if (this.nodeConfig.primaryNetworkEndpoint) {\n const [endpoint, config] = this.nodeConfig.primaryNetworkEndpoint;\n (network.endpoint as Record<string, IEndpointConfig>)[endpoint] = config;\n }\n\n const sorobanEndpoint: string | undefined = network.sorobanEndpoint;\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 { protocol } = new URL(sorobanEndpoint);\n const protocolStr = protocol.replace(':', '');\n\n const sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint, {\n allowHttp: protocolStr === 'http',\n })\n : undefined;\n\n await this.createConnections(network, (endpoint, config) =>\n StellarApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n sorobanClient,\n config,\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 (\n ...args: any[]\n ): Promise<ReturnType<typeof originalMethod>> => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error | undefined;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\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 if (!throwingError) {\n throw new Error('Failed to make request, maximum retries failed');\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;AAEtD,gDAO0B;AAO1B,kEAGsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,yBAAvB,MAAM,iBAAkB,SAAQ,sBAMtC;IACC,YACE,qBAAkE,EAClE,YAA2B;QAE3B,KAAK,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,OAAwB,EACxB,qBAAkE,EAClE,YAA2B,EAC3B,UAAsB;QAEtB,IAAI,OAAoC,CAAC;QAEzC,MAAM,UAAU,GAAG,IAAI,mBAAiB,CACtC,qBAAqB,EACrB,YAAY,CACb,CAAC;QAEF,IAAI,CAAC;YACH,OA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DAAgD,CAAC,CAAC;wBACpE,CAAC;wBACD,MAAM,aAAa,CAAC;oBACtB,CAAC,CAAC;gBACJ,CAAC;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;AApIY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCASc,iCAAqB;QAC9B,6BAAa;GATlB,iBAAiB,CAoI7B","sourcesContent":["// Copyright 2020-2025 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 { StellarProjectNetworkConfig } from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n IBlock,\n exitWithError,\n NodeConfig,\n} from '@subql/node-core';\nimport { IEndpointConfig } from '@subql/types-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n IStellarEndpointConfig,\n} 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 StellarApiConnection,\n IStellarEndpointConfig\n> {\n private constructor(\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n ) {\n super(connectionPoolService, eventEmitter);\n }\n\n static async create(\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ): Promise<StellarApiService> {\n let network: StellarProjectNetworkConfig;\n\n const apiService = new StellarApiService(\n connectionPoolService,\n eventEmitter,\n );\n\n try {\n network = project.network;\n } catch (e) {\n exitWithError(new Error(`Failed to init api`, { cause: e }), logger);\n }\n\n if (nodeConfig.primaryNetworkEndpoint) {\n const [endpoint, config] = nodeConfig.primaryNetworkEndpoint;\n (network.endpoint as Record<string, IEndpointConfig>)[endpoint] = config;\n }\n\n const sorobanEndpoint: string | undefined = network.sorobanEndpoint;\n\n if (!network.sorobanEndpoint && sorobanEndpoint) {\n //update sorobanEndpoint from parent project\n project.network.sorobanEndpoint = sorobanEndpoint;\n }\n\n // TOOD if project upgrades introduces new datasoruces this wont work\n if (\n dsHasSorobanEventHandler([\n ...project.dataSources,\n ...(project.templates as SubqlDatasource[]),\n ]) &&\n !sorobanEndpoint\n ) {\n throw new Error(\n `Soroban network endpoint must be provided for network. chainId=\"${project.network.chainId}\"`,\n );\n }\n\n const { protocol } = new URL(sorobanEndpoint);\n const protocolStr = protocol.replace(':', '');\n\n const sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint, {\n allowHttp: protocolStr === 'http',\n })\n : undefined;\n\n await apiService.createConnections(network, (endpoint, config) =>\n StellarApiConnection.create(\n endpoint,\n apiService.fetchBlockBatches.bind(apiService),\n sorobanClient,\n config,\n ),\n );\n\n return apiService;\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 (\n ...args: any[]\n ): Promise<ReturnType<typeof originalMethod>> => {\n let retries = 0;\n let currentApi = target;\n let throwingError: Error | undefined;\n\n while (retries < maxRetries) {\n try {\n return await originalMethod.apply(currentApi, args);\n } catch (error: any) {\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 if (!throwingError) {\n throw new Error('Failed to make request, maximum retries failed');\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"]}
@@ -44,14 +44,22 @@ const prepareApiService = async (endpoint = HTTP_ENDPOINT, soroban = SOROBAN_END
44
44
  provide: 'ISubqueryProject',
45
45
  useFactory: () => project ?? testSubqueryProject(endpoint, soroban),
46
46
  },
47
- api_service_stellar_1.StellarApiService,
47
+ {
48
+ provide: api_service_stellar_1.StellarApiService,
49
+ useFactory: api_service_stellar_1.StellarApiService.create.bind(api_service_stellar_1.StellarApiService),
50
+ inject: [
51
+ 'ISubqueryProject',
52
+ node_core_1.ConnectionPoolService,
53
+ event_emitter_1.EventEmitter2,
54
+ node_core_1.NodeConfig,
55
+ ],
56
+ },
48
57
  ],
49
58
  imports: [event_emitter_1.EventEmitterModule.forRoot()],
50
59
  }).compile();
51
60
  const app = module.createNestApplication();
52
61
  await app.init();
53
62
  const apiService = app.get(api_service_stellar_1.StellarApiService);
54
- await apiService.init();
55
63
  return [apiService, app];
56
64
  };
57
65
  jest.setTimeout(90000);
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC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ifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport { scValToNative } from '@stellar/stellar-sdk';\nimport { ConnectionPoolService, NodeConfig } from '@subql/node-core';\nimport { ConnectionPoolStateManager } from '@subql/node-core/dist';\nimport { GraphQLSchema } from 'graphql';\nimport { range } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiService } from './api.service.stellar';\nimport { StellarApi } from './api.stellar';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\nfunction testSubqueryProject(\n endpoint: string,\n sorobanEndpoint: string,\n): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Future Network ; October 2022',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n soroban: string = SOROBAN_ENDPOINT,\n project?: SubqueryProject,\n): Promise<[StellarApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: 'IProjectUpgradeService',\n useFactory: () => ({}),\n },\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => project ?? testSubqueryProject(endpoint, soroban),\n },\n StellarApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(StellarApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n it('should allow http protocol for soroban endpoint', async () => {\n await expect(\n prepareApiService(HTTP_ENDPOINT, 'http://rpc-futurenet.stellar.org'),\n ).resolves.not.toThrow();\n });\n\n it('should instantiate api', () => {\n expect(apiService.api).toBeInstanceOf(StellarApi);\n });\n\n it('should fetch blocks', async () => {\n const latestHeight = await apiService.api.getFinalizedBlockHeight();\n const blocks = await apiService.fetchBlocks(\n range(latestHeight - 1, latestHeight),\n );\n expect(blocks).toBeDefined();\n expect(blocks[0].block.block.sequence).toEqual(latestHeight - 1);\n });\n\n it('should throw error when chainId does not match', async () => {\n const faultyProject = {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT),\n network: {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT).network,\n chainId: 'Incorrect ChainId',\n },\n };\n\n await expect(\n prepareApiService(\n HTTP_ENDPOINT,\n SOROBAN_ENDPOINT,\n faultyProject as unknown as SubqueryProject,\n ),\n ).rejects.toThrow();\n });\n\n it('fails after maximum retries', async () => {\n const api = apiService.unsafeApi;\n\n // Mock the fetchBlocks method to always throw an error\n (api as any).fetchBlocks = jest\n .fn()\n .mockRejectedValue(new Error('Network error'));\n\n await expect(\n (api as any).fetchBlocks(range(50000, 50100)),\n ).rejects.toThrow();\n });\n});\n\n// Skip test as rpc is pruned and block can be missing,\n// To test this, find any block with transfer event first\ndescribe.skip('testnet StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n function testSubqueryProject2(\n endpoint: string,\n sorobanEndpoint: string,\n ): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Network ; September 2015',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n }\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n testSubqueryProject2(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n ),\n );\n });\n\n it('should fetch blocks, and decode address', async () => {\n const blocks = await apiService.fetchBlocks([228236]);\n expect(blocks).toBeDefined();\n\n const block228236 = blocks[0];\n const transferEvent = block228236.block.events?.find(\n (e) => e.id === '0000980266155778048-0000000001',\n );\n\n const [sys, from, to] = transferEvent!.topic;\n const decodedFrom = scValToNative(from).toString();\n const decodedTo = scValToNative(to).toString();\n\n console.log(scValToNative(sys));\n console.log(decodedFrom);\n console.log(decodedTo);\n });\n});\n"]}
1
+ {"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA0E;AAC1E,6CAAuC;AACvC,sDAAqD;AACrD,gDAAqE;AACrE,gDAAmE;AACnE,qCAAwC;AACxC,mCAA+B;AAE/B,+DAA0D;AAC1D,+CAA2C;AAE3C,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,eAAuB;IAEvB,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,eAAe;YACf,OAAO,EAAE,wCAAwC;SAClD;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACgB,CAAC;AAClC,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EAChC,UAAkB,gBAAgB,EAClC,OAAyB,EACuB,EAAE;IAClD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,iCAA0B;YAC1B;gBACE,OAAO,EAAE,wBAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE,CA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CAAC,EAAE,KAAK,gCAAgC,CACjD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,aAAc,CAAC,KAAK,CAAC;QAC7C,MAAM,WAAW,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QACnD,MAAM,SAAS,GAAG,IAAA,2BAAa,EAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QAE/C,OAAO,CAAC,GAAG,CAAC,IAAA,2BAAa,EAAC,GAAG,CAAC,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport { scValToNative } from '@stellar/stellar-sdk';\nimport { ConnectionPoolService, NodeConfig } from '@subql/node-core';\nimport { ConnectionPoolStateManager } from '@subql/node-core/dist';\nimport { GraphQLSchema } from 'graphql';\nimport { range } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiService } from './api.service.stellar';\nimport { StellarApi } from './api.stellar';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\nfunction testSubqueryProject(\n endpoint: string,\n sorobanEndpoint: string,\n): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Future Network ; October 2022',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n soroban: string = SOROBAN_ENDPOINT,\n project?: SubqueryProject,\n): Promise<[StellarApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: 'IProjectUpgradeService',\n useFactory: () => ({}),\n },\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => project ?? testSubqueryProject(endpoint, soroban),\n },\n {\n provide: StellarApiService,\n useFactory: StellarApiService.create.bind(StellarApiService),\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(StellarApiService);\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n it('should allow http protocol for soroban endpoint', async () => {\n await expect(\n prepareApiService(HTTP_ENDPOINT, 'http://rpc-futurenet.stellar.org'),\n ).resolves.not.toThrow();\n });\n\n it('should instantiate api', () => {\n expect(apiService.api).toBeInstanceOf(StellarApi);\n });\n\n it('should fetch blocks', async () => {\n const latestHeight = await apiService.api.getFinalizedBlockHeight();\n const blocks = await apiService.fetchBlocks(\n range(latestHeight - 1, latestHeight),\n );\n expect(blocks).toBeDefined();\n expect(blocks[0].block.block.sequence).toEqual(latestHeight - 1);\n });\n\n it('should throw error when chainId does not match', async () => {\n const faultyProject = {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT),\n network: {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT).network,\n chainId: 'Incorrect ChainId',\n },\n };\n\n await expect(\n prepareApiService(\n HTTP_ENDPOINT,\n SOROBAN_ENDPOINT,\n faultyProject as unknown as SubqueryProject,\n ),\n ).rejects.toThrow();\n });\n\n it('fails after maximum retries', async () => {\n const api = apiService.unsafeApi;\n\n // Mock the fetchBlocks method to always throw an error\n (api as any).fetchBlocks = jest\n .fn()\n .mockRejectedValue(new Error('Network error'));\n\n await expect(\n (api as any).fetchBlocks(range(50000, 50100)),\n ).rejects.toThrow();\n });\n});\n\n// Skip test as rpc is pruned and block can be missing,\n// To test this, find any block with transfer event first\ndescribe.skip('testnet StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n function testSubqueryProject2(\n endpoint: string,\n sorobanEndpoint: string,\n ): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Network ; September 2015',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n }\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n testSubqueryProject2(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n ),\n );\n });\n\n it('should fetch blocks, and decode address', async () => {\n const blocks = await apiService.fetchBlocks([228236]);\n expect(blocks).toBeDefined();\n\n const block228236 = blocks[0];\n const transferEvent = block228236.block.events?.find(\n (e) => e.id === '0000980266155778048-0000000001',\n );\n\n const [sys, from, to] = transferEvent!.topic;\n const decodedFrom = scValToNative(from).toString();\n const decodedTo = scValToNative(to).toString();\n\n console.log(scValToNative(sys));\n console.log(decodedFrom);\n console.log(decodedTo);\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAE5B,gDAAqD;AAWrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,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EACxB,aAAa,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,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAClE,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;AA9YD,gCA8YC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { DEFAULT_PAGE_SIZE, formatBlockUtil } from './utils.stellar';\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 pageLimit = DEFAULT_PAGE_SIZE;\n\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n this.pageLimit = config?.pageLimit || this.pageLimit;\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(\n `Api host: ${hostname}, method: ${protocolStr}, pageLimit: ${this.pageLimit}`,\n );\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Horizon.Server.Options = {\n allowHttp: protocolStr === 'http',\n headers: {\n ...config?.headers,\n },\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 get sorobanClient(): SorobanServer {\n assert(this._sorobanClient, 'Soraban client is not initialized');\n return this._sorobanClient;\n }\n\n async getFinalizedBlock(): Promise<Horizon.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 assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getChainId(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.TransactionRecord[]> {\n const txs: Horizon.ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api\n .transactions()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api\n .operations()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api\n .effects()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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 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 limit: this.pageLimit,\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: Horizon.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 operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n const events = eventsForSequence.filter(\n (evt) => evt.txHash === transactionId,\n );\n\n // If there are soroban events then there should only be a single operation.\n // This check is here in case there are furture changes to the network.\n assert(\n events.length > 0 ? operations.length === 1 : true,\n 'Unable to assign events to multiple operations',\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\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: Horizon.ServerApi.TransactionRecord[],\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx) => {\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 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: any) {\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 Horizon.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(): Horizon.Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(this.sorobanClient, 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":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAE5B,gDAAqD;AAWrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQX;IACA;IARV,yBAAyB;IACjB,aAAa,CAAgB;IAE7B,OAAO,CAAU;IACjB,SAAS,GAAG,iCAAiB,CAAC;IAEtC,YACU,QAAgB,EAChB,cAA8B,EACtC,MAA+B;QAFvB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,mBAAc,GAAd,cAAc,CAAgB;QAGtC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;QAErD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CACT,aAAa,QAAQ,aAAa,WAAW,gBAAgB,IAAI,CAAC,SAAS,EAAE,CAC9E,CAAC;QACF,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YACtD,MAAM,OAAO,GAA2B;gBACtC,SAAS,EAAE,WAAW,KAAK,MAAM;gBACjC,OAAO,EAAE;oBACP,GAAG,MAAM,EAAE,OAAO;iBACnB;aACF,CAAC;YAEF,IAAI,CAA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;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,CAAC;YAClD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA9YD,gCA8YC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { DEFAULT_PAGE_SIZE, formatBlockUtil } from './utils.stellar';\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 pageLimit = DEFAULT_PAGE_SIZE;\n\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n this.pageLimit = config?.pageLimit || this.pageLimit;\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(\n `Api host: ${hostname}, method: ${protocolStr}, pageLimit: ${this.pageLimit}`,\n );\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Horizon.Server.Options = {\n allowHttp: protocolStr === 'http',\n headers: {\n ...config?.headers,\n },\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 get sorobanClient(): SorobanServer {\n assert(this._sorobanClient, 'Soraban client is not initialized');\n return this._sorobanClient;\n }\n\n async getFinalizedBlock(): Promise<Horizon.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 assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getChainId(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.TransactionRecord[]> {\n const txs: Horizon.ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api\n .transactions()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api\n .operations()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api\n .effects()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .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 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 limit: this.pageLimit,\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: Horizon.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 operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n const events = eventsForSequence.filter(\n (evt) => evt.txHash === transactionId,\n );\n\n // If there are soroban events then there should only be a single operation.\n // This check is here in case there are furture changes to the network.\n assert(\n events.length > 0 ? operations.length === 1 : true,\n 'Unable to assign events to multiple operations',\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\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: Horizon.ServerApi.TransactionRecord[],\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx) => {\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 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: any) {\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 Horizon.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(): Horizon.Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(this.sorobanClient, 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 +1 @@
1
- {"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,sDAAqD;AACrD,gDAAwD;AAexD,4CAAqD;AAErD,MAAa,mBAAmB;IAEpB;IACA;IACA;IACA;IACA;IALV,YACU,MAAoB,EACpB,aAAmC,EACnC,WAA+B,EAC/B,QAAyB,EACzB,OAAuB;QAJvB,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAAsB;QACnC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,aAAQ,GAAR,QAAQ,CAAiB;QACzB,YAAO,GAAP,OAAO,CAAgB;IAC9B,CAAC;IAEJ,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC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AAK,IAAA,2BAAa,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;oBAC3C,OAAO,KAAK,CAAC;iBACd;aACF;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjID,kDAiIC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { scValToNative } from '@stellar/stellar-sdk';\nimport { filterBlockTimestamp } from '@subql/node-core';\nimport {\n StellarBlock,\n StellarBlockFilter,\n StellarBlockWrapper,\n StellarEffect,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n StellarOperation,\n StellarOperationFilter,\n StellarTransaction,\n StellarTransactionFilter,\n} from '@subql/types-stellar';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { stringNormalizedEq } from '../utils/string';\n\nexport class StellarBlockWrapped implements StellarBlockWrapper {\n constructor(\n private _block: StellarBlock,\n private _transactions: StellarTransaction[],\n private _operations: StellarOperation[],\n private _effects: StellarEffect[],\n private _events: SorobanEvent[],\n ) {}\n\n get block(): StellarBlock {\n return this._block;\n }\n\n get transactions(): StellarTransaction[] {\n return this._transactions;\n }\n\n get operations(): StellarOperation[] {\n return this._operations;\n }\n\n get effects(): StellarEffect[] {\n return this._effects;\n }\n\n get events(): SorobanEvent[] {\n return this._events;\n }\n\n static filterBlocksProcessor(\n block: StellarBlock,\n filter: StellarBlockFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter?.modulo && block.sequence % filter.modulo !== 0) {\n return false;\n }\n if (\n !filterBlockTimestamp(\n new Date(block.closed_at).getTime(),\n filter as SubqlProjectBlockFilter,\n )\n ) {\n return false;\n }\n return true;\n }\n\n static filterTransactionProcessor(\n tx: StellarTransaction,\n filter: StellarTransactionFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== (tx as any).source_account) {\n return false;\n }\n\n return true;\n }\n\n static filterOperationProcessor(\n op: StellarOperation,\n filter: StellarOperationFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.sourceAccount && filter.sourceAccount !== op.source_account) {\n return false;\n }\n if (filter.type && filter.type !== op.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEffectProcessor(\n effect: StellarEffect,\n filter: StellarEffectFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== effect.account) {\n return false;\n }\n if (filter.type && filter.type !== effect.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEventProcessor(\n event: SorobanEvent,\n filter: SorobanEventFilter,\n address?: string,\n ): boolean {\n if (address && !stringNormalizedEq(address, event.contractId?.toString())) {\n return false;\n }\n\n if (!filter) return true;\n\n if (\n filter.contractId &&\n filter.contractId !== event.contractId?.toString()\n ) {\n return false;\n }\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!event.topic[i]) {\n return false;\n }\n if (topic !== scValToNative(event.topic[i])) {\n return false;\n }\n }\n }\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,sDAAqD;AACrD,gDAAwD;AAexD,4CAAqD;AAErD,MAAa,mBAAmB;IAEpB;IACA;IACA;IACA;IACA;IALV,YACU,MAAoB,EACpB,aAAmC,EACnC,WAA+B,EAC/B,QAAyB,EACzB,OAAuB;QAJvB,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAAsB;QACnC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,aAAQ,GAAR,QAAQ,CAAiB;QACzB,YAAO,GAAP,OAAO,CAAgB;IAC9B,CAAC;IAEJ,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,YAAY;QACd,O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K,EAAE,CAAC;oBACX,SAAS;gBACX,CAAC;gBAED,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBACpB,OAAO,KAAK,CAAC;gBACf,CAAC;gBACD,IAAI,KAAK,KAAK,IAAA,2BAAa,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5C,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjID,kDAiIC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { scValToNative } from '@stellar/stellar-sdk';\nimport { filterBlockTimestamp } from '@subql/node-core';\nimport {\n StellarBlock,\n StellarBlockFilter,\n StellarBlockWrapper,\n StellarEffect,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n StellarOperation,\n StellarOperationFilter,\n StellarTransaction,\n StellarTransactionFilter,\n} from '@subql/types-stellar';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { stringNormalizedEq } from '../utils/string';\n\nexport class StellarBlockWrapped implements StellarBlockWrapper {\n constructor(\n private _block: StellarBlock,\n private _transactions: StellarTransaction[],\n private _operations: StellarOperation[],\n private _effects: StellarEffect[],\n private _events: SorobanEvent[],\n ) {}\n\n get block(): StellarBlock {\n return this._block;\n }\n\n get transactions(): StellarTransaction[] {\n return this._transactions;\n }\n\n get operations(): StellarOperation[] {\n return this._operations;\n }\n\n get effects(): StellarEffect[] {\n return this._effects;\n }\n\n get events(): SorobanEvent[] {\n return this._events;\n }\n\n static filterBlocksProcessor(\n block: StellarBlock,\n filter: StellarBlockFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter?.modulo && block.sequence % filter.modulo !== 0) {\n return false;\n }\n if (\n !filterBlockTimestamp(\n new Date(block.closed_at).getTime(),\n filter as SubqlProjectBlockFilter,\n )\n ) {\n return false;\n }\n return true;\n }\n\n static filterTransactionProcessor(\n tx: StellarTransaction,\n filter: StellarTransactionFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== (tx as any).source_account) {\n return false;\n }\n\n return true;\n }\n\n static filterOperationProcessor(\n op: StellarOperation,\n filter: StellarOperationFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.sourceAccount && filter.sourceAccount !== op.source_account) {\n return false;\n }\n if (filter.type && filter.type !== op.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEffectProcessor(\n effect: StellarEffect,\n filter: StellarEffectFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== effect.account) {\n return false;\n }\n if (filter.type && filter.type !== effect.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEventProcessor(\n event: SorobanEvent,\n filter: SorobanEventFilter,\n address?: string,\n ): boolean {\n if (address && !stringNormalizedEq(address, event.contractId?.toString())) {\n return false;\n }\n\n if (!filter) return true;\n\n if (\n filter.contractId &&\n filter.contractId !== event.contractId?.toString()\n ) {\n return false;\n }\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!event.topic[i]) {\n return false;\n }\n if (topic !== scValToNative(event.topic[i])) {\n return false;\n }\n }\n }\n return true;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,sDAA2C;AAE3C,mCAAgD;AAChD,mDAAoD;AAOpD,MAAa,aAAc,SAAQ,iBAAG,CAAC,MAAM;IACnC,WAAW,GAAiD,EAAE,CAAC;IAE/D,KAAK,CAAC,sBAAsB,CAClC,QAAgB,EAChB,OAAoC,EACpC,YAAuC,EAAE;QAKzC,MAAM,SAAS,GAAG,OAAO,C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AI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;SACxE;QAED,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;YAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC;SACrB;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAExD,OAAO,QAAQ,CAAC,MAAmC,CAAC;IACtD,CAAC;CACF;AApGD,sCAoGC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { rpc } from '@stellar/stellar-sdk';\nimport { SorobanRpcEventResponse } from '@subql/types-stellar';\nimport { compact, groupBy, last } from 'lodash';\nimport { DEFAULT_PAGE_SIZE } from './utils.stellar';\n\ntype CachedEventsResponse = Pick<\n rpc.Api.GetEventsResponse,\n 'events' | 'latestLedger'\n>;\n\nexport class SorobanServer extends rpc.Server {\n private eventsCache: { [key: number]: rpc.Api.GetEventsResponse } = {};\n\n private async fetchEventsForSequence(\n sequence: number,\n request: rpc.Server.GetEventsRequest,\n accEvents: SorobanRpcEventResponse[] = [],\n ): Promise<{\n events: CachedEventsResponse;\n eventsToCache: CachedEventsResponse;\n }> {\n const pageLimit = request.limit ?? DEFAULT_PAGE_SIZE;\n const response = await super.getEvents(request);\n\n // Separate the events for the current sequence and the subsequent sequences\n const groupedEvents = groupBy(response.events, (event) =>\n event.ledger === sequence ? 'events' : 'eventsToCache',\n );\n const events = compact(groupedEvents.events);\n let eventsToCache = compact(groupedEvents.eventsToCache);\n\n // Update the accumulated events with the events from the current sequence\n const newEvents = accEvents.concat(events);\n\n if (eventsToCache?.length) {\n if (response.events.length === pageLimit) {\n const lastSequence = last(response.events)!.ledger;\n eventsToCache = eventsToCache.filter(\n (event) => event.ledger !== lastSequence,\n );\n }\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: {\n events: eventsToCache,\n latestLedger: response.latestLedger,\n },\n };\n }\n\n if (response.events.length < pageLimit) {\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: { events: [], latestLedger: response.latestLedger },\n };\n }\n\n // Prepare the next request\n const nextRequest = {\n ...request,\n cursor: response.events[response.events.length - 1]?.pagingToken,\n startLedger: undefined,\n };\n\n // Continue fetching events for the sequence\n return this.fetchEventsForSequence(sequence, nextRequest, newEvents);\n }\n\n private updateEventCache(\n response: CachedEventsResponse,\n ignoreHeight?: number,\n ): void {\n response.events.forEach((event) => {\n if (ignoreHeight && ignoreHeight === event.ledger) return;\n const ledger = event.ledger;\n if (!this.eventsCache[ledger]) {\n this.eventsCache[ledger] = {\n events: [],\n latestLedger: response.latestLedger,\n } as unknown as rpc.Api.GetEventsResponse;\n }\n const eventExists = this.eventsCache[ledger].events.some(\n (existingEvent) => existingEvent.id === event.id,\n );\n if (!eventExists) {\n this.eventsCache[ledger].events.push(event);\n }\n });\n }\n\n async getEvents(\n request: rpc.Server.GetEventsRequest,\n ): Promise<rpc.Api.GetEventsResponse> {\n const sequence = request.startLedger;\n\n if (sequence === undefined) {\n throw new Error(`Get soraban event failed, block sequence is missing`);\n }\n\n if (this.eventsCache[sequence]) {\n const cachedEvents = this.eventsCache[sequence];\n delete this.eventsCache[sequence];\n return cachedEvents;\n }\n\n const response = await this.fetchEventsForSequence(sequence, request);\n this.updateEventCache(response.eventsToCache, sequence);\n\n return response.events as rpc.Api.GetEventsResponse;\n }\n}\n"]}
1
+ {"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8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AAC,EAAE,KAAK,KAAK,CAAC,EAAE,CACjD,CAAC;YACF,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CACb,OAAoC;QAEpC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;QAErC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAExD,OAAO,QAAQ,CAAC,MAAmC,CAAC;IACtD,CAAC;CACF;AApGD,sCAoGC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { rpc } from '@stellar/stellar-sdk';\nimport { SorobanRpcEventResponse } from '@subql/types-stellar';\nimport { compact, groupBy, last } from 'lodash';\nimport { DEFAULT_PAGE_SIZE } from './utils.stellar';\n\ntype CachedEventsResponse = Pick<\n rpc.Api.GetEventsResponse,\n 'events' | 'latestLedger'\n>;\n\nexport class SorobanServer extends rpc.Server {\n private eventsCache: { [key: number]: rpc.Api.GetEventsResponse } = {};\n\n private async fetchEventsForSequence(\n sequence: number,\n request: rpc.Server.GetEventsRequest,\n accEvents: SorobanRpcEventResponse[] = [],\n ): Promise<{\n events: CachedEventsResponse;\n eventsToCache: CachedEventsResponse;\n }> {\n const pageLimit = request.limit ?? DEFAULT_PAGE_SIZE;\n const response = await super.getEvents(request);\n\n // Separate the events for the current sequence and the subsequent sequences\n const groupedEvents = groupBy(response.events, (event) =>\n event.ledger === sequence ? 'events' : 'eventsToCache',\n );\n const events = compact(groupedEvents.events);\n let eventsToCache = compact(groupedEvents.eventsToCache);\n\n // Update the accumulated events with the events from the current sequence\n const newEvents = accEvents.concat(events);\n\n if (eventsToCache?.length) {\n if (response.events.length === pageLimit) {\n const lastSequence = last(response.events)!.ledger;\n eventsToCache = eventsToCache.filter(\n (event) => event.ledger !== lastSequence,\n );\n }\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: {\n events: eventsToCache,\n latestLedger: response.latestLedger,\n },\n };\n }\n\n if (response.events.length < pageLimit) {\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: { events: [], latestLedger: response.latestLedger },\n };\n }\n\n // Prepare the next request\n const nextRequest = {\n ...request,\n cursor: response.events[response.events.length - 1]?.pagingToken,\n startLedger: undefined,\n };\n\n // Continue fetching events for the sequence\n return this.fetchEventsForSequence(sequence, nextRequest, newEvents);\n }\n\n private updateEventCache(\n response: CachedEventsResponse,\n ignoreHeight?: number,\n ): void {\n response.events.forEach((event) => {\n if (ignoreHeight && ignoreHeight === event.ledger) return;\n const ledger = event.ledger;\n if (!this.eventsCache[ledger]) {\n this.eventsCache[ledger] = {\n events: [],\n latestLedger: response.latestLedger,\n } as unknown as rpc.Api.GetEventsResponse;\n }\n const eventExists = this.eventsCache[ledger].events.some(\n (existingEvent) => existingEvent.id === event.id,\n );\n if (!eventExists) {\n this.eventsCache[ledger].events.push(event);\n }\n });\n }\n\n async getEvents(\n request: rpc.Server.GetEventsRequest,\n ): Promise<rpc.Api.GetEventsResponse> {\n const sequence = request.startLedger;\n\n if (sequence === undefined) {\n throw new Error(`Get soraban event failed, block sequence is missing`);\n }\n\n if (this.eventsCache[sequence]) {\n const cachedEvents = this.eventsCache[sequence];\n delete this.eventsCache[sequence];\n return cachedEvents;\n }\n\n const response = await this.fetchEventsForSequence(sequence, request);\n this.updateEventCache(response.eventsToCache, sequence);\n\n return response.events as rpc.Api.GetEventsResponse;\n }\n}\n"]}
@@ -2,25 +2,30 @@
2
2
  // Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.DEFAULT_PAGE_SIZE = exports.calcInterval = exports.formatBlockUtil = exports.stellarBlockToHeader = void 0;
5
+ exports.DEFAULT_PAGE_SIZE = void 0;
6
+ exports.stellarBlockToHeader = stellarBlockToHeader;
7
+ exports.formatBlockUtil = formatBlockUtil;
8
+ exports.calcInterval = calcInterval;
6
9
  function stellarBlockToHeader(block) {
7
10
  return {
8
11
  blockHeight: block.sequence,
9
- blockHash: block.hash.toString(),
10
- parentHash: block.prev_hash.toString(),
12
+ // Stellar has instant finalization and there is no RPC for getting blocks by hash.
13
+ // For these reasons we use the block numbers for hashes so that unfinalized blocks works.
14
+ blockHash: block.sequence.toString(),
15
+ parentHash: (block.sequence - 1).toString(),
16
+ // blockHash: block.hash.toString(),
17
+ // parentHash: block.prev_hash.toString(),
18
+ timestamp: new Date(block.closed_at),
11
19
  };
12
20
  }
13
- exports.stellarBlockToHeader = stellarBlockToHeader;
14
21
  function formatBlockUtil(block) {
15
22
  return {
16
23
  block,
17
24
  getHeader: () => stellarBlockToHeader(block.block),
18
25
  };
19
26
  }
20
- exports.formatBlockUtil = formatBlockUtil;
21
27
  function calcInterval(api) {
22
28
  return 6000;
23
29
  }
24
- exports.calcInterval = calcInterval;
25
30
  exports.DEFAULT_PAGE_SIZE = 150;
26
31
  //# sourceMappingURL=utils.stellar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAUnC,SAAgB,oBAAoB,CAClC,KAAoD;IAEpD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,QAAQ;QAC3B,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;QAChC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE;KACvC,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC;KACnD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC;AAEY,QAAA,iBAAiB,GAAG,GAAG,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function stellarBlockToHeader(\n block: StellarBlock | Horizon.ServerApi.LedgerRecord,\n): Header {\n return {\n blockHeight: block.sequence,\n blockHash: block.hash.toString(),\n parentHash: block.prev_hash.toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => stellarBlockToHeader(block.block),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n\nexport const DEFAULT_PAGE_SIZE = 150;\n"]}
1
+ {"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAUnC,oDAaC;AAED,0CAOC;AAED,oCAEC;AA1BD,SAAgB,oBAAoB,CAClC,KAAoD;IAEpD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,QAAQ;QAC3B,mFAAmF;QACnF,0FAA0F;QAC1F,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACpC,UAAU,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;QAC3C,oCAAoC;QACpC,0CAA0C;QAC1C,SAAS,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAEY,QAAA,iBAAiB,GAAG,GAAG,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function stellarBlockToHeader(\n block: StellarBlock | Horizon.ServerApi.LedgerRecord,\n): Header {\n return {\n blockHeight: block.sequence,\n // Stellar has instant finalization and there is no RPC for getting blocks by hash.\n // For these reasons we use the block numbers for hashes so that unfinalized blocks works.\n blockHash: block.sequence.toString(),\n parentHash: (block.sequence - 1).toString(),\n // blockHash: block.hash.toString(),\n // parentHash: block.prev_hash.toString(),\n timestamp: new Date(block.closed_at),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => stellarBlockToHeader(block.block),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n\nexport const DEFAULT_PAGE_SIZE = 150;\n"]}
@@ -14,7 +14,8 @@ const node_core_1 = require("@subql/node-core");
14
14
  const configure_module_1 = require("../configure/configure.module");
15
15
  let ForceCleanModule = class ForceCleanModule {
16
16
  };
17
- ForceCleanModule = __decorate([
17
+ exports.ForceCleanModule = ForceCleanModule;
18
+ exports.ForceCleanModule = ForceCleanModule = __decorate([
18
19
  (0, common_1.Module)({
19
20
  imports: [
20
21
  node_core_1.DbModule.forRoot(),
@@ -24,5 +25,4 @@ ForceCleanModule = __decorate([
24
25
  controllers: [],
25
26
  })
26
27
  ], ForceCleanModule);
27
- exports.ForceCleanModule = ForceCleanModule;
28
28
  //# sourceMappingURL=forceClean.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"forceClean.module.js","sourceRoot":"","sources":["../../src/subcommands/forceClean.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,gDAAqE;AACrE,oEAAgE;AAUzD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,gBAAgB;IAR5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,mCAAuB;SACxB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,gBAAgB,CAAG;AAAnB,4CAAgB","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { DbModule, ForceCleanFeatureModule } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ForceCleanFeatureModule,\n ],\n controllers: [],\n})\nexport class ForceCleanModule {}\n"]}
1
+ {"version":3,"file":"forceClean.module.js","sourceRoot":"","sources":["../../src/subcommands/forceClean.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,gDAAqE;AACrE,oEAAgE;AAUzD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAR5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,mCAAuB;SACxB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,gBAAgB,CAAG","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { DbModule, ForceCleanFeatureModule } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ForceCleanFeatureModule,\n ],\n controllers: [],\n})\nexport class ForceCleanModule {}\n"]}
@@ -14,42 +14,37 @@ const event_emitter_1 = require("@nestjs/event-emitter");
14
14
  const schedule_1 = require("@nestjs/schedule");
15
15
  const node_core_1 = require("@subql/node-core");
16
16
  const x_sequelize_1 = require("@subql/x-sequelize");
17
+ const blockchain_service_1 = require("../blockchain.service");
17
18
  const configure_module_1 = require("../configure/configure.module");
18
- const ds_processor_service_1 = require("../indexer/ds-processor.service");
19
- const dynamic_ds_service_1 = require("../indexer/dynamic-ds.service");
20
- const unfinalizedBlocks_service_1 = require("../indexer/unfinalizedBlocks.service");
21
19
  const stellar_1 = require("../stellar");
22
20
  let ReindexFeatureModule = class ReindexFeatureModule {
23
21
  };
24
- ReindexFeatureModule = __decorate([
22
+ exports.ReindexFeatureModule = ReindexFeatureModule;
23
+ exports.ReindexFeatureModule = ReindexFeatureModule = __decorate([
25
24
  (0, common_1.Module)({
26
25
  providers: [
27
26
  {
28
27
  provide: 'IStoreModelProvider',
29
28
  useFactory: node_core_1.storeModelFactory,
30
- inject: [node_core_1.NodeConfig, event_emitter_1.EventEmitter2, schedule_1.SchedulerRegistry, x_sequelize_1.Sequelize],
29
+ inject: [node_core_1.NodeConfig, event_emitter_1.EventEmitter2, x_sequelize_1.Sequelize],
31
30
  },
32
31
  node_core_1.StoreService,
33
32
  node_core_1.ReindexService,
34
33
  node_core_1.ForceCleanService,
35
34
  {
36
35
  provide: 'UnfinalizedBlocksService',
37
- useClass: unfinalizedBlocks_service_1.UnfinalizedBlocksService,
36
+ useClass: node_core_1.UnfinalizedBlocksService,
38
37
  },
39
38
  {
40
39
  provide: 'DynamicDsService',
41
- useClass: dynamic_ds_service_1.DynamicDsService,
40
+ useClass: node_core_1.DynamicDsService,
42
41
  },
43
- ds_processor_service_1.DsProcessorService,
42
+ node_core_1.DsProcessorService,
44
43
  node_core_1.ConnectionPoolService,
45
44
  node_core_1.ConnectionPoolStateManager,
46
45
  {
47
- provide: node_core_1.ApiService,
48
- useFactory: async (project, connectionPoolService, eventEmitter, nodeConfig) => {
49
- const apiService = new stellar_1.StellarApiService(project, connectionPoolService, eventEmitter, nodeConfig);
50
- await apiService.init();
51
- return apiService;
52
- },
46
+ provide: 'APIService',
47
+ useFactory: stellar_1.StellarApiService.create.bind(stellar_1.StellarApiService),
53
48
  inject: [
54
49
  'ISubqueryProject',
55
50
  node_core_1.ConnectionPoolService,
@@ -57,15 +52,19 @@ ReindexFeatureModule = __decorate([
57
52
  node_core_1.NodeConfig,
58
53
  ],
59
54
  },
55
+ {
56
+ provide: 'IBlockchainService',
57
+ useClass: blockchain_service_1.BlockchainService,
58
+ },
60
59
  schedule_1.SchedulerRegistry,
61
60
  ],
62
61
  controllers: [],
63
62
  })
64
63
  ], ReindexFeatureModule);
65
- exports.ReindexFeatureModule = ReindexFeatureModule;
66
64
  let ReindexModule = class ReindexModule {
67
65
  };
68
- ReindexModule = __decorate([
66
+ exports.ReindexModule = ReindexModule;
67
+ exports.ReindexModule = ReindexModule = __decorate([
69
68
  (0, common_1.Module)({
70
69
  imports: [
71
70
  node_core_1.DbModule.forRoot(),
@@ -76,5 +75,4 @@ ReindexModule = __decorate([
76
75
  controllers: [],
77
76
  })
78
77
  ], ReindexModule);
79
- exports.ReindexModule = ReindexModule;
80
78
  //# sourceMappingURL=reindex.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA0E;AAC1E,+CAAqD;AACrD,gDAU0B;AAC1B,oDAA+C;AAC/C,oEAAgE;AAEhE,0EAAqE;AACrE,sEAAiE;AACjE,oFAAgF;AAChF,wCAA+C;AAoDxC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAjDhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,qBAAqB;gBAC9B,UAAU,EAAE,6BAAiB;gBAC7B,MAAM,EAAE,CAAC,sBAAU,EAAE,6BAAa,EAAE,4BAAiB,EAAE,uBAAS,CAAC;aAClE;YACD,wBAAY;YACZ,0BAAc;YACd,6BAAiB;YACjB;gBACE,OAAO,EAAE,0BAA0B;gBACnC,QAAQ,EAAE,oDAAwB;aACnC;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,QAAQ,EAAE,qCAAgB;aAC3B;YACD,yCAAkB;YAClB,iCAAqB;YACrB,sCAA0B;YAC1B;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAkE,EAClE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,2BAAiB,CACtC,OAAO,EACP,qBAAqB,EACrB,YAAY,EACZ,UAAU,CACX,CAAC;oBACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;oBACxB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,MAAM,EAAE;oBACN,kBAAkB;oBAClB,iCAAqB;oBACrB,6BAAa;oBACb,sBAAU;iBACX;aACF;YACD,4BAAiB;SAClB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB;AAW1B,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,oBAAoB;YACpB,kCAAkB,CAAC,OAAO,EAAE;SAC7B;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,aAAa,CAAG;AAAhB,sCAAa","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\nimport {\n ApiService,\n DbModule,\n ForceCleanService,\n StoreService,\n ReindexService,\n storeModelFactory,\n NodeConfig,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n} from '@subql/node-core';\nimport { Sequelize } from '@subql/x-sequelize';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { DsProcessorService } from '../indexer/ds-processor.service';\nimport { DynamicDsService } from '../indexer/dynamic-ds.service';\nimport { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';\nimport { StellarApiService } from '../stellar';\nimport { StellarApiConnection } from '../stellar/api.connection';\n\n@Module({\n providers: [\n {\n provide: 'IStoreModelProvider',\n useFactory: storeModelFactory,\n inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize],\n },\n StoreService,\n ReindexService,\n ForceCleanService,\n {\n provide: 'UnfinalizedBlocksService',\n useClass: UnfinalizedBlocksService,\n },\n {\n provide: 'DynamicDsService',\n useClass: DynamicDsService,\n },\n DsProcessorService,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<StellarApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) => {\n const apiService = new StellarApiService(\n project,\n connectionPoolService,\n eventEmitter,\n nodeConfig,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n SchedulerRegistry,\n ],\n controllers: [],\n})\nexport class ReindexFeatureModule {}\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ReindexFeatureModule,\n EventEmitterModule.forRoot(),\n ],\n controllers: [],\n})\nexport class ReindexModule {}\n"]}
1
+ {"version":3,"file":"reindex.module.js","sourceRoot":"","sources":["../../src/subcommands/reindex.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA0E;AAC1E,+CAAqD;AACrD,gDAY0B;AAC1B,oDAA+C;AAC/C,8DAA0D;AAC1D,oEAAgE;AAChE,wCAA+C;AAyCxC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oDAAoB;+BAApB,oBAAoB;IAvChC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,qBAAqB;gBAC9B,UAAU,EAAE,6BAAiB;gBAC7B,MAAM,EAAE,CAAC,sBAAU,EAAE,6BAAa,EAAE,uBAAS,CAAC;aAC/C;YACD,wBAAY;YACZ,0BAAc;YACd,6BAAiB;YACjB;gBACE,OAAO,EAAE,0BAA0B;gBACnC,QAAQ,EAAE,oCAAwB;aACnC;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,QAAQ,EAAE,4BAAgB;aAC3B;YACD,8BAAkB;YAClB,iCAAqB;YACrB,sCAA0B;YAC1B;gBACE,OAAO,EAAE,YAAY;gBACrB,UAAU,EAAE,2BAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,2BAAiB,CAAC;gBAC5D,MAAM,EAAE;oBACN,kBAAkB;oBAClB,iCAAqB;oBACrB,6BAAa;oBACb,sBAAU;iBACX;aACF;YACD;gBACE,OAAO,EAAE,oBAAoB;gBAC7B,QAAQ,EAAE,sCAAiB;aAC5B;YACD,4BAAiB;SAClB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,oBAAoB,CAAG;AAW7B,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,oBAAoB;YACpB,kCAAkB,CAAC,OAAO,EAAE;SAC7B;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,aAAa,CAAG","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\nimport {\n DbModule,\n ForceCleanService,\n StoreService,\n ReindexService,\n storeModelFactory,\n NodeConfig,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n UnfinalizedBlocksService,\n DynamicDsService,\n DsProcessorService,\n} from '@subql/node-core';\nimport { Sequelize } from '@subql/x-sequelize';\nimport { BlockchainService } from '../blockchain.service';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { StellarApiService } from '../stellar';\n\n@Module({\n providers: [\n {\n provide: 'IStoreModelProvider',\n useFactory: storeModelFactory,\n inject: [NodeConfig, EventEmitter2, Sequelize],\n },\n StoreService,\n ReindexService,\n ForceCleanService,\n {\n provide: 'UnfinalizedBlocksService',\n useClass: UnfinalizedBlocksService,\n },\n {\n provide: 'DynamicDsService',\n useClass: DynamicDsService,\n },\n DsProcessorService,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: 'APIService',\n useFactory: StellarApiService.create.bind(StellarApiService),\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n {\n provide: 'IBlockchainService',\n useClass: BlockchainService,\n },\n SchedulerRegistry,\n ],\n controllers: [],\n})\nexport class ReindexFeatureModule {}\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n ReindexFeatureModule,\n EventEmitterModule.forRoot(),\n ],\n controllers: [],\n})\nexport class ReindexModule {}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.testingInit = void 0;
5
+ exports.testingInit = testingInit;
6
6
  const node_core_1 = require("@subql/node-core");
7
7
  const configure_module_1 = require("../configure/configure.module");
8
8
  const testing_service_1 = require("./testing.service");
@@ -18,5 +18,4 @@ async function testingInit() {
18
18
  }
19
19
  process.exit(0);
20
20
  }
21
- exports.testingInit = testingInit;
22
21
  //# sourceMappingURL=testing.init.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAA4D;AAC5D,oEAAgE;AAChE,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAC7B,KAAK,UAAU,WAAW;IAC/B,IAAI;QACF,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,kCAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,MAAM,cAAc,GAAG,IAAI,gCAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,cAAc,CAAC,GAAG,EAAE,CAAC;KAC5B;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,yBAAa,EAAC,IAAI,KAAK,CAAC,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;KAClE;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAVD,kCAUC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { exitWithError, getLogger } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { TestingService } from './testing.service';\n\nconst logger = getLogger('Testing');\nexport async function testingInit(): Promise<void> {\n try {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n const testingService = new TestingService(nodeConfig, project);\n await testingService.run();\n } catch (e) {\n exitWithError(new Error('Testing failed', { cause: e }), logger);\n }\n process.exit(0);\n}\n"]}
1
+ {"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAOnC,kCAUC;AAfD,gDAA4D;AAC5D,oEAAgE;AAChE,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAC7B,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,kCAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,MAAM,cAAc,GAAG,IAAI,gCAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,cAAc,CAAC,GAAG,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAA,yBAAa,EAAC,IAAI,KAAK,CAAC,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { exitWithError, getLogger } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { TestingService } from './testing.service';\n\nconst logger = getLogger('Testing');\nexport async function testingInit(): Promise<void> {\n try {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n const testingService = new TestingService(nodeConfig, project);\n await testingService.run();\n } catch (e) {\n exitWithError(new Error('Testing failed', { cause: e }), logger);\n }\n process.exit(0);\n}\n"]}
@@ -13,48 +13,24 @@ const common_1 = require("@nestjs/common");
13
13
  const event_emitter_1 = require("@nestjs/event-emitter");
14
14
  const schedule_1 = require("@nestjs/schedule");
15
15
  const node_core_1 = require("@subql/node-core");
16
- const x_sequelize_1 = require("@subql/x-sequelize");
16
+ const blockchain_service_1 = require("../blockchain.service");
17
17
  const configure_module_1 = require("../configure/configure.module");
18
- const ds_processor_service_1 = require("../indexer/ds-processor.service");
19
- const dynamic_ds_service_1 = require("../indexer/dynamic-ds.service");
20
18
  const indexer_manager_1 = require("../indexer/indexer.manager");
21
- const project_service_1 = require("../indexer/project.service");
22
- const unfinalizedBlocks_service_1 = require("../indexer/unfinalizedBlocks.service");
23
19
  const stellar_1 = require("../stellar");
24
- const testing_service_1 = require("./testing.service");
25
20
  let TestingFeatureModule = class TestingFeatureModule {
26
21
  };
27
- TestingFeatureModule = __decorate([
22
+ exports.TestingFeatureModule = TestingFeatureModule;
23
+ exports.TestingFeatureModule = TestingFeatureModule = __decorate([
28
24
  (0, common_1.Module)({
25
+ imports: [node_core_1.TestingCoreModule],
29
26
  providers: [
30
- node_core_1.InMemoryCacheService,
31
- node_core_1.StoreService,
32
- {
33
- provide: 'IStoreModelProvider',
34
- useFactory: node_core_1.storeModelFactory,
35
- inject: [node_core_1.NodeConfig, event_emitter_1.EventEmitter2, schedule_1.SchedulerRegistry, x_sequelize_1.Sequelize],
36
- },
37
- testing_service_1.TestingService,
38
- event_emitter_1.EventEmitter2,
39
- node_core_1.PoiService,
40
- node_core_1.PoiSyncService,
41
- node_core_1.SandboxService,
42
- ds_processor_service_1.DsProcessorService,
43
- dynamic_ds_service_1.DynamicDsService,
44
- unfinalizedBlocks_service_1.UnfinalizedBlocksService,
45
- node_core_1.ConnectionPoolService,
46
- node_core_1.ConnectionPoolStateManager,
47
27
  {
48
28
  provide: 'IProjectService',
49
- useClass: project_service_1.ProjectService,
29
+ useClass: node_core_1.ProjectService,
50
30
  },
51
31
  {
52
- provide: node_core_1.ApiService,
53
- useFactory: async (project, connectionPoolService, eventEmitter, nodeConfig) => {
54
- const apiService = new stellar_1.StellarApiService(project, connectionPoolService, eventEmitter, nodeConfig);
55
- await apiService.init();
56
- return apiService;
57
- },
32
+ provide: 'APIService',
33
+ useFactory: stellar_1.StellarApiService.create.bind(stellar_1.StellarApiService),
58
34
  inject: [
59
35
  'ISubqueryProject',
60
36
  node_core_1.ConnectionPoolService,
@@ -62,26 +38,31 @@ TestingFeatureModule = __decorate([
62
38
  node_core_1.NodeConfig,
63
39
  ],
64
40
  },
65
- node_core_1.TestRunner,
66
41
  {
67
- provide: 'IApi',
68
- useClass: stellar_1.StellarApiService,
42
+ provide: 'IUnfinalizedBlocksService',
43
+ useClass: node_core_1.UnfinalizedBlocksService,
44
+ },
45
+ {
46
+ provide: 'IBlockchainService',
47
+ useClass: blockchain_service_1.BlockchainService,
69
48
  },
49
+ node_core_1.TestRunner,
70
50
  {
71
51
  provide: 'IIndexerManager',
72
52
  useClass: indexer_manager_1.IndexerManager,
73
53
  },
74
54
  indexer_manager_1.IndexerManager,
75
- schedule_1.SchedulerRegistry,
55
+ node_core_1.DsProcessorService,
56
+ node_core_1.DynamicDsService,
76
57
  ],
77
58
  controllers: [],
78
59
  exports: [node_core_1.TestRunner],
79
60
  })
80
61
  ], TestingFeatureModule);
81
- exports.TestingFeatureModule = TestingFeatureModule;
82
62
  let TestingModule = class TestingModule {
83
63
  };
84
- TestingModule = __decorate([
64
+ exports.TestingModule = TestingModule;
65
+ exports.TestingModule = TestingModule = __decorate([
85
66
  (0, common_1.Module)({
86
67
  imports: [
87
68
  node_core_1.DbModule.forRoot(),
@@ -93,5 +74,4 @@ TestingModule = __decorate([
93
74
  controllers: [],
94
75
  })
95
76
  ], TestingModule);
96
- exports.TestingModule = TestingModule;
97
77
  //# sourceMappingURL=testing.module.js.map