@subql/node-stellar 4.6.0 → 4.6.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":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,0DAa+B;AAC/B,gDAc0B;AAe1B,8DAA0D;AAE1D,4DAA+D;AAG/D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAUnC;IACW,WAAW,GAAG,4BAAW,CAAC;IAC1B,UAAU,GAAG,2BAAU,CAAC;IAElC,YACwB,UAAsB,EAC5C,UAAsB,EACtB,cAAsE,EACtE,kBAAsC,EACtC,gBAA0D,EAE1D,wBAAkD,EACpB,iBAAoC;QAElE,KAAK,CACH,UAAU,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,CAClB,CAAC;IACJ,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CACd,KAAkC,EAClC,WAAqC;QAErC,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,CACvD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CACzB,CAAC;IACJ,CAAC;IAED,4DAA4D;IACpD,KAAK,CAAC,MAAM,CAClB,KAA0B;QAE1B,wDAAwD;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,KAAK,CAAC,cAAc,CAC5B,EAAE,KAAK,EAAE,YAAY,EAAuB,EAC5C,WAA8B,EAC9B,KAAsD;QAEtD,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,WA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AE,CACF,mCAAmB,CAAC,wBAAwB,CAC1C,IAAI,EACJ,MAAM,EACN,EAAE,CAAC,OAAO,EAAE,OAAO,CACpB;IAEH,CAAC,mCAAkB,CAAC,OAAO,CAAC,EAAE,CAC5B,IAAmB,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-2025 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 DsProcessorService,\n DynamicDsService,\n UnfinalizedBlocksService,\n ProjectService,\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 { BlockchainService } from '../blockchain.service';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\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 @Inject('APIService') apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService<SafeStellarProvider | null, StellarApi>,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService<SubqlStellarDataSource>,\n @Inject('IUnfinalizedBlocksService')\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IBlockchainService') blockchainService: BlockchainService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n blockchainService,\n );\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
|
+
{"version":3,"file":"indexer.manager.js","sourceRoot":"","sources":["../../src/indexer/indexer.manager.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,0DAa+B;AAC/B,gDAa0B;AAe1B,8DAA0D;AAE1D,4DAA+D;AAG/D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,8BAUnC;IACW,WAAW,GAAG,4BAAW,CAAC;IAC1B,UAAU,GAAG,2BAAU,CAAC;IAElC,YACwB,UAAsB,EAC5C,UAAsB,EACtB,cAAsE,EACtE,kBAAsC,EACtC,gBAA0D,EAE1D,wBAAkD,EACpB,iBAAoC;QAElE,KAAK,CACH,UAAU,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,CAClB,CAAC;IACJ,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CACd,KAAkC,EAClC,WAAqC;QAErC,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,CACvD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CACzB,CAAC;IACJ,CAAC;IAED,4DAA4D;IACpD,KAAK,CAAC,MAAM,CAClB,KAA0B;QAE1B,wDAAwD;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,KAAK,CAAC,cAAc,CAC5B,EAAE,KAAK,EAAE,YAAY,EAAuB,EAC5C,WAA8B,EAC9B,KAAsD;QAEtD,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QAExD,K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1C,IAAI,EACJ,MAAM,EACN,EAAE,CAAC,OAAO,EAAE,OAAO,CACpB;IAEH,CAAC,mCAAkB,CAAC,OAAO,CAAC,EAAE,CAC5B,IAAmB,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-2025 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 DsProcessorService,\n DynamicDsService,\n UnfinalizedBlocksService,\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 { BlockchainService } from '../blockchain.service';\nimport { StellarApi } from '../stellar';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from '../stellar/safe-api';\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 @Inject('APIService') apiService: ApiService,\n nodeConfig: NodeConfig,\n sandboxService: SandboxService<SafeStellarProvider | null, StellarApi>,\n dsProcessorService: DsProcessorService,\n dynamicDsService: DynamicDsService<SubqlStellarDataSource>,\n @Inject('IUnfinalizedBlocksService')\n unfinalizedBlocksService: UnfinalizedBlocksService,\n @Inject('IBlockchainService') blockchainService: BlockchainService,\n ) {\n super(\n apiService,\n nodeConfig,\n sandboxService,\n dsProcessorService,\n dynamicDsService,\n unfinalizedBlocksService,\n FilterTypeMap,\n ProcessorTypeMap,\n blockchainService,\n );\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"]}
|
|
@@ -22,9 +22,8 @@ export declare class StellarApi implements ApiWrapper {
|
|
|
22
22
|
private fetchTransactionsForLedger;
|
|
23
23
|
private fetchOperationsForLedger;
|
|
24
24
|
private fetchEffectsForLedger;
|
|
25
|
-
private getOperationIndex;
|
|
26
25
|
getAndWrapEvents(height: number): Promise<SorobanEvent[]>;
|
|
27
|
-
private
|
|
26
|
+
private wrapEffect;
|
|
28
27
|
private wrapOperationsForTx;
|
|
29
28
|
private wrapTransactionsForLedger;
|
|
30
29
|
private fetchAndWrapLedger;
|
|
@@ -114,15 +114,6 @@ class StellarApi {
|
|
|
114
114
|
}
|
|
115
115
|
return effects;
|
|
116
116
|
}
|
|
117
|
-
getOperationIndex(id) {
|
|
118
|
-
// Pick the first part of the ID before the '-' character
|
|
119
|
-
const idPart = id.split('-')[0];
|
|
120
|
-
// Create a mask for 12 bits to isolate the Operation Index
|
|
121
|
-
const mask = BigInt((1 << 12) - 1);
|
|
122
|
-
// Apply bitwise AND operation with the mask to get the Operation Index
|
|
123
|
-
const operationIndex = BigInt(idPart) & mask;
|
|
124
|
-
return Number(operationIndex);
|
|
125
|
-
}
|
|
126
117
|
async getAndWrapEvents(height) {
|
|
127
118
|
const { events: events } = await this.sorobanClient.getEvents({
|
|
128
119
|
startLedger: height,
|
|
@@ -139,24 +130,21 @@ class StellarApi {
|
|
|
139
130
|
return wrappedEvent;
|
|
140
131
|
});
|
|
141
132
|
}
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
.filter((effect) => this.getOperationIndex(effect.id) === operationIndex)
|
|
145
|
-
.map((effect) => ({
|
|
133
|
+
wrapEffect(effect) {
|
|
134
|
+
return {
|
|
146
135
|
...effect,
|
|
147
136
|
ledger: null,
|
|
148
137
|
transaction: null,
|
|
149
138
|
operation: null,
|
|
150
|
-
}
|
|
139
|
+
};
|
|
151
140
|
}
|
|
152
|
-
wrapOperationsForTx(
|
|
153
|
-
const operations = operationsForSequence.filter((op) => op.transaction_hash === transactionId);
|
|
154
|
-
const events = eventsForSequence.filter((evt) => evt.txHash === transactionId);
|
|
141
|
+
wrapOperationsForTx(operations, effectsForSequence, events) {
|
|
155
142
|
// If there are soroban events then there should only be a single operation.
|
|
156
143
|
// This check is here in case there are furture changes to the network.
|
|
157
144
|
(0, assert_1.default)(events.length > 0 ? operations.length === 1 : true, 'Unable to assign events to multiple operations');
|
|
158
145
|
return operations.map((op, index) => {
|
|
159
|
-
const effects = this.
|
|
146
|
+
const effects = (effectsForSequence[op.id] ?? []).map(this.wrapEffect.bind(this));
|
|
147
|
+
// const effects = this.wrapEffectsForOperation(index, effectsForSequence);
|
|
160
148
|
const wrappedOp = {
|
|
161
149
|
...op,
|
|
162
150
|
ledger: null,
|
|
@@ -172,7 +160,7 @@ class StellarApi {
|
|
|
172
160
|
return wrappedOp;
|
|
173
161
|
});
|
|
174
162
|
}
|
|
175
|
-
wrapTransactionsForLedger(
|
|
163
|
+
wrapTransactionsForLedger(transactions, operationsForSequence, effectsForSequence, eventsForSequence) {
|
|
176
164
|
return transactions.map((tx) => {
|
|
177
165
|
const wrappedTx = {
|
|
178
166
|
...tx,
|
|
@@ -181,11 +169,31 @@ class StellarApi {
|
|
|
181
169
|
effects: [],
|
|
182
170
|
events: [],
|
|
183
171
|
};
|
|
172
|
+
// Effects grouped by the operation id
|
|
173
|
+
const groupedEffects = effectsForSequence.reduce((acc, item) => {
|
|
174
|
+
// BigInt conversion is for stripping leading 0s
|
|
175
|
+
const key = BigInt(item.id.split('-')[0]).toString();
|
|
176
|
+
acc[key] ??= [];
|
|
177
|
+
acc[key].push(item);
|
|
178
|
+
return acc;
|
|
179
|
+
}, {});
|
|
180
|
+
// Operations grouped by the transaction hash
|
|
181
|
+
const groupedOperations = operationsForSequence.reduce((acc, item) => {
|
|
182
|
+
acc[item.transaction_hash] ??= [];
|
|
183
|
+
acc[item.transaction_hash].push(item);
|
|
184
|
+
return acc;
|
|
185
|
+
}, {});
|
|
186
|
+
// Events grouped by the transaction hash
|
|
187
|
+
const groupedEvents = eventsForSequence.reduce((acc, item) => {
|
|
188
|
+
acc[item.txHash] ??= [];
|
|
189
|
+
acc[item.txHash].push(item);
|
|
190
|
+
return acc;
|
|
191
|
+
}, {});
|
|
184
192
|
const clonedTx = (0, lodash_1.cloneDeep)(wrappedTx);
|
|
185
193
|
const operations = this.wrapOperationsForTx(
|
|
186
194
|
// TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect
|
|
187
195
|
// TransactionRecord extends Omit<HorizonApi.TransactionResponse, "created_at">
|
|
188
|
-
tx.
|
|
196
|
+
groupedOperations[tx.hash] ?? [], groupedEffects, groupedEvents[tx.hash] ?? []).map((op) => {
|
|
189
197
|
op.transaction = clonedTx;
|
|
190
198
|
op.effects = op.effects.map((effect) => {
|
|
191
199
|
effect.transaction = clonedTx;
|
|
@@ -245,7 +253,7 @@ class StellarApi {
|
|
|
245
253
|
effects: [],
|
|
246
254
|
events: eventsForSequence,
|
|
247
255
|
};
|
|
248
|
-
const wrapperTxs = this.wrapTransactionsForLedger(
|
|
256
|
+
const wrapperTxs = this.wrapTransactionsForLedger(transactions, operations, effects, eventsForSequence);
|
|
249
257
|
const clonedLedger = (0, lodash_1.cloneDeep)(wrappedLedger);
|
|
250
258
|
wrapperTxs.forEach((tx) => {
|
|
251
259
|
tx.ledger = clonedLedger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAE5B,gDAAqD;AAWrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQX;IACA;IARV,yBAAyB;IACjB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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,CAAC;YAClD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA9YD,gCA8YC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { DEFAULT_PAGE_SIZE, formatBlockUtil } from './utils.stellar';\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId?: string;\n private pageLimit = DEFAULT_PAGE_SIZE;\n\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n this.pageLimit = config?.pageLimit || this.pageLimit;\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(\n `Api host: ${hostname}, method: ${protocolStr}, pageLimit: ${this.pageLimit}`,\n );\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Horizon.Server.Options = {\n allowHttp: protocolStr === 'http',\n headers: {\n ...config?.headers,\n },\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n get sorobanClient(): SorobanServer {\n assert(this._sorobanClient, 'Soraban client is not initialized');\n return this._sorobanClient;\n }\n\n async getFinalizedBlock(): Promise<Horizon.ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getChainId(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.TransactionRecord[]> {\n const txs: Horizon.ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api\n .transactions()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api\n .operations()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api\n .effects()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n limit: this.pageLimit,\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n const events = eventsForSequence.filter(\n (evt) => evt.txHash === transactionId,\n );\n\n // If there are soroban events then there should only be a single operation.\n // This check is here in case there are furture changes to the network.\n assert(\n events.length > 0 ? operations.length === 1 : true,\n 'Unable to assign events to multiple operations',\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: Horizon.ServerApi.TransactionRecord[],\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e: any) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as Horizon.ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return formatBlockUtil(wrappedLedgerInstance);\n }\n\n async fetchBlocks(\n bufferBlocks: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Horizon.Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(this.sorobanClient, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAE5B,gDAAqD;AAWrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQX;IACA;IARV,yBAAyB;IACjB,aAAa,CAAgB;IAE7B,OAAO,CAAU;IACjB,SAAS,GAAG,iCAAiB,CAAC;IAEtC,YACU,QAAgB,EAChB,cAA8B,EACtC,MAA+B;QAFvB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,mBAAc,GAAd,cAAc,CAAgB;QAGtC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;QAErD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CACT,aAAa,QAAQ,aAAa,WAAW,gBAAgB,IAAI,CAAC,SAAS,EAAE,CAC9E,CAAC;QACF,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YACtD,MAAM,OAAO,GAA2B;gBACtC,SAAS,EAAE,WAAW,KAAK,MAAM;gBACjC,OAAO,EAAE;oB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E,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,CAAC;YAClD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA9YD,gCA8YC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n IStellarEndpointConfig,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\nimport { DEFAULT_PAGE_SIZE, formatBlockUtil } from './utils.stellar';\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId?: string;\n private pageLimit = DEFAULT_PAGE_SIZE;\n\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n this.pageLimit = config?.pageLimit || this.pageLimit;\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(\n `Api host: ${hostname}, method: ${protocolStr}, pageLimit: ${this.pageLimit}`,\n );\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Horizon.Server.Options = {\n allowHttp: protocolStr === 'http',\n headers: {\n ...config?.headers,\n },\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n get sorobanClient(): SorobanServer {\n assert(this._sorobanClient, 'Soraban client is not initialized');\n return this._sorobanClient;\n }\n\n async getFinalizedBlock(): Promise<Horizon.ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getChainId(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.TransactionRecord[]> {\n const txs: Horizon.ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api\n .transactions()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api\n .operations()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n\n let effectsPage = await this.api\n .effects()\n .forLedger(sequence)\n .limit(this.pageLimit)\n .call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n limit: this.pageLimit,\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffect(effect: Horizon.ServerApi.EffectRecord): StellarEffect {\n return {\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n };\n }\n\n private wrapOperationsForTx(\n operations: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Record<string, Horizon.ServerApi.EffectRecord[]>,\n events: SorobanEvent[],\n ): StellarOperation[] {\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 = (effectsForSequence[op.id] ?? []).map(\n this.wrapEffect.bind(this),\n );\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 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 // Effects grouped by the operation id\n const groupedEffects = effectsForSequence.reduce((acc, item) => {\n // BigInt conversion is for stripping leading 0s\n const key = BigInt(item.id.split('-')[0]).toString();\n acc[key] ??= [];\n acc[key].push(item);\n\n return acc;\n }, {} as Record<string, Horizon.ServerApi.EffectRecord[]>);\n\n // Operations grouped by the transaction hash\n const groupedOperations = operationsForSequence.reduce((acc, item) => {\n acc[item.transaction_hash] ??= [];\n acc[item.transaction_hash].push(item);\n\n return acc;\n }, {} as Record<string, Horizon.ServerApi.OperationRecord[]>);\n\n // Events grouped by the transaction hash\n const groupedEvents = eventsForSequence.reduce((acc, item) => {\n acc[item.txHash] ??= [];\n acc[item.txHash].push(item);\n\n return acc;\n }, {} as Record<string, SorobanEvent[]>);\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 groupedOperations[tx.hash] ?? [],\n groupedEffects,\n groupedEvents[tx.hash] ?? [],\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 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"]}
|
package/package.json
CHANGED