@subql/node-stellar 6.0.1 → 6.0.2-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.
|
@@ -138,9 +138,13 @@ class StellarApi {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
wrapOperationsForTx(operations, effectsForSequence, events) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
const groupedEvts = events.reduce((acc, evt) => {
|
|
142
|
+
// Types are not correct, the evt also has a transactionIndex
|
|
143
|
+
const operationIndex = evt.operationIndex;
|
|
144
|
+
acc[operationIndex] ??= [];
|
|
145
|
+
acc[operationIndex].push(evt);
|
|
146
|
+
return acc;
|
|
147
|
+
}, {});
|
|
144
148
|
return operations.map((op, index) => {
|
|
145
149
|
const effects = (effectsForSequence[op.id] ?? []).map(this.wrapEffect.bind(this));
|
|
146
150
|
// const effects = this.wrapEffectsForOperation(index, effectsForSequence);
|
|
@@ -149,7 +153,7 @@ class StellarApi {
|
|
|
149
153
|
ledger: null,
|
|
150
154
|
transaction: null,
|
|
151
155
|
effects: [],
|
|
152
|
-
events,
|
|
156
|
+
events: groupedEvts[index] ?? [],
|
|
153
157
|
};
|
|
154
158
|
const clonedOp = (0, lodash_1.cloneDeep)(wrappedOp);
|
|
155
159
|
effects.forEach((effect) => {
|
|
@@ -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;AAUrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAOX;IACA;IAPF,aAAa,CAAgB;IAE7B,OAAO,CAAU;IACjB,SAAS,GAAG,iC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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;AA7YD,gCA6YC","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 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 {\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"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAE5B,gDAAqD;AAUrD,mCAAmC;AACnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAqE;AAErE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAOX;IACA;IAPF,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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AChF,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA/YD,gCA+YC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport { Horizon, rpc } from '@stellar/stellar-sdk';\nimport { getLogger, IBlock } from '@subql/node-core';\nimport {\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 {\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 const groupedEvts = events.reduce((acc, evt) => {\n // Types are not correct, the evt also has a transactionIndex\n const operationIndex = (evt as any).operationIndex as number;\n acc[operationIndex] ??= [];\n acc[operationIndex].push(evt);\n\n return acc;\n }, {} as Record<number, SorobanEvent[]>);\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: groupedEvts[index] ?? [],\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"]}
|
|
@@ -7,9 +7,9 @@ const soroban_server_1 = require("./soroban.server");
|
|
|
7
7
|
const HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';
|
|
8
8
|
const SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';
|
|
9
9
|
jest.setTimeout(60000);
|
|
10
|
-
const prepareStellarApi = async function () {
|
|
11
|
-
const soroban = new soroban_server_1.SorobanServer(
|
|
12
|
-
const api = new api_stellar_1.StellarApi(
|
|
10
|
+
const prepareStellarApi = async function (stellarEndpoint = HTTP_ENDPOINT, sorobanEndpoint = SOROBAN_ENDPOINT) {
|
|
11
|
+
const soroban = new soroban_server_1.SorobanServer(sorobanEndpoint);
|
|
12
|
+
const api = new api_stellar_1.StellarApi(stellarEndpoint, soroban);
|
|
13
13
|
await api.init();
|
|
14
14
|
return api;
|
|
15
15
|
};
|
|
@@ -74,5 +74,19 @@ describe('StellarApi', () => {
|
|
|
74
74
|
]);
|
|
75
75
|
await expect(stellarApi.fetchAndWrapLedger(100)).rejects.toThrow(/(Gone|Not Found)/);
|
|
76
76
|
});
|
|
77
|
+
it('handles a transaction with multiple operations and events', async () => {
|
|
78
|
+
const api = await prepareStellarApi('https://horizon-testnet.stellar.org', 'https://soroban-testnet.stellar.org');
|
|
79
|
+
const [block] = await api.fetchBlocks([466592]);
|
|
80
|
+
const tx = block.block.transactions.find((tx) => tx.hash ===
|
|
81
|
+
'7967828275a8ba2442a0d4d21e8052b77ec87e8601598173e8857ad96c135685');
|
|
82
|
+
expect(tx).toBeDefined();
|
|
83
|
+
expect(tx?.operations.length).toEqual(4);
|
|
84
|
+
expect(tx?.events.length).toEqual(2);
|
|
85
|
+
// Events should be correctly assigned to operations
|
|
86
|
+
expect(tx?.operations[0].events.length).toEqual(1);
|
|
87
|
+
expect(tx?.operations[1].events.length).toEqual(1);
|
|
88
|
+
expect(tx?.operations[2].events.length).toEqual(0);
|
|
89
|
+
expect(tx?.operations[3].events.length).toEqual(0);
|
|
90
|
+
});
|
|
77
91
|
});
|
|
78
92
|
//# sourceMappingURL=api.stellar.spec.js.map
|
|
@@ -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,+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;
|
|
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,WAC7B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CACjC,qCAAqC,EACrC,qCAAqC,CACtC,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QAEhD,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CACtC,CAAC,EAAE,EAAE,EAAE,CACL,EAAE,CAAC,IAAI;YACP,kEAAkE,CACrE,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAEzB,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAErC,oDAAoD;QACpD,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { 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 stellarEndpoint = HTTP_ENDPOINT,\n sorobanEndpoint = SOROBAN_ENDPOINT,\n) {\n const soroban = new SorobanServer(sorobanEndpoint);\n const api = new StellarApi(stellarEndpoint, 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 it('handles a transaction with multiple operations and events', async () => {\n const api = await prepareStellarApi(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n );\n\n const [block] = await api.fetchBlocks([466592]);\n\n const tx = block.block.transactions.find(\n (tx) =>\n tx.hash ===\n '7967828275a8ba2442a0d4d21e8052b77ec87e8601598173e8857ad96c135685',\n );\n\n expect(tx).toBeDefined();\n\n expect(tx?.operations.length).toEqual(4);\n expect(tx?.events.length).toEqual(2);\n\n // Events should be correctly assigned to operations\n expect(tx?.operations[0].events.length).toEqual(1);\n expect(tx?.operations[1].events.length).toEqual(1);\n expect(tx?.operations[2].events.length).toEqual(0);\n expect(tx?.operations[3].events.length).toEqual(0);\n });\n});\n"]}
|
package/package.json
CHANGED