@subql/node-stellar 3.4.3-1 → 3.4.3-2
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/stellar/api.stellar.js +8 -13
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/api.stellar.spec.js +10 -0
- package/dist/stellar/api.stellar.spec.js.map +1 -1
- package/dist/stellar/soroban.server.d.ts +0 -2
- package/dist/stellar/soroban.server.js +0 -8
- package/dist/stellar/soroban.server.js.map +1 -1
- package/package.json +2 -2
|
@@ -105,19 +105,7 @@ class StellarApi {
|
|
|
105
105
|
return Number(operationIndex);
|
|
106
106
|
}
|
|
107
107
|
async getAndWrapEvents(height) {
|
|
108
|
-
|
|
109
|
-
// We check if cached latestLedger behind height, if so get updated and check again.
|
|
110
|
-
if (!this.sorobanClient.latestLedger ||
|
|
111
|
-
this.sorobanClient.latestLedger < height) {
|
|
112
|
-
const latestLedger = (await this.sorobanClient.getLatestLedger())
|
|
113
|
-
.sequence;
|
|
114
|
-
this.sorobanClient.updateCacheLatestLedger(latestLedger);
|
|
115
|
-
if (this.sorobanClient.latestLedger < height) {
|
|
116
|
-
logger.warn(`Error: Unable to fetch Soroban events at block height ${height} because the start is after the newest ledger. The latest ledger on Soroban is at ${latestLedger}. Please check the Soroban node. Subquery will treat it as if there are no events for this height.`);
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const { events: events, latestLedger: latestLedger } = await this.sorobanClient.getEvents({
|
|
108
|
+
const { events: events } = await this.sorobanClient.getEvents({
|
|
121
109
|
startLedger: height,
|
|
122
110
|
filters: [],
|
|
123
111
|
});
|
|
@@ -188,6 +176,13 @@ class StellarApi {
|
|
|
188
176
|
eventsForSequence = await this.getAndWrapEvents(sequence);
|
|
189
177
|
}
|
|
190
178
|
catch (e) {
|
|
179
|
+
if (e.message === 'start is after newest ledger') {
|
|
180
|
+
const latestLedger = (await this.sorobanClient.getLatestLedger())
|
|
181
|
+
.sequence;
|
|
182
|
+
throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.
|
|
183
|
+
This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.
|
|
184
|
+
To resolve this issue, please check you endpoint node start height`);
|
|
185
|
+
}
|
|
191
186
|
if (e.message === 'start is before oldest ledger') {
|
|
192
187
|
throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.
|
|
193
188
|
This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAA6C;AAU7C,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AAEjD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAgB;QAErC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,aAAa,WAAW,EAAE,CAAC,CAAC;QAC7D,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE;YACrD,MAAM,O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C;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;AAtYD,gCAsYC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\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<StellarBlockWrapper> {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private genesisHash: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n // If soroban network the latest ledger height behind processing height (due to network reset)\n // We check if cached latestLedger behind height, if so get updated and check again.\n if (\n !this.sorobanClient.latestLedger ||\n this.sorobanClient.latestLedger < height\n ) {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n this.sorobanClient.updateCacheLatestLedger(latestLedger);\n if (this.sorobanClient.latestLedger < height) {\n logger.warn(\n `Error: Unable to fetch Soroban events at block height ${height} because the start is after the newest ledger. The latest ledger on Soroban is at ${latestLedger}. Please check the Soroban node. Subquery will treat it as if there are no events for this height.`,\n );\n return [];\n }\n }\n\n const { events: events, latestLedger: latestLedger } =\n await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<StellarBlockWrapper> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return wrappedLedgerInstance;\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<StellarBlockWrapper[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAA6C;AAU7C,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AAEjD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAgB;QAErC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAA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AQ,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;AA5XD,gCA4XC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n SorobanEvent,\n StellarBlock,\n StellarBlockWrapper,\n StellarEffect,\n StellarOperation,\n StellarTransaction,\n} from '@subql/types-stellar';\nimport { cloneDeep } from 'lodash';\nimport { Server, ServerApi } from 'stellar-sdk/lib/horizon';\nimport { StellarBlockWrapped } from '../stellar/block.stellar';\nimport SafeStellarProvider from './safe-api';\nimport { SorobanServer } from './soroban.server';\nimport { StellarServer } from './stellar.server';\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<StellarBlockWrapper> {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n private genesisHash: string;\n private name: string;\n\n constructor(\n private endpoint: string,\n private eventEmitter: EventEmitter2,\n private sorobanClient?: SorobanServer,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Server.Options = {\n allowHttp: protocolStr === 'http',\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n async getFinalizedBlock(): Promise<ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): string {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<ServerApi.TransactionRecord[]> {\n const txs: ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<ServerApi.OperationRecord[]> {\n const operations: ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<ServerApi.EffectRecord[]> {\n const effects: ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getTransactionApplicationOrder(eventId: string) {\n // Right shift the ID by 12 bits to exclude the Operation Index\n const shiftedId = BigInt(eventId.split('-')[0]) >> BigInt(12);\n\n // Create a mask for 20 bits to ignore the Ledger Sequence Number\n const mask = BigInt((1 << 20) - 1);\n\n // Apply bitwise AND operation with the mask to get the Transaction Application Order\n const transactionApplicationOrder = shiftedId & mask;\n return Number(transactionApplicationOrder);\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n applicationOrder: number,\n sequence: number,\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const events = eventsForSequence.filter(\n (event) =>\n this.getTransactionApplicationOrder(event.id) === applicationOrder,\n );\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: ServerApi.TransactionRecord[],\n operationsForSequence: ServerApi.OperationRecord[],\n effectsForSequence: ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx, index) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n index + 1,\n sequence,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<StellarBlockWrapper> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return wrappedLedgerInstance;\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<StellarBlockWrapper[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(null, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
@@ -65,5 +65,15 @@ describe('StellarApi', () => {
|
|
|
65
65
|
const specName = stellarApi.getSpecName();
|
|
66
66
|
expect(specName).toEqual('Stellar');
|
|
67
67
|
});
|
|
68
|
+
it('handleError - soroban node been reset', async () => {
|
|
69
|
+
const error = new Error('start is after newest ledger');
|
|
70
|
+
stellarApi.getAndWrapEvents = jest.fn(() => {
|
|
71
|
+
throw new Error('start is after newest ledger');
|
|
72
|
+
});
|
|
73
|
+
stellarApi.fetchOperationsForLedger = jest.fn((seq) => [
|
|
74
|
+
{ type: { toString: () => 'invoke_host_function' } },
|
|
75
|
+
]);
|
|
76
|
+
await expect(stellarApi.fetchAndWrapLedger(100)).rejects.toThrow(/access a ledger that is after the latest ledger number/);
|
|
77
|
+
});
|
|
68
78
|
});
|
|
69
79
|
//# 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,iDAA8C;AAC9C,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IA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AI,CAAC,CAAC;IACzD,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;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.block.sequence).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).name);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,iDAA8C;AAC9C,+CAA2C;AAC3C,qDAAiD;AAEjD,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,MAAM,iBAAiB,GAAG,KAAK;IAC7B,MAAM,OAAO,GAAG,IAAI,8BAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,wBAAU,CAAC,aAAa,EAAE,IAAI,6BAAa,EAAE,EAAE,OAAO,CAAC,CAAC;IACxE,MAAM,GAAG,CAAC,IAAI,EAAE,C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AAU,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,wDAAwD,CACzD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { StellarApi } from './api.stellar';\nimport { SorobanServer } from './soroban.server';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\njest.setTimeout(60000);\n\nconst prepareStellarApi = async function () {\n const soroban = new SorobanServer(SOROBAN_ENDPOINT);\n const api = new StellarApi(HTTP_ENDPOINT, new EventEmitter2(), soroban);\n await api.init();\n return api;\n};\n\ndescribe('StellarApi', () => {\n let stellarApi: StellarApi;\n\n beforeEach(async () => {\n stellarApi = await prepareStellarApi();\n });\n\n it('should initialize chainId', () => {\n expect(stellarApi.getChainId()).toEqual(\n 'Test SDF Future Network ; October 2022',\n );\n });\n\n it('should get finalized block height', async () => {\n const height = await stellarApi.getFinalizedBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should get best block height', async () => {\n const height = await stellarApi.getBestBlockHeight();\n expect(height).not.toBeNaN();\n expect(height).toBeGreaterThan(0);\n });\n\n it('should fetch block', async () => {\n const latestHeight = await stellarApi.getFinalizedBlockHeight();\n const block = (await stellarApi.fetchBlocks([latestHeight]))[0];\n expect(block.block.sequence).toEqual(latestHeight);\n });\n\n it('should throw on calling connect', async () => {\n await expect(stellarApi.connect()).rejects.toThrow('Not implemented');\n });\n\n it('should throw on calling disconnect', async () => {\n await expect(stellarApi.disconnect()).rejects.toThrow('Not implemented');\n });\n\n it('handleError - pruned node errors', () => {\n const error = new Error('start is before oldest ledger');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled.message).toContain(\n 'The requested ledger number 1000 is not available on the current blockchain node',\n );\n });\n\n it('handleError - non pruned node errors should return the same error', () => {\n const error = new Error('Generic error');\n const handled = stellarApi.handleError(error, 1000);\n expect(handled).toBe(error);\n });\n\n it('should get runtime chain', () => {\n const runtimeChain = stellarApi.getRuntimeChain();\n expect(runtimeChain).toEqual((stellarApi as any).name);\n });\n\n it('should return chainId for genesis hash', () => {\n const genesisHash = stellarApi.getGenesisHash();\n expect(genesisHash).toEqual(stellarApi.getChainId());\n });\n\n it('should get spec name', () => {\n const specName = stellarApi.getSpecName();\n expect(specName).toEqual('Stellar');\n });\n\n it('handleError - soroban node been reset', async () => {\n const error = new Error('start is after newest ledger');\n stellarApi.getAndWrapEvents = jest.fn(() => {\n throw new Error('start is after newest ledger');\n });\n (stellarApi as any).fetchOperationsForLedger = jest.fn((seq: number) => [\n { type: { toString: () => 'invoke_host_function' } },\n ]);\n await expect((stellarApi as any).fetchAndWrapLedger(100)).rejects.toThrow(\n /access a ledger that is after the latest ledger number/,\n );\n });\n});\n"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Server, SorobanRpc } from 'soroban-client';
|
|
2
2
|
export declare class SorobanServer extends Server {
|
|
3
3
|
private eventsCache;
|
|
4
|
-
latestLedger?: number;
|
|
5
4
|
private fetchEventsForSequence;
|
|
6
5
|
private updateEventCache;
|
|
7
|
-
updateCacheLatestLedger(latestLedger: number): void;
|
|
8
6
|
getEvents(request: Server.GetEventsRequest): Promise<SorobanRpc.GetEventsResponse>;
|
|
9
7
|
}
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.SorobanServer = void 0;
|
|
6
|
-
const node_core_1 = require("@subql/node-core");
|
|
7
6
|
const lodash_1 = require("lodash");
|
|
8
7
|
const soroban_client_1 = require("soroban-client");
|
|
9
|
-
const logger = (0, node_core_1.getLogger)('stellar-server');
|
|
10
8
|
const DEFAULT_PAGE_SIZE = 100;
|
|
11
9
|
class SorobanServer extends soroban_client_1.Server {
|
|
12
10
|
constructor() {
|
|
@@ -60,14 +58,8 @@ class SorobanServer extends soroban_client_1.Server {
|
|
|
60
58
|
if (!eventExists) {
|
|
61
59
|
this.eventsCache[ledger].events.push(event);
|
|
62
60
|
}
|
|
63
|
-
this.updateCacheLatestLedger(response.latestLedger);
|
|
64
61
|
});
|
|
65
62
|
}
|
|
66
|
-
updateCacheLatestLedger(latestLedger) {
|
|
67
|
-
if (!this.latestLedger || this.latestLedger < latestLedger) {
|
|
68
|
-
this.latestLedger = latestLedger;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
63
|
async getEvents(request) {
|
|
72
64
|
const sequence = request.startLedger;
|
|
73
65
|
if (this.eventsCache[sequence]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;
|
|
1
|
+
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,mCAAgD;AAChD,mDAAoD;AAEpD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAa,aAAc,SAAQ,uBAAM;IAAzC;;QACU,gBAAW,GAAoD,EAAE,CAAC;IA6F5E,CAAC;IA3FS,KAAK,CAAC,sBAAsB,CAClC,QAAgB,EAChB,OAAgC,EAChC,YAAuC,EAAE;;QAKzC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAEhD,4EAA4E;QAC5E,MAAM,aAAa,GAAG,IAAA,gBAAO,EAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CACvD,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,CACvD,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,aAAa,GAAG,IAAA,gBAAO,EAAC,aAAa,CAAC,aAAa,CAAC,CAAC;QAEzD,0EAA0E;QAC1E,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE3C,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,EAAE;YACzB,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,iBAAiB,EAAE;gBAChD,MAAM,YAAY,GAAG,IAAA,aAAI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,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG;oBACzB,MAAM,EAAE,EAAE;iBACqB,CAAC;aACnC;YACD,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CACtD,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CACjD,CAAC;YACF,IAAI,CAAC,WAAW,EAAE;gBAChB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC7C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CACb,OAAgC;QAEhC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;QAErC,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;YAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC;SACrB;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAExD,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;CACF;AA9FD,sCA8FC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { SorobanRpcEventResponse } from '@subql/types-stellar';\nimport { compact, groupBy, last } from 'lodash';\nimport { Server, SorobanRpc } from 'soroban-client';\n\nconst DEFAULT_PAGE_SIZE = 100;\n\nexport class SorobanServer extends Server {\n private eventsCache: { [key: number]: SorobanRpc.GetEventsResponse } = {};\n\n private async fetchEventsForSequence(\n sequence: number,\n request: Server.GetEventsRequest,\n accEvents: SorobanRpcEventResponse[] = [],\n ): Promise<{\n events: SorobanRpc.GetEventsResponse;\n eventsToCache: SorobanRpc.GetEventsResponse;\n }> {\n const response = await super.getEvents(request);\n\n // Separate the events for the current sequence and the subsequent sequences\n const groupedEvents = groupBy(response.events, (event) =>\n event.ledger === sequence ? 'events' : 'eventsToCache',\n );\n const events = compact(groupedEvents.events);\n let eventsToCache = compact(groupedEvents.eventsToCache);\n\n // Update the accumulated events with the events from the current sequence\n const newEvents = accEvents.concat(events);\n\n if (eventsToCache?.length) {\n if (response.events.length === DEFAULT_PAGE_SIZE) {\n const lastSequence = last(response.events).ledger;\n eventsToCache = eventsToCache.filter(\n (event) => event.ledger !== lastSequence,\n );\n }\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: {\n events: eventsToCache,\n latestLedger: response.latestLedger,\n },\n };\n }\n\n if (response.events.length < DEFAULT_PAGE_SIZE) {\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: { events: [], latestLedger: response.latestLedger },\n };\n }\n\n // Prepare the next request\n const nextRequest = {\n ...request,\n cursor: response.events[response.events.length - 1]?.pagingToken,\n startLedger: undefined,\n };\n\n // Continue fetching events for the sequence\n return this.fetchEventsForSequence(sequence, nextRequest, newEvents);\n }\n\n private updateEventCache(\n response: SorobanRpc.GetEventsResponse,\n ignoreHeight?: number,\n ): void {\n response.events.forEach((event) => {\n if (ignoreHeight && ignoreHeight === event.ledger) return;\n const ledger = event.ledger;\n if (!this.eventsCache[ledger]) {\n this.eventsCache[ledger] = {\n events: [],\n } as SorobanRpc.GetEventsResponse;\n }\n const eventExists = this.eventsCache[ledger].events.some(\n (existingEvent) => existingEvent.id === event.id,\n );\n if (!eventExists) {\n this.eventsCache[ledger].events.push(event);\n }\n });\n }\n\n async getEvents(\n request: Server.GetEventsRequest,\n ): Promise<SorobanRpc.GetEventsResponse> {\n const sequence = request.startLedger;\n\n if (this.eventsCache[sequence]) {\n const cachedEvents = this.eventsCache[sequence];\n delete this.eventsCache[sequence];\n return cachedEvents;\n }\n\n const response = await this.fetchEventsForSequence(sequence, request);\n this.updateEventCache(response.eventsToCache, sequence);\n\n return response.events;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subql/node-stellar",
|
|
3
|
-
"version": "3.4.3-
|
|
3
|
+
"version": "3.4.3-2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Ian He",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"/dist",
|
|
67
67
|
"/bin"
|
|
68
68
|
],
|
|
69
|
-
"stableVersion": "3.4.3-
|
|
69
|
+
"stableVersion": "3.4.3-1"
|
|
70
70
|
}
|