@subql/node-stellar 4.3.0 → 4.3.1-0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAa0B;AAG1B,wEAAmE;AACnE,uDAG2B;AAC3B,6CAAwD;AACxD,iEAA4D;AAC5D,6DAAwD;AACxD,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AA0GhE,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IAxGvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAU,CAAC;QACrB,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAkE,EAClE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,uCAAiB,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,gCAAc;YACd;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,CACV,UAAsB,EACtB,YAA2B,EAC3B,cAA8B,EAC9B,qBAA6C,EAC7C,UAAsB,EACtB,cAA8B,EAC9B,YAAkC,EAClC,YAA0B,EAC1B,kBAAuC,EACvC,cAA8B,EAC9B,OAAwB,EACxB,gBAAkC,EAClC,iBAA2C,EAC3C,mBAAqE,EACrE,cAA+B,EAC/B,EAAE,CACF,UAAU,CAAC,OAAO;oBAChB,CAAC,CAAC,IAAI,8CAA4B,CAC9B,UAAU,EACV,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,CACf;oBACH,CAAC,CAAC,IAAI,wCAAsB,CACxB,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,OAAO,CACR;gBACP,MAAM,EAAE;oBACN,sBAAU;oBACV,6BAAa;oBACb,iBAAiB;oBACjB,wBAAwB;oBACxB,sBAAU;oBACV,gCAAc;oBACd,gCAAoB;oBACpB,wBAAY;oBACZ,qBAAqB;oBACrB,0BAAc;oBACd,kBAAkB;oBAClB,qCAAgB;oBAChB,oDAAwB;oBACxB,sCAA0B;oBAC1B,0BAAc;iBACf;aACF;YACD,4BAAY;YACZ,qCAAwB;YACxB,yCAAkB;YAClB,qCAAgB;YAChB;gBACE,QAAQ,EAAE,gCAAc;gBACxB,OAAO,EAAE,iBAAiB;aAC3B;YACD,oDAAwB;SACzB;KACF,CAAC;GACW,WAAW,CAAG;AAAd,kCAAW","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StoreService,\n PoiSyncService,\n ApiService,\n ConnectionPoolService,\n IStoreModelProvider,\n ConnectionPoolStateManager,\n NodeConfig,\n IProjectUpgradeService,\n ProjectUpgradeService,\n InMemoryCacheService,\n MonitorService,\n CoreModule,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiConnection } from '../stellar/api.connection';\nimport { StellarApiService } from '../stellar/api.service.stellar';\nimport {\n BlockDispatcherService,\n WorkerBlockDispatcherService,\n} from './blockDispatcher';\nimport { StellarDictionaryService } from './dictionary';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { FetchService } from './fetch.service';\nimport { IndexerManager } from './indexer.manager';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n@Module({\n imports: [CoreModule],\n providers: [\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 IndexerManager,\n {\n provide: 'IBlockDispatcher',\n useFactory: (\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n projectUpgradeService: IProjectUpgradeService,\n apiService: ApiService,\n indexerManager: IndexerManager,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeModelProvider: IStoreModelProvider,\n poiSyncService: PoiSyncService,\n project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocks: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<StellarApiConnection>,\n monitorService?: MonitorService,\n ) =>\n nodeConfig.workers\n ? new WorkerBlockDispatcherService(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgradeService,\n cacheService,\n storeService,\n storeModelProvider,\n poiSyncService,\n project,\n dynamicDsService,\n unfinalizedBlocks,\n connectionPoolState,\n monitorService,\n )\n : new BlockDispatcherService(\n apiService,\n nodeConfig,\n indexerManager,\n eventEmitter,\n projectService,\n projectUpgradeService,\n storeService,\n storeModelProvider,\n poiSyncService,\n project,\n ),\n inject: [\n NodeConfig,\n EventEmitter2,\n 'IProjectService',\n 'IProjectUpgradeService',\n ApiService,\n IndexerManager,\n InMemoryCacheService,\n StoreService,\n 'IStoreModelProvider',\n PoiSyncService,\n 'ISubqueryProject',\n DynamicDsService,\n UnfinalizedBlocksService,\n ConnectionPoolStateManager,\n MonitorService,\n ],\n },\n FetchService,\n StellarDictionaryService,\n DsProcessorService,\n DynamicDsService,\n {\n useClass: ProjectService,\n provide: 'IProjectService',\n },\n UnfinalizedBlocksService,\n ],\n})\nexport class FetchModule {}\n"]}
1
+ {"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAY0B;AAG1B,wEAAmE;AACnE,uDAG2B;AAC3B,6CAAwD;AACxD,iEAA4D;AAC5D,6DAAwD;AACxD,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AA0GhE,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IAxGvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAU,CAAC;QACrB,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAkE,EAClE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,uCAAiB,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,gCAAc;YACd;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,CACV,UAAsB,EACtB,YAA2B,EAC3B,cAA8B,EAC9B,qBAA6C,EAC7C,UAAsB,EACtB,cAA8B,EAC9B,YAAkC,EAClC,YAA0B,EAC1B,kBAAuC,EACvC,cAA8B,EAC9B,OAAwB,EACxB,gBAAkC,EAClC,iBAA2C,EAC3C,mBAAqE,EACrE,cAA+B,EAC/B,EAAE,CACF,UAAU,CAAC,OAAO;oBAChB,CAAC,CAAC,IAAI,8CAA4B,CAC9B,UAAU,EACV,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,CACf;oBACH,CAAC,CAAC,IAAI,wCAAsB,CACxB,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,OAAO,CACR;gBACP,MAAM,EAAE;oBACN,sBAAU;oBACV,6BAAa;oBACb,iBAAiB;oBACjB,wBAAwB;oBACxB,sBAAU;oBACV,gCAAc;oBACd,gCAAoB;oBACpB,wBAAY;oBACZ,qBAAqB;oBACrB,0BAAc;oBACd,kBAAkB;oBAClB,qCAAgB;oBAChB,oDAAwB;oBACxB,sCAA0B;oBAC1B,0BAAc;iBACf;aACF;YACD,4BAAY;YACZ,qCAAwB;YACxB,yCAAkB;YAClB,qCAAgB;YAChB;gBACE,QAAQ,EAAE,gCAAc;gBACxB,OAAO,EAAE,iBAAiB;aAC3B;YACD,oDAAwB;SACzB;KACF,CAAC;GACW,WAAW,CAAG;AAAd,kCAAW","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StoreService,\n PoiSyncService,\n ApiService,\n ConnectionPoolService,\n IStoreModelProvider,\n ConnectionPoolStateManager,\n NodeConfig,\n IProjectUpgradeService,\n InMemoryCacheService,\n MonitorService,\n CoreModule,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiConnection } from '../stellar/api.connection';\nimport { StellarApiService } from '../stellar/api.service.stellar';\nimport {\n BlockDispatcherService,\n WorkerBlockDispatcherService,\n} from './blockDispatcher';\nimport { StellarDictionaryService } from './dictionary';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { FetchService } from './fetch.service';\nimport { IndexerManager } from './indexer.manager';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n@Module({\n imports: [CoreModule],\n providers: [\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 IndexerManager,\n {\n provide: 'IBlockDispatcher',\n useFactory: (\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n projectUpgradeService: IProjectUpgradeService,\n apiService: ApiService,\n indexerManager: IndexerManager,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeModelProvider: IStoreModelProvider,\n poiSyncService: PoiSyncService,\n project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocks: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<StellarApiConnection>,\n monitorService?: MonitorService,\n ) =>\n nodeConfig.workers\n ? new WorkerBlockDispatcherService(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgradeService,\n cacheService,\n storeService,\n storeModelProvider,\n poiSyncService,\n project,\n dynamicDsService,\n unfinalizedBlocks,\n connectionPoolState,\n monitorService,\n )\n : new BlockDispatcherService(\n apiService,\n nodeConfig,\n indexerManager,\n eventEmitter,\n projectService,\n projectUpgradeService,\n storeService,\n storeModelProvider,\n poiSyncService,\n project,\n ),\n inject: [\n NodeConfig,\n EventEmitter2,\n 'IProjectService',\n 'IProjectUpgradeService',\n ApiService,\n IndexerManager,\n InMemoryCacheService,\n StoreService,\n 'IStoreModelProvider',\n PoiSyncService,\n 'ISubqueryProject',\n DynamicDsService,\n UnfinalizedBlocksService,\n ConnectionPoolStateManager,\n MonitorService,\n ],\n },\n FetchService,\n StellarDictionaryService,\n DsProcessorService,\n DynamicDsService,\n {\n useClass: ProjectService,\n provide: 'IProjectService',\n },\n UnfinalizedBlocksService,\n ],\n})\nexport class FetchModule {}\n"]}
@@ -15,7 +15,7 @@ export declare class IndexerManager extends BaseIndexerManager<StellarApi, SafeS
15
15
  start(): Promise<void>;
16
16
  indexBlock(block: IBlock<StellarBlockWrapper>, dataSources: SubqlStellarDataSource[]): Promise<ProcessBlockResponse>;
17
17
  private getApi;
18
- protected indexBlockData({ block, effects, operations, transactions }: StellarBlockWrapper, dataSources: SubqlDatasource[], getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>): Promise<void>;
18
+ protected indexBlockData({ block, transactions }: StellarBlockWrapper, dataSources: SubqlDatasource[], getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>): Promise<void>;
19
19
  private indexBlockContent;
20
20
  private indexTransaction;
21
21
  private indexOperation;
@@ -44,7 +44,7 @@ let IndexerManager = class IndexerManager extends node_core_1.BaseIndexerManager
44
44
  // return this.apiService.safeApi(block.block.sequence);
45
45
  return null;
46
46
  }
47
- async indexBlockData({ block, effects, operations, transactions }, dataSources, getVM) {
47
+ async indexBlockData({ block, transactions }, dataSources, getVM) {
48
48
  await this.indexBlockContent(block, dataSources, getVM);
49
49
  for (const tx of transactions) {
50
50
  await this.indexTransaction(tx, dataSources, getVM);
@@ -1 +1 @@
1
- {"version":3,"file":"ind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,EACnB,MAA2B,EAC3B,EAA0B,EAC1B,EAAE,CACF,mCAAmB,CAAC,qBAAqB,CACvC,IAAI,EACJ,MAAM,EACN,EAAE,CAAC,OAAO,EAAE,OAAO,CACpB;IAEH,CAAC,mCAAkB,CAAC,KAAK,CAAC,EAAE,CAC1B,IAAkB,EAClB,MAA0B,EAC1B,EAA0B,EAC1B,EAAE,CACF,mCAAmB,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;CAC9E,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n isCustomDs,\n isRuntimeDs,\n SubqlStellarCustomDataSource,\n StellarHandlerKind,\n StellarRuntimeHandlerInputMap,\n SubqlStellarDataSource,\n isBlockHandlerProcessor,\n isTransactionHandlerProcessor,\n isOperationHandlerProcessor,\n isEffectHandlerProcessor,\n isEventHandlerProcessor,\n isSorobanTransactionHandlerProcessor,\n} from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n ApiService,\n IBlock,\n SandboxService,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n StellarTransaction,\n StellarOperation,\n StellarEffect,\n StellarBlock,\n StellarBlockFilter,\n StellarTransactionFilter,\n StellarOperationFilter,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n} from '@subql/types-stellar';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('indexer');\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n StellarApi,\n SafeStellarProvider | null,\n StellarBlockWrapper,\n ApiService,\n SubqlStellarDataSource,\n SubqlStellarCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n StellarRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService<SafeStellarProvider | null, StellarApi>,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IProjectService') private projectService: ProjectService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n async start(): Promise<void> {\n await this.projectService.init();\n logger.info('indexer manager started');\n }\n\n @profiler()\n async indexBlock(\n block: IBlock<StellarBlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block.block),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(\n block: StellarBlockWrapper,\n ): Promise<SafeStellarProvider | null> {\n // return this.apiService.safeApi(block.block.sequence);\n return null;\n }\n\n protected async indexBlockData(\n { block, effects, operations, transactions }: StellarBlockWrapper,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const operation of tx.operations) {\n await this.indexOperation(operation, dataSources, getVM);\n\n for (const effect of operation.effects) {\n await this.indexEffect(effect, dataSources, getVM);\n }\n for (const event of operation.events) {\n await this.indexEvent(event, dataSources, getVM);\n }\n }\n }\n }\n\n private async indexBlockContent(\n block: StellarBlock,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n transaction: StellarTransaction,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(\n StellarHandlerKind.Transaction,\n transaction,\n ds,\n getVM,\n );\n\n if (\n transaction.operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n )\n ) {\n await this.indexData(\n StellarHandlerKind.SorobanTransaction,\n transaction,\n ds,\n getVM,\n );\n }\n }\n }\n\n private async indexOperation(\n operation: StellarOperation,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Operation, operation, ds, getVM);\n }\n }\n\n private async indexEffect(\n effect: StellarEffect,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Effects, effect, ds, getVM);\n }\n }\n\n private async indexEvent(\n event: SorobanEvent,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Event, event, ds, getVM);\n }\n }\n\n protected async prepareFilteredData<T = any>(\n kind: StellarHandlerKind,\n data: T,\n ds: SubqlDatasource,\n ): Promise<T> {\n return Promise.resolve(data);\n }\n}\n\ntype ProcessorTypeMap = {\n [StellarHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [StellarHandlerKind.Transaction]: typeof isTransactionHandlerProcessor;\n [StellarHandlerKind.SorobanTransaction]: typeof isSorobanTransactionHandlerProcessor;\n [StellarHandlerKind.Operation]: typeof isOperationHandlerProcessor;\n [StellarHandlerKind.Effects]: typeof isEffectHandlerProcessor;\n [StellarHandlerKind.Event]: typeof isEventHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [StellarHandlerKind.Block]: isBlockHandlerProcessor,\n [StellarHandlerKind.Transaction]: isTransactionHandlerProcessor,\n [StellarHandlerKind.SorobanTransaction]: isSorobanTransactionHandlerProcessor,\n [StellarHandlerKind.Operation]: isOperationHandlerProcessor,\n [StellarHandlerKind.Effects]: isEffectHandlerProcessor,\n [StellarHandlerKind.Event]: isEventHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [StellarHandlerKind.Block]: (\n data: StellarBlock,\n filter: StellarBlockFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterBlocksProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Transaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.SorobanTransaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Operation]: (\n data: StellarOperation,\n filter: StellarOperationFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterOperationProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Effects]: (\n data: StellarEffect,\n filter: StellarEffectFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEffectProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Event]: (\n data: SorobanEvent,\n filter: SorobanEventFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEventProcessor(data, filter, ds.options?.address),\n};\n"]}
1
+ {"version":3,"file":"indexer.manager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EAC1B,EAAE,CACF,mCAAmB,CAAC,qBAAqB,CACvC,IAAI,EACJ,MAAM,EACN,EAAE,CAAC,OAAO,EAAE,OAAO,CACpB;IAEH,CAAC,mCAAkB,CAAC,KAAK,CAAC,EAAE,CAC1B,IAAkB,EAClB,MAA0B,EAC1B,EAA0B,EAC1B,EAAE,CACF,mCAAmB,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;CAC9E,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n isCustomDs,\n isRuntimeDs,\n SubqlStellarCustomDataSource,\n StellarHandlerKind,\n StellarRuntimeHandlerInputMap,\n SubqlStellarDataSource,\n isBlockHandlerProcessor,\n isTransactionHandlerProcessor,\n isOperationHandlerProcessor,\n isEffectHandlerProcessor,\n isEventHandlerProcessor,\n isSorobanTransactionHandlerProcessor,\n} from '@subql/common-stellar';\nimport {\n NodeConfig,\n getLogger,\n profiler,\n IndexerSandbox,\n ProcessBlockResponse,\n BaseIndexerManager,\n ApiService,\n IBlock,\n SandboxService,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n SubqlDatasource,\n StellarTransaction,\n StellarOperation,\n StellarEffect,\n StellarBlock,\n StellarBlockFilter,\n StellarTransactionFilter,\n StellarOperationFilter,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n} from '@subql/types-stellar';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\nconst logger = getLogger('indexer');\n\n@Injectable()\nexport class IndexerManager extends BaseIndexerManager<\n StellarApi,\n SafeStellarProvider | null,\n StellarBlockWrapper,\n ApiService,\n SubqlStellarDataSource,\n SubqlStellarCustomDataSource,\n typeof FilterTypeMap,\n typeof ProcessorTypeMap,\n StellarRuntimeHandlerInputMap\n> {\n protected isRuntimeDs = isRuntimeDs;\n protected isCustomDs = isCustomDs;\n\n constructor(\n apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService<SafeStellarProvider | null, StellarApi>,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IProjectService') private projectService: ProjectService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n );\n }\n\n async start(): Promise<void> {\n await this.projectService.init();\n logger.info('indexer manager started');\n }\n\n @profiler()\n async indexBlock(\n block: IBlock<StellarBlockWrapper>,\n dataSources: SubqlStellarDataSource[],\n ): Promise<ProcessBlockResponse> {\n return super.internalIndexBlock(block, dataSources, () =>\n this.getApi(block.block),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n private async getApi(\n block: StellarBlockWrapper,\n ): Promise<SafeStellarProvider | null> {\n // return this.apiService.safeApi(block.block.sequence);\n return null;\n }\n\n protected async indexBlockData(\n { block, transactions }: StellarBlockWrapper,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n await this.indexBlockContent(block, dataSources, getVM);\n\n for (const tx of transactions) {\n await this.indexTransaction(tx, dataSources, getVM);\n\n for (const operation of tx.operations) {\n await this.indexOperation(operation, dataSources, getVM);\n\n for (const effect of operation.effects) {\n await this.indexEffect(effect, dataSources, getVM);\n }\n for (const event of operation.events) {\n await this.indexEvent(event, dataSources, getVM);\n }\n }\n }\n }\n\n private async indexBlockContent(\n block: StellarBlock,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Block, block, ds, getVM);\n }\n }\n\n private async indexTransaction(\n transaction: StellarTransaction,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(\n StellarHandlerKind.Transaction,\n transaction,\n ds,\n getVM,\n );\n\n if (\n transaction.operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n )\n ) {\n await this.indexData(\n StellarHandlerKind.SorobanTransaction,\n transaction,\n ds,\n getVM,\n );\n }\n }\n }\n\n private async indexOperation(\n operation: StellarOperation,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Operation, operation, ds, getVM);\n }\n }\n\n private async indexEffect(\n effect: StellarEffect,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Effects, effect, ds, getVM);\n }\n }\n\n private async indexEvent(\n event: SorobanEvent,\n dataSources: SubqlDatasource[],\n getVM: (d: SubqlDatasource) => Promise<IndexerSandbox>,\n ): Promise<void> {\n for (const ds of dataSources) {\n await this.indexData(StellarHandlerKind.Event, event, ds, getVM);\n }\n }\n\n protected async prepareFilteredData<T = any>(\n kind: StellarHandlerKind,\n data: T,\n ds: SubqlDatasource,\n ): Promise<T> {\n return Promise.resolve(data);\n }\n}\n\ntype ProcessorTypeMap = {\n [StellarHandlerKind.Block]: typeof isBlockHandlerProcessor;\n [StellarHandlerKind.Transaction]: typeof isTransactionHandlerProcessor;\n [StellarHandlerKind.SorobanTransaction]: typeof isSorobanTransactionHandlerProcessor;\n [StellarHandlerKind.Operation]: typeof isOperationHandlerProcessor;\n [StellarHandlerKind.Effects]: typeof isEffectHandlerProcessor;\n [StellarHandlerKind.Event]: typeof isEventHandlerProcessor;\n};\n\nconst ProcessorTypeMap = {\n [StellarHandlerKind.Block]: isBlockHandlerProcessor,\n [StellarHandlerKind.Transaction]: isTransactionHandlerProcessor,\n [StellarHandlerKind.SorobanTransaction]: isSorobanTransactionHandlerProcessor,\n [StellarHandlerKind.Operation]: isOperationHandlerProcessor,\n [StellarHandlerKind.Effects]: isEffectHandlerProcessor,\n [StellarHandlerKind.Event]: isEventHandlerProcessor,\n};\n\nconst FilterTypeMap = {\n [StellarHandlerKind.Block]: (\n data: StellarBlock,\n filter: StellarBlockFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterBlocksProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Transaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.SorobanTransaction]: (\n data: StellarTransaction,\n filter: StellarTransactionFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterTransactionProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Operation]: (\n data: StellarOperation,\n filter: StellarOperationFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterOperationProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Effects]: (\n data: StellarEffect,\n filter: StellarEffectFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEffectProcessor(\n data,\n filter,\n ds.options?.address,\n ),\n\n [StellarHandlerKind.Event]: (\n data: SorobanEvent,\n filter: SorobanEventFilter,\n ds: SubqlStellarDataSource,\n ) =>\n StellarBlockWrapped.filterEventProcessor(data, filter, ds.options?.address),\n};\n"]}
@@ -1,4 +1,3 @@
1
- import { EventEmitter2 } from '@nestjs/event-emitter';
2
1
  import { ApiConnectionError, IApiConnectionSpecific, NetworkMetadataPayload, IBlock } from '@subql/node-core';
3
2
  import { StellarBlockWrapper, IStellarEndpointConfig } from '@subql/types-stellar';
4
3
  import { StellarApi } from './api.stellar';
@@ -10,7 +9,7 @@ export declare class StellarApiConnection implements IApiConnectionSpecific<Stel
10
9
  private fetchBlocksBatches;
11
10
  readonly networkMeta: NetworkMetadataPayload;
12
11
  constructor(unsafeApi: StellarApi, fetchBlocksBatches: FetchFunc);
13
- static create(endpoint: string, fetchBlockBatches: FetchFunc, eventEmitter: EventEmitter2, soroban?: SorobanServer, config?: IStellarEndpointConfig): Promise<StellarApiConnection>;
12
+ static create(endpoint: string, fetchBlockBatches: FetchFunc, soroban?: SorobanServer, config?: IStellarEndpointConfig): Promise<StellarApiConnection>;
14
13
  safeApi(height: number): SafeStellarProvider;
15
14
  apiConnect(): Promise<void>;
16
15
  apiDisconnect(): Promise<void>;
@@ -18,8 +18,8 @@ class StellarApiConnection {
18
18
  genesisHash: unsafeApi.getGenesisHash(),
19
19
  };
20
20
  }
21
- static async create(endpoint, fetchBlockBatches, eventEmitter, soroban, config) {
22
- const api = new api_stellar_1.StellarApi(endpoint, eventEmitter, soroban, config);
21
+ static async create(endpoint, fetchBlockBatches, soroban, config) {
22
+ const api = new api_stellar_1.StellarApi(endpoint, soroban, config);
23
23
  await api.init();
24
24
  return new StellarApiConnection(api, fetchBlockBatches);
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/stellar/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,gDAU0B;AAK1B,+CAA2C;AAS3C,MAAa,oBAAoB;IAWtB;IACC;IAJD,WAAW,CAAyB;IAE7C,YACS,SAAqB,EACpB,kBAA6B;QAD9B,cAAS,GAAT,SAAS,CAAY;QACpB,uBAAkB,GAAlB,kBAAkB,CAAW;QAErC,IAAI,CAAC,WAAW,GAAG;YACjB,KAAK,EA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AAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM,IACL,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC;YACzC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACvC;YACA,eAAe,GAAG,IAAI,0BAAc,CAAC,CAAC,CAAC,CAAC;SACzC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE;YACtD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM;YACL,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA7ED,oDA6EC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n IApiConnectionSpecific,\n NetworkMetadataPayload,\n TimeoutError,\n RateLimitError,\n DisconnectionError,\n LargeResponseError,\n IBlock,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\ntype FetchFunc = (\n api: StellarApi,\n batch: number[],\n) => Promise<IBlock<StellarBlockWrapper>[]>;\n\nexport class StellarApiConnection\n implements\n IApiConnectionSpecific<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: StellarApi,\n private fetchBlocksBatches: FetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n fetchBlockBatches: FetchFunc,\n eventEmitter: EventEmitter2,\n soroban?: SorobanServer,\n config?: IStellarEndpointConfig,\n ): Promise<StellarApiConnection> {\n const api = new StellarApi(endpoint, eventEmitter, soroban, config);\n\n await api.init();\n\n return new StellarApiConnection(api, fetchBlockBatches);\n }\n\n safeApi(height: number): SafeStellarProvider {\n //safe api not implemented\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(heights: number[]): Promise<IBlock<StellarBlockWrapper>[]> {\n const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = StellarApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.includes(`Timeout`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (\n e.message.includes(`Rate Limit Exceeded`) ||\n e.message.includes('Too Many Requests')\n ) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`limit must not exceed`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
1
+ {"version":3,"file":"api.connection.js","sourceRoot":"","sources":["../../src/stellar/api.connection.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAU0B;AAK1B,+CAA2C;AAS3C,MAAa,oBAAoB;IAWtB;IACC;IAJD,WAAW,CAAyB;IAE7C,YACS,SAAqB,EACpB,kBAA6B;QAD9B,cAAS,GAAT,SAAS,CAAY;QACpB,uBAAkB,GAAlB,kBAAkB,CAAW;QAErC,IAAI,CAAC,WAAW,GAAG;Y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AAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM,IACL,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC;YACzC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACvC;YACA,eAAe,GAAG,IAAI,0BAAc,CAAC,CAAC,CAAC,CAAC;SACzC;aAAM,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE;YACtD,eAAe,GAAG,IAAI,8BAAkB,CAAC,CAAC,CAAC,CAAC;SAC7C;aAAM;YACL,eAAe,GAAG,IAAI,8BAAkB,CACtC,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,wBAAY,CAAC,OAAO,CACrB,CAAC;SACH;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA5ED,oDA4EC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n ApiConnectionError,\n ApiErrorType,\n IApiConnectionSpecific,\n NetworkMetadataPayload,\n TimeoutError,\n RateLimitError,\n DisconnectionError,\n LargeResponseError,\n IBlock,\n} from '@subql/node-core';\nimport {\n StellarBlockWrapper,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { StellarApi } from './api.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\n\ntype FetchFunc = (\n api: StellarApi,\n batch: number[],\n) => Promise<IBlock<StellarBlockWrapper>[]>;\n\nexport class StellarApiConnection\n implements\n IApiConnectionSpecific<\n StellarApi,\n SafeStellarProvider,\n IBlock<StellarBlockWrapper>[]\n >\n{\n readonly networkMeta: NetworkMetadataPayload;\n\n constructor(\n public unsafeApi: StellarApi,\n private fetchBlocksBatches: FetchFunc,\n ) {\n this.networkMeta = {\n chain: unsafeApi.getChainId(),\n specName: unsafeApi.getSpecName(),\n genesisHash: unsafeApi.getGenesisHash(),\n };\n }\n\n static async create(\n endpoint: string,\n fetchBlockBatches: FetchFunc,\n soroban?: SorobanServer,\n config?: IStellarEndpointConfig,\n ): Promise<StellarApiConnection> {\n const api = new StellarApi(endpoint, soroban, config);\n\n await api.init();\n\n return new StellarApiConnection(api, fetchBlockBatches);\n }\n\n safeApi(height: number): SafeStellarProvider {\n //safe api not implemented\n throw new Error(`Not Implemented`);\n }\n\n async apiConnect(): Promise<void> {\n await this.unsafeApi.connect();\n }\n\n async apiDisconnect(): Promise<void> {\n await this.unsafeApi.disconnect();\n }\n\n async fetchBlocks(heights: number[]): Promise<IBlock<StellarBlockWrapper>[]> {\n const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);\n return blocks;\n }\n\n handleError = StellarApiConnection.handleError;\n\n static handleError(e: Error): ApiConnectionError {\n let formatted_error: ApiConnectionError;\n if (e.message.includes(`Timeout`)) {\n formatted_error = new TimeoutError(e);\n } else if (e.message.startsWith(`disconnected from `)) {\n formatted_error = new DisconnectionError(e);\n } else if (\n e.message.includes(`Rate Limit Exceeded`) ||\n e.message.includes('Too Many Requests')\n ) {\n formatted_error = new RateLimitError(e);\n } else if (e.message.includes(`limit must not exceed`)) {\n formatted_error = new LargeResponseError(e);\n } else {\n formatted_error = new ApiConnectionError(\n e.name,\n e.message,\n ApiErrorType.Default,\n );\n }\n return formatted_error;\n }\n}\n"]}
@@ -2,7 +2,6 @@
2
2
  // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- const event_emitter_1 = require("@nestjs/event-emitter");
6
5
  const node_core_1 = require("@subql/node-core");
7
6
  const api_connection_1 = require("./api.connection");
8
7
  const api_stellar_1 = require("./api.stellar");
@@ -30,12 +29,12 @@ describe('StellarApiConnection', () => {
30
29
  const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);
31
30
  beforeEach(async () => {
32
31
  sorobanApi = new soroban_server_1.SorobanServer(SOROBAN_ENDPOINT);
33
- unsafeApi = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new event_emitter_1.EventEmitter2(), sorobanApi);
32
+ unsafeApi = new api_stellar_1.StellarApi(HTTP_ENDPOINT, sorobanApi);
34
33
  await unsafeApi.init();
35
34
  apiConnection = new api_connection_1.StellarApiConnection(unsafeApi, fetchBlockBatches);
36
35
  });
37
36
  it('creates a connection', async () => {
38
- expect(await api_connection_1.StellarApiConnection.create(HTTP_ENDPOINT, fetchBlockBatches, new event_emitter_1.EventEmitter2(), sorobanApi)).toBeInstanceOf(api_connection_1.StellarApiConnection);
37
+ expect(await api_connection_1.StellarApiConnection.create(HTTP_ENDPOINT, fetchBlockBatches, sorobanApi)).toBeInstanceOf(api_connection_1.StellarApiConnection);
39
38
  });
40
39
  it('fetches blocks', async () => {
41
40
  const result = await apiConnection.fetchBlocks([1, 2]);
@@ -1 +1 @@
1
- {"version":3,"file":"api.connection.spec.js","sourceRoot":"","sources":["../../src/stellar/api.connection.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,gDAO0B;AAE1B,qDAAwD;AACxD,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,SAAqB,CAAC;IAC1B,IAAI,UAAyB,CAAC;IAC9B,MAAM,UAAU,GAA0B;QACxC;YACE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAA6B;YAChE,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAA6B;YAChE,YAAY,EAAE,EAAE;YACh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C,OAAO,CAAC,wBAAY,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n RateLimitError,\n TimeoutError,\n} from '@subql/node-core';\nimport { StellarBlock, StellarBlockWrapper } from '@subql/types-stellar';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\ndescribe('StellarApiConnection', () => {\n let apiConnection: StellarApiConnection;\n let unsafeApi: StellarApi;\n let sorobanApi: SorobanServer;\n const mockBlocks: StellarBlockWrapper[] = [\n {\n block: { sequence: 1, hash: 'hash1' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n {\n block: { sequence: 2, hash: 'hash2' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n ];\n\n const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);\n\n beforeEach(async () => {\n sorobanApi = new SorobanServer(SOROBAN_ENDPOINT);\n unsafeApi = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), sorobanApi);\n await unsafeApi.init();\n apiConnection = new StellarApiConnection(unsafeApi, fetchBlockBatches);\n });\n\n it('creates a connection', async () => {\n expect(\n await StellarApiConnection.create(\n HTTP_ENDPOINT,\n fetchBlockBatches,\n new EventEmitter2(),\n sorobanApi,\n ),\n ).toBeInstanceOf(StellarApiConnection);\n });\n\n it('fetches blocks', async () => {\n const result = await apiConnection.fetchBlocks([1, 2]);\n expect(result).toEqual(mockBlocks);\n expect(fetchBlockBatches).toHaveBeenCalledWith(unsafeApi, [1, 2]);\n });\n\n describe('Error handling', () => {\n it('handles timeout errors', () => {\n const error = new Error('Timeout');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(TimeoutError);\n });\n\n it('handles disconnection errors', () => {\n const error = new Error('disconnected from ');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(DisconnectionError);\n });\n\n it('handles rate limit errors', () => {\n const error = new Error('Rate Limit Exceeded');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(RateLimitError);\n });\n\n it('handles large response errors', () => {\n const error = new Error('limit must not exceed');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(LargeResponseError);\n });\n\n it('handles default errors', () => {\n const error = new Error('default error');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(ApiConnectionError);\n expect(handledError.errorType).toEqual(ApiErrorType.Default);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"api.connection.spec.js","sourceRoot":"","sources":["../../src/stellar/api.connection.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAO0B;AAE1B,qDAAwD;AACxD,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,SAAqB,CAAC;IAC1B,IAAI,UAAyB,CAAC;IAC9B,MAAM,UAAU,GAA0B;QACxC;YACE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAA6B;YAChE,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,I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C,OAAO,CAAC,wBAAY,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n ApiConnectionError,\n ApiErrorType,\n DisconnectionError,\n LargeResponseError,\n RateLimitError,\n TimeoutError,\n} from '@subql/node-core';\nimport { StellarBlock, StellarBlockWrapper } from '@subql/types-stellar';\nimport { StellarApiConnection } from './api.connection';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\ndescribe('StellarApiConnection', () => {\n let apiConnection: StellarApiConnection;\n let unsafeApi: StellarApi;\n let sorobanApi: SorobanServer;\n const mockBlocks: StellarBlockWrapper[] = [\n {\n block: { sequence: 1, hash: 'hash1' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n {\n block: { sequence: 2, hash: 'hash2' } as unknown as StellarBlock,\n transactions: [],\n operations: [],\n effects: [],\n },\n ];\n\n const fetchBlockBatches = jest.fn().mockResolvedValue(mockBlocks);\n\n beforeEach(async () => {\n sorobanApi = new SorobanServer(SOROBAN_ENDPOINT);\n unsafeApi = new StellarApi(HTTP_ENDPOINT, sorobanApi);\n await unsafeApi.init();\n apiConnection = new StellarApiConnection(unsafeApi, fetchBlockBatches);\n });\n\n it('creates a connection', async () => {\n expect(\n await StellarApiConnection.create(\n HTTP_ENDPOINT,\n fetchBlockBatches,\n sorobanApi,\n ),\n ).toBeInstanceOf(StellarApiConnection);\n });\n\n it('fetches blocks', async () => {\n const result = await apiConnection.fetchBlocks([1, 2]);\n expect(result).toEqual(mockBlocks);\n expect(fetchBlockBatches).toHaveBeenCalledWith(unsafeApi, [1, 2]);\n });\n\n describe('Error handling', () => {\n it('handles timeout errors', () => {\n const error = new Error('Timeout');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(TimeoutError);\n });\n\n it('handles disconnection errors', () => {\n const error = new Error('disconnected from ');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(DisconnectionError);\n });\n\n it('handles rate limit errors', () => {\n const error = new Error('Rate Limit Exceeded');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(RateLimitError);\n });\n\n it('handles large response errors', () => {\n const error = new Error('limit must not exceed');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(LargeResponseError);\n });\n\n it('handles default errors', () => {\n const error = new Error('default error');\n const handledError = StellarApiConnection.handleError(error);\n expect(handledError).toBeInstanceOf(ApiConnectionError);\n expect(handledError.errorType).toEqual(ApiErrorType.Default);\n });\n });\n});\n"]}
@@ -57,7 +57,7 @@ let StellarApiService = class StellarApiService extends node_core_1.ApiService {
57
57
  const sorobanClient = sorobanEndpoint
58
58
  ? new soroban_server_1.SorobanServer(sorobanEndpoint)
59
59
  : undefined;
60
- await this.createConnections(network, (endpoint, config) => api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, this.eventEmitter, sorobanClient, config));
60
+ await this.createConnections(network, (endpoint, config) => api_connection_1.StellarApiConnection.create(endpoint, this.fetchBlockBatches, sorobanClient, config));
61
61
  return this;
62
62
  }
63
63
  get api() {
@@ -1 +1 @@
1
- {"version":3,"file":"api.service.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AAKtD,gDAQ0B;AAO1B,kEAGsC;AACtC,qDAAwD;AAGxD,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAA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;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;AAxHY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;6CACJ,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAZb,iBAAiB,CAwH7B;AAxHY,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n StellarProjectNetwork,\n StellarProjectNetworkConfig,\n} from '@subql/common-stellar';\nimport {\n ApiService,\n ConnectionPoolService,\n getLogger,\n ProjectUpgradeService,\n IBlock,\n 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 sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint)\n : undefined;\n\n await this.createConnections(network, (endpoint, config) =>\n StellarApiConnection.create(\n endpoint,\n this.fetchBlockBatches,\n this.eventEmitter,\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,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,CAAC,CAAC;QALP,YAAO,GAAP,OAAO,CAAiB;QAM5D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,OAAoC,CAAC;QACzC,IAAI;YACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;SAChC;QAAC,OAAO,CAAC,EAAE;YACV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AO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAvHY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;6CACJ,iCAAqB;QAC9B,6BAAa;QACf,sBAAU;GAZb,iBAAiB,CAuH7B;AAvHY,8CAAiB","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { 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 sorobanClient = sorobanEndpoint\n ? new SorobanServer(sorobanEndpoint)\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 +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,yDAA2D;AAC3D,6CAAuC;AACvC,sDAAqD;AACrD,gDAA4E;AAC5E,gDAAmE;AACnE,qCAAwC;AACxC,mCAAqC;AAErC,+DAA0D;AAC1D,+CAA2C;AAG3C,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,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAA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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, delay, NodeConfig } from '@subql/node-core';\nimport { ConnectionPoolStateManager } from '@subql/node-core/dist';\nimport { GraphQLSchema } from 'graphql';\nimport { range, some } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiService } from './api.service.stellar';\nimport { StellarApi } from './api.stellar';\nimport { StellarBlockWrapped } from './block.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 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,yDAA2D;AAC3D,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,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,E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O,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { 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 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,4 +1,3 @@
1
- import { EventEmitter2 } from '@nestjs/event-emitter';
2
1
  import { Horizon } from '@stellar/stellar-sdk';
3
2
  import { IBlock } from '@subql/node-core';
4
3
  import { ApiWrapper, SorobanEvent, StellarBlockWrapper, IStellarEndpointConfig } from '@subql/types-stellar';
@@ -6,12 +5,10 @@ import SafeStellarProvider from './safe-api';
6
5
  import { SorobanServer } from './soroban.server';
7
6
  export declare class StellarApi implements ApiWrapper {
8
7
  private endpoint;
9
- private eventEmitter;
10
8
  private _sorobanClient?;
11
- private config?;
12
9
  private stellarClient;
13
10
  private chainId?;
14
- constructor(endpoint: string, eventEmitter: EventEmitter2, _sorobanClient?: SorobanServer | undefined, config?: IStellarEndpointConfig | undefined);
11
+ constructor(endpoint: string, _sorobanClient?: SorobanServer | undefined, config?: IStellarEndpointConfig);
15
12
  init(): Promise<void>;
16
13
  get sorobanClient(): SorobanServer;
17
14
  getFinalizedBlock(): Promise<Horizon.ServerApi.LedgerRecord>;
@@ -24,7 +21,6 @@ export declare class StellarApi implements ApiWrapper {
24
21
  private fetchTransactionsForLedger;
25
22
  private fetchOperationsForLedger;
26
23
  private fetchEffectsForLedger;
27
- private getTransactionApplicationOrder;
28
24
  private getOperationIndex;
29
25
  getAndWrapEvents(height: number): Promise<SorobanEvent[]>;
30
26
  private wrapEffectsForOperation;
@@ -13,22 +13,16 @@ const block_stellar_1 = require("../stellar/block.stellar");
13
13
  const safe_api_1 = __importDefault(require("./safe-api"));
14
14
  const stellar_server_1 = require("./stellar.server");
15
15
  const utils_stellar_1 = require("./utils.stellar");
16
- // eslint-disable-next-line @typescript-eslint/no-var-requires
17
- const { version: packageVersion } = require('../../package.json');
18
16
  const logger = (0, node_core_1.getLogger)('api.Stellar');
19
17
  class StellarApi {
20
18
  endpoint;
21
- eventEmitter;
22
19
  _sorobanClient;
23
- config;
24
20
  //private client: Server;
25
21
  stellarClient;
26
22
  chainId;
27
- constructor(endpoint, eventEmitter, _sorobanClient, config) {
23
+ constructor(endpoint, _sorobanClient, config) {
28
24
  this.endpoint = endpoint;
29
- this.eventEmitter = eventEmitter;
30
25
  this._sorobanClient = _sorobanClient;
31
- this.config = config;
32
26
  const { hostname, protocol, searchParams } = new URL(this.endpoint);
33
27
  const protocolStr = protocol.replace(':', '');
34
28
  logger.info(`Api host: ${hostname}, method: ${protocolStr}`);
@@ -106,15 +100,6 @@ class StellarApi {
106
100
  }
107
101
  return effects;
108
102
  }
109
- getTransactionApplicationOrder(eventId) {
110
- // Right shift the ID by 12 bits to exclude the Operation Index
111
- const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);
112
- // Create a mask for 20 bits to ignore the Ledger Sequence Number
113
- const mask = BigInt((1 << 20) - 1);
114
- // Apply bitwise AND operation with the mask to get the Transaction Application Order
115
- const transactionApplicationOrder = shiftedId & mask;
116
- return Number(transactionApplicationOrder);
117
- }
118
103
  getOperationIndex(id) {
119
104
  // Pick the first part of the ID before the '-' character
120
105
  const idPart = id.split('-')[0];
@@ -149,11 +134,14 @@ class StellarApi {
149
134
  operation: null,
150
135
  }));
151
136
  }
152
- wrapOperationsForTx(transactionId, applicationOrder, sequence, operationsForSequence, effectsForSequence, eventsForSequence) {
137
+ wrapOperationsForTx(transactionId, operationsForSequence, effectsForSequence, eventsForSequence) {
153
138
  const operations = operationsForSequence.filter((op) => op.transaction_hash === transactionId);
139
+ const events = eventsForSequence.filter((evt) => evt.txHash === transactionId);
140
+ // If there are soroban events then there should only be a single operation.
141
+ // This check is here in case there are furture changes to the network.
142
+ (0, assert_1.default)(events.length > 0 ? operations.length === 1 : true, 'Unable to assign events to multiple operations');
154
143
  return operations.map((op, index) => {
155
144
  const effects = this.wrapEffectsForOperation(index, effectsForSequence);
156
- const events = eventsForSequence.filter((event) => this.getTransactionApplicationOrder(event.id) === applicationOrder);
157
145
  const wrappedOp = {
158
146
  ...op,
159
147
  ledger: null,
@@ -170,7 +158,7 @@ class StellarApi {
170
158
  });
171
159
  }
172
160
  wrapTransactionsForLedger(sequence, transactions, operationsForSequence, effectsForSequence, eventsForSequence) {
173
- return transactions.map((tx, index) => {
161
+ return transactions.map((tx) => {
174
162
  const wrappedTx = {
175
163
  ...tx,
176
164
  ledger: null,
@@ -182,7 +170,7 @@ class StellarApi {
182
170
  const operations = this.wrapOperationsForTx(
183
171
  // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect
184
172
  // TransactionRecord extends Omit<HorizonApi.TransactionResponse, "created_at">
185
- tx.id, index + 1, sequence, operationsForSequence, effectsForSequence, eventsForSequence).map((op) => {
173
+ tx.id, operationsForSequence, effectsForSequence, eventsForSequence).map((op) => {
186
174
  op.transaction = clonedTx;
187
175
  op.effects = op.effects.map((effect) => {
188
176
  effect.transaction = clonedTx;
@@ -1 +1 @@
1
- {"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAG5B,gDAAqD;AAWrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAkD;AAElD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAOX;IACA;IACA;IACA;IATV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D,aAAa,EACb,aAAa,CAAC,YAAY,EAC1B,aAAa,CAAC,UAAU,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;AAxYD,gCAwYC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\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 { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId?: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private _sorobanClient?: SorobanServer,\n private config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: 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.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: 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 applicationOrder: number,\n sequence: number,\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 return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: Horizon.ServerApi.TransactionRecord[],\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e: 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,mDAAkD;AAElD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAOX;IACA;IAPV,yBAAyB;IACjB,aAAa,CAAgB;IAE7B,OAAO,CAAU;IAEzB,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;QAEpE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,aAAa,WAAW,EAAE,CAAC,CAAC;QAC7D,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE;YACrD,MAAM,OAAO,GAA2B;gBACtC,SAAS,EAAE,WAAW,KAAK,MAAM;gBACjC,OAAO,EAAE;oBACP,GAAG,MAAM,EAAE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D,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;SAC/E;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA7XD,gCA6XC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport 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 { 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\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: 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.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: 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"]}
@@ -2,7 +2,6 @@
2
2
  // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
3
3
  // SPDX-License-Identifier: GPL-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- const event_emitter_1 = require("@nestjs/event-emitter");
6
5
  const api_stellar_1 = require("./api.stellar");
7
6
  const soroban_server_1 = require("./soroban.server");
8
7
  const HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';
@@ -10,7 +9,7 @@ const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
10
9
  jest.setTimeout(60000);
11
10
  const prepareStellarApi = async function () {
12
11
  const soroban = new soroban_server_1.SorobanServer(SOROBAN_ENDPOINT);
13
- const api = new api_stellar_1.StellarApi(HTTP_ENDPOINT, new event_emitter_1.EventEmitter2(), soroban);
12
+ const api = new api_stellar_1.StellarApi(HTTP_ENDPOINT, soroban);
14
13
  await api.init();
15
14
  return api;
16
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,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OAAO,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,WAAW,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QAChD,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACxD,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YACzC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACF,UAAkB,CAAC,wBAAwB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC;YACtE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;SACrD,CAAC,CAAC;QACH,MAAM,MAAM,CAAE,UAAkB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACvE,kBAAkB,CACnB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.getHeader().blockHeight).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).chainId);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n\n it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /(Gone|Not Found)/,\n );\n });\n});\n"]}
1
+ {"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,wBAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,UAAsB,CAAC;IAE3B,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,UAAU,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CACrC,wCAAwC,CACzC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAA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CAAC,8BAA8B,CAAC,CAAC;QACxD,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YACzC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACF,UAAkB,CAAC,wBAAwB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC;YACtE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,sBAAsB,EAAE,EAAE;SACrD,CAAC,CAAC;QACH,MAAM,MAAM,CAAE,UAAkB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACvE,kBAAkB,CACnB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.getHeader().blockHeight).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).chainId);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n\n it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /(Gone|Not Found)/,\n );\n });\n});\n"]}