@subql/node-stellar 4.3.1-2 → 4.4.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.
- package/CHANGELOG.md +12 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/stellar/api.stellar.d.ts +1 -0
- package/dist/stellar/api.stellar.js +19 -4
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/soroban.server.js +4 -3
- package/dist/stellar/soroban.server.js.map +1 -1
- package/dist/stellar/utils.stellar.d.ts +1 -0
- package/dist/stellar/utils.stellar.js +2 -1
- package/dist/stellar/utils.stellar.js.map +1 -1
- package/package.json +4 -4
|
@@ -8,6 +8,7 @@ export declare class StellarApi implements ApiWrapper {
|
|
|
8
8
|
private _sorobanClient?;
|
|
9
9
|
private stellarClient;
|
|
10
10
|
private chainId?;
|
|
11
|
+
private pageLimit;
|
|
11
12
|
constructor(endpoint: string, _sorobanClient?: SorobanServer | undefined, config?: IStellarEndpointConfig);
|
|
12
13
|
init(): Promise<void>;
|
|
13
14
|
get sorobanClient(): SorobanServer;
|
|
@@ -20,12 +20,14 @@ class StellarApi {
|
|
|
20
20
|
//private client: Server;
|
|
21
21
|
stellarClient;
|
|
22
22
|
chainId;
|
|
23
|
+
pageLimit = utils_stellar_1.DEFAULT_PAGE_SIZE;
|
|
23
24
|
constructor(endpoint, _sorobanClient, config) {
|
|
24
25
|
this.endpoint = endpoint;
|
|
25
26
|
this._sorobanClient = _sorobanClient;
|
|
26
27
|
const { hostname, protocol, searchParams } = new URL(this.endpoint);
|
|
28
|
+
this.pageLimit = config?.pageLimit || this.pageLimit;
|
|
27
29
|
const protocolStr = protocol.replace(':', '');
|
|
28
|
-
logger.info(`Api host: ${hostname}, method: ${protocolStr}`);
|
|
30
|
+
logger.info(`Api host: ${hostname}, method: ${protocolStr}, pageLimit: ${this.pageLimit}`);
|
|
29
31
|
if (protocolStr === 'https' || protocolStr === 'http') {
|
|
30
32
|
const options = {
|
|
31
33
|
allowHttp: protocolStr === 'http',
|
|
@@ -75,7 +77,11 @@ class StellarApi {
|
|
|
75
77
|
}
|
|
76
78
|
async fetchTransactionsForLedger(sequence) {
|
|
77
79
|
const txs = [];
|
|
78
|
-
let txsPage = await this.api
|
|
80
|
+
let txsPage = await this.api
|
|
81
|
+
.transactions()
|
|
82
|
+
.forLedger(sequence)
|
|
83
|
+
.limit(this.pageLimit)
|
|
84
|
+
.call();
|
|
79
85
|
while (txsPage.records.length !== 0) {
|
|
80
86
|
txs.push(...txsPage.records);
|
|
81
87
|
txsPage = await txsPage.next();
|
|
@@ -84,7 +90,11 @@ class StellarApi {
|
|
|
84
90
|
}
|
|
85
91
|
async fetchOperationsForLedger(sequence) {
|
|
86
92
|
const operations = [];
|
|
87
|
-
let operationsPage = await this.api
|
|
93
|
+
let operationsPage = await this.api
|
|
94
|
+
.operations()
|
|
95
|
+
.forLedger(sequence)
|
|
96
|
+
.limit(this.pageLimit)
|
|
97
|
+
.call();
|
|
88
98
|
while (operationsPage.records.length !== 0) {
|
|
89
99
|
operations.push(...operationsPage.records);
|
|
90
100
|
operationsPage = await operationsPage.next();
|
|
@@ -93,7 +103,11 @@ class StellarApi {
|
|
|
93
103
|
}
|
|
94
104
|
async fetchEffectsForLedger(sequence) {
|
|
95
105
|
const effects = [];
|
|
96
|
-
let effectsPage = await this.api
|
|
106
|
+
let effectsPage = await this.api
|
|
107
|
+
.effects()
|
|
108
|
+
.forLedger(sequence)
|
|
109
|
+
.limit(this.pageLimit)
|
|
110
|
+
.call();
|
|
97
111
|
while (effectsPage.records.length !== 0) {
|
|
98
112
|
effects.push(...effectsPage.records);
|
|
99
113
|
effectsPage = await effectsPage.next();
|
|
@@ -113,6 +127,7 @@ class StellarApi {
|
|
|
113
127
|
const { events: events } = await this.sorobanClient.getEvents({
|
|
114
128
|
startLedger: height,
|
|
115
129
|
filters: [],
|
|
130
|
+
limit: this.pageLimit,
|
|
116
131
|
});
|
|
117
132
|
return events.map((event) => {
|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Aa,CAAC,UAAU,EACxB,aAAa,CAAC,OAAO,EACrB,aAAa,CAAC,MAAM,CACrB,CAAC;QAEF,OAAO,IAAA,+BAAe,EAAC,qBAAqB,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,WAAW,CACf,YAAsB;QAEtB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,YAAY,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAClE,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,UAAU,CAAC,WAAmB;QAC5B,8BAA8B;QAC9B,OAAO,IAAI,kBAAmB,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,WAAW,CAAC,CAAQ,EAAE,MAAc;QAClC,IAAI,CAAC,CAAC,OAAO,KAAK,+BAA+B,EAAE;YACjD,OAAO,IAAI,KAAK,CAAC,+BAA+B,MAAM;;;;kFAIsB,CAAC,CAAC;SAC/E;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA7XD,gCA6XC","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 { formatBlockUtil } from './utils.stellar';\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId?: string;\n\n constructor(\n private endpoint: string,\n private _sorobanClient?: SorobanServer,\n config?: IStellarEndpointConfig,\n ) {\n const { hostname, protocol, searchParams } = new URL(this.endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options: Horizon.Server.Options = {\n allowHttp: protocolStr === 'http',\n headers: {\n ...config?.headers,\n },\n };\n\n this.stellarClient = new StellarServer(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n //need archive node for genesis hash\n //const genesisLedger = (await this.stellarClient.ledgers().ledger(1).call()).records[0];\n this.chainId = (await this.stellarClient.getNetwork()).network_passphrase;\n //this.genesisHash = genesisLedger.hash;\n }\n\n get sorobanClient(): SorobanServer {\n assert(this._sorobanClient, 'Soraban client is not initialized');\n return this._sorobanClient;\n }\n\n async getFinalizedBlock(): Promise<Horizon.ServerApi.LedgerRecord> {\n return (await this.stellarClient.ledgers().order('desc').call()).records[0];\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).sequence;\n }\n\n async getBestBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlockHeight()) + 1;\n }\n\n getRuntimeChain(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getChainId(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getSpecName(): string {\n return 'Stellar';\n }\n\n private async fetchTransactionsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.TransactionRecord[]> {\n const txs: Horizon.ServerApi.TransactionRecord[] = [];\n let txsPage = await this.api.transactions().forLedger(sequence).call();\n while (txsPage.records.length !== 0) {\n txs.push(...txsPage.records);\n txsPage = await txsPage.next();\n }\n\n return txs;\n }\n\n private async fetchOperationsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.OperationRecord[]> {\n const operations: Horizon.ServerApi.OperationRecord[] = [];\n let operationsPage = await this.api.operations().forLedger(sequence).call();\n while (operationsPage.records.length !== 0) {\n operations.push(...operationsPage.records);\n operationsPage = await operationsPage.next();\n }\n\n return operations;\n }\n\n private async fetchEffectsForLedger(\n sequence: number,\n ): Promise<Horizon.ServerApi.EffectRecord[]> {\n const effects: Horizon.ServerApi.EffectRecord[] = [];\n let effectsPage = await this.api.effects().forLedger(sequence).call();\n while (effectsPage.records.length !== 0) {\n effects.push(...effectsPage.records);\n effectsPage = await effectsPage.next();\n }\n\n return effects;\n }\n\n private getOperationIndex(id: string) {\n // Pick the first part of the ID before the '-' character\n const idPart = id.split('-')[0];\n\n // Create a mask for 12 bits to isolate the Operation Index\n const mask = BigInt((1 << 12) - 1);\n\n // Apply bitwise AND operation with the mask to get the Operation Index\n const operationIndex = BigInt(idPart) & mask;\n\n return Number(operationIndex);\n }\n\n async getAndWrapEvents(height: number): Promise<SorobanEvent[]> {\n const { events: events } = await this.sorobanClient.getEvents({\n startLedger: height,\n filters: [],\n });\n return events.map((event) => {\n const wrappedEvent = {\n ...event,\n ledger: null,\n transaction: null,\n operation: null,\n } as SorobanEvent;\n\n return wrappedEvent;\n });\n }\n\n private wrapEffectsForOperation(\n operationIndex: number,\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n ): StellarEffect[] {\n return effectsForSequence\n .filter((effect) => this.getOperationIndex(effect.id) === operationIndex)\n .map((effect) => ({\n ...effect,\n ledger: null,\n transaction: null,\n operation: null,\n }));\n }\n\n private wrapOperationsForTx(\n transactionId: string,\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarOperation[] {\n const operations = operationsForSequence.filter(\n (op) => op.transaction_hash === transactionId,\n );\n\n const events = eventsForSequence.filter(\n (evt) => evt.txHash === transactionId,\n );\n\n // If there are soroban events then there should only be a single operation.\n // This check is here in case there are furture changes to the network.\n assert(\n events.length > 0 ? operations.length === 1 : true,\n 'Unable to assign events to multiple operations',\n );\n\n return operations.map((op, index) => {\n const effects = this.wrapEffectsForOperation(index, effectsForSequence);\n\n const wrappedOp: StellarOperation = {\n ...op,\n ledger: null,\n transaction: null,\n effects: [],\n events,\n };\n\n const clonedOp = cloneDeep(wrappedOp);\n\n effects.forEach((effect) => {\n effect.operation = clonedOp;\n wrappedOp.effects.push(effect);\n });\n\n return wrappedOp;\n });\n }\n\n private wrapTransactionsForLedger(\n sequence: number,\n transactions: Horizon.ServerApi.TransactionRecord[],\n operationsForSequence: Horizon.ServerApi.OperationRecord[],\n effectsForSequence: Horizon.ServerApi.EffectRecord[],\n eventsForSequence: SorobanEvent[],\n ): StellarTransaction[] {\n return transactions.map((tx) => {\n const wrappedTx: StellarTransaction = {\n ...tx,\n ledger: null,\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: [] as SorobanEvent[],\n };\n\n const clonedTx = cloneDeep(wrappedTx);\n const operations = this.wrapOperationsForTx(\n // TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect\n // TransactionRecord extends Omit<HorizonApi.TransactionResponse, \"created_at\">\n (tx as any).id,\n operationsForSequence,\n effectsForSequence,\n eventsForSequence,\n ).map((op) => {\n op.transaction = clonedTx;\n op.effects = op.effects.map((effect) => {\n effect.transaction = clonedTx;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.transaction = clonedTx;\n return event;\n });\n return op;\n });\n\n wrappedTx.operations.push(...operations);\n operations.forEach((op) => {\n wrappedTx.effects.push(...op.effects);\n wrappedTx.events.push(...op.events);\n });\n\n return wrappedTx;\n });\n }\n\n private async fetchAndWrapLedger(\n sequence: number,\n ): Promise<IBlock<StellarBlockWrapper>> {\n const [ledger, transactions, operations, effects] = await Promise.all([\n this.api.ledgers().ledger(sequence).call(),\n this.fetchTransactionsForLedger(sequence),\n this.fetchOperationsForLedger(sequence),\n this.fetchEffectsForLedger(sequence),\n ]);\n\n let eventsForSequence: SorobanEvent[] = [];\n\n //check if there is InvokeHostFunctionOp operation\n //If yes then, there are soroban transactions and we should we fetch soroban events\n const hasInvokeHostFunctionOp = operations.some(\n (op) => op.type.toString() === 'invoke_host_function',\n );\n\n if (this.sorobanClient && hasInvokeHostFunctionOp) {\n try {\n eventsForSequence = await this.getAndWrapEvents(sequence);\n } catch (e: any) {\n if (e.message === 'start is after newest ledger') {\n const latestLedger = (await this.sorobanClient.getLatestLedger())\n .sequence;\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is after the latest ledger number ${latestLedger} stored in this node.\n To resolve this issue, please check you endpoint node start height`);\n }\n\n if (e.message === 'start is before oldest ledger') {\n throw new Error(`The requested events for ledger number ${sequence} is not available on the current soroban node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n throw e;\n }\n }\n\n const wrappedLedger: StellarBlock = {\n ...(ledger as unknown as Horizon.ServerApi.LedgerRecord),\n transactions: [] as StellarTransaction[],\n operations: [] as StellarOperation[],\n effects: [] as StellarEffect[],\n events: eventsForSequence,\n };\n\n const wrapperTxs = this.wrapTransactionsForLedger(\n sequence,\n transactions,\n operations,\n effects,\n eventsForSequence,\n );\n\n const clonedLedger = cloneDeep(wrappedLedger);\n\n wrapperTxs.forEach((tx) => {\n tx.ledger = clonedLedger;\n tx.operations = tx.operations.map((op) => {\n op.ledger = clonedLedger;\n op.effects = op.effects.map((effect) => {\n effect.ledger = clonedLedger;\n return effect;\n });\n op.events = op.events.map((event) => {\n event.ledger = clonedLedger;\n return event;\n });\n return op;\n });\n\n wrappedLedger.transactions.push(tx);\n wrappedLedger.operations.push(...tx.operations);\n\n tx.operations.forEach((op) => {\n wrappedLedger.effects.push(...op.effects);\n });\n });\n\n const wrappedLedgerInstance = new StellarBlockWrapped(\n wrappedLedger,\n wrappedLedger.transactions,\n wrappedLedger.operations,\n wrappedLedger.effects,\n wrappedLedger.events,\n );\n\n return formatBlockUtil(wrappedLedgerInstance);\n }\n\n async fetchBlocks(\n bufferBlocks: number[],\n ): Promise<IBlock<StellarBlockWrapper>[]> {\n const ledgers = await Promise.all(\n bufferBlocks.map((sequence) => this.fetchAndWrapLedger(sequence)),\n );\n return ledgers;\n }\n\n get api(): Horizon.Server {\n return this.stellarClient;\n }\n\n getSafeApi(blockHeight: number): SafeStellarProvider {\n //safe api not implemented yet\n return new SafeStellarProvider(this.sorobanClient, blockHeight);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Stellar API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n logger.error('Stellar API disconnect is not implemented');\n throw new Error('Not implemented');\n }\n\n handleError(e: Error, height: number): Error {\n if (e.message === 'start is before oldest ledger') {\n return new Error(`The requested ledger number ${height} is not available on the current blockchain node.\n This is because you're trying to access a ledger that is older than the oldest ledger stored in this node.\n To resolve this issue, you can either:\n 1. Increase the start ledger to a more recent one, or\n 2. Connect to a different node that might have a longer history of ledgers.`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":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ED,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"]}
|
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.SorobanServer = void 0;
|
|
6
6
|
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
|
-
const
|
|
8
|
+
const utils_stellar_1 = require("./utils.stellar");
|
|
9
9
|
class SorobanServer extends stellar_sdk_1.rpc.Server {
|
|
10
10
|
eventsCache = {};
|
|
11
11
|
async fetchEventsForSequence(sequence, request, accEvents = []) {
|
|
12
|
+
const pageLimit = request.limit ?? utils_stellar_1.DEFAULT_PAGE_SIZE;
|
|
12
13
|
const response = await super.getEvents(request);
|
|
13
14
|
// Separate the events for the current sequence and the subsequent sequences
|
|
14
15
|
const groupedEvents = (0, lodash_1.groupBy)(response.events, (event) => event.ledger === sequence ? 'events' : 'eventsToCache');
|
|
@@ -17,7 +18,7 @@ class SorobanServer extends stellar_sdk_1.rpc.Server {
|
|
|
17
18
|
// Update the accumulated events with the events from the current sequence
|
|
18
19
|
const newEvents = accEvents.concat(events);
|
|
19
20
|
if (eventsToCache?.length) {
|
|
20
|
-
if (response.events.length ===
|
|
21
|
+
if (response.events.length === pageLimit) {
|
|
21
22
|
const lastSequence = (0, lodash_1.last)(response.events).ledger;
|
|
22
23
|
eventsToCache = eventsToCache.filter((event) => event.ledger !== lastSequence);
|
|
23
24
|
}
|
|
@@ -29,7 +30,7 @@ class SorobanServer extends stellar_sdk_1.rpc.Server {
|
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
|
-
if (response.events.length <
|
|
33
|
+
if (response.events.length < pageLimit) {
|
|
33
34
|
return {
|
|
34
35
|
events: { events: newEvents, latestLedger: response.latestLedger },
|
|
35
36
|
eventsToCache: { events: [], latestLedger: response.latestLedger },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,sDAA2C;AAE3C,mCAAgD;
|
|
1
|
+
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,sDAA2C;AAE3C,mCAAgD;AAChD,mDAAoD;AAOpD,MAAa,aAAc,SAAQ,iBAAG,CAAC,MAAM;IACnC,WAAW,GAAiD,EAAE,CAAC;IAE/D,KAAK,CAAC,sBAAsB,CAClC,QAAgB,EAChB,OAAoC,EACpC,YAAuC,EAAE;QAKzC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,iCAAiB,CAAC;QACrD,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;QAC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CAAC,MAAmC,CAAC;IACtD,CAAC;CACF;AApGD,sCAoGC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { rpc } from '@stellar/stellar-sdk';\nimport { SorobanRpcEventResponse } from '@subql/types-stellar';\nimport { compact, groupBy, last } from 'lodash';\nimport { DEFAULT_PAGE_SIZE } from './utils.stellar';\n\ntype CachedEventsResponse = Pick<\n rpc.Api.GetEventsResponse,\n 'events' | 'latestLedger'\n>;\n\nexport class SorobanServer extends rpc.Server {\n private eventsCache: { [key: number]: rpc.Api.GetEventsResponse } = {};\n\n private async fetchEventsForSequence(\n sequence: number,\n request: rpc.Server.GetEventsRequest,\n accEvents: SorobanRpcEventResponse[] = [],\n ): Promise<{\n events: CachedEventsResponse;\n eventsToCache: CachedEventsResponse;\n }> {\n const pageLimit = request.limit ?? DEFAULT_PAGE_SIZE;\n const response = await super.getEvents(request);\n\n // Separate the events for the current sequence and the subsequent sequences\n const groupedEvents = groupBy(response.events, (event) =>\n event.ledger === sequence ? 'events' : 'eventsToCache',\n );\n const events = compact(groupedEvents.events);\n let eventsToCache = compact(groupedEvents.eventsToCache);\n\n // Update the accumulated events with the events from the current sequence\n const newEvents = accEvents.concat(events);\n\n if (eventsToCache?.length) {\n if (response.events.length === pageLimit) {\n const lastSequence = last(response.events)!.ledger;\n eventsToCache = eventsToCache.filter(\n (event) => event.ledger !== lastSequence,\n );\n }\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: {\n events: eventsToCache,\n latestLedger: response.latestLedger,\n },\n };\n }\n\n if (response.events.length < pageLimit) {\n return {\n events: { events: newEvents, latestLedger: response.latestLedger },\n eventsToCache: { events: [], latestLedger: response.latestLedger },\n };\n }\n\n // Prepare the next request\n const nextRequest = {\n ...request,\n cursor: response.events[response.events.length - 1]?.pagingToken,\n startLedger: undefined,\n };\n\n // Continue fetching events for the sequence\n return this.fetchEventsForSequence(sequence, nextRequest, newEvents);\n }\n\n private updateEventCache(\n response: CachedEventsResponse,\n ignoreHeight?: number,\n ): void {\n response.events.forEach((event) => {\n if (ignoreHeight && ignoreHeight === event.ledger) return;\n const ledger = event.ledger;\n if (!this.eventsCache[ledger]) {\n this.eventsCache[ledger] = {\n events: [],\n latestLedger: response.latestLedger,\n } as unknown as rpc.Api.GetEventsResponse;\n }\n const eventExists = this.eventsCache[ledger].events.some(\n (existingEvent) => existingEvent.id === event.id,\n );\n if (!eventExists) {\n this.eventsCache[ledger].events.push(event);\n }\n });\n }\n\n async getEvents(\n request: rpc.Server.GetEventsRequest,\n ): Promise<rpc.Api.GetEventsResponse> {\n const sequence = request.startLedger;\n\n if (sequence === undefined) {\n throw new Error(`Get soraban event failed, block sequence is missing`);\n }\n\n if (this.eventsCache[sequence]) {\n const cachedEvents = this.eventsCache[sequence];\n delete this.eventsCache[sequence];\n return cachedEvents;\n }\n\n const response = await this.fetchEventsForSequence(sequence, request);\n this.updateEventCache(response.eventsToCache, sequence);\n\n return response.events as rpc.Api.GetEventsResponse;\n }\n}\n"]}
|
|
@@ -4,3 +4,4 @@ import { ApiWrapper, StellarBlock, StellarBlockWrapper } from '@subql/types-stel
|
|
|
4
4
|
export declare function stellarBlockToHeader(block: StellarBlock | Horizon.ServerApi.LedgerRecord): Header;
|
|
5
5
|
export declare function formatBlockUtil<B extends StellarBlockWrapper = StellarBlockWrapper>(block: B): IBlock<B>;
|
|
6
6
|
export declare function calcInterval(api: ApiWrapper): number;
|
|
7
|
+
export declare const DEFAULT_PAGE_SIZE = 150;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.calcInterval = exports.formatBlockUtil = exports.stellarBlockToHeader = void 0;
|
|
5
|
+
exports.DEFAULT_PAGE_SIZE = exports.calcInterval = exports.formatBlockUtil = exports.stellarBlockToHeader = void 0;
|
|
6
6
|
function stellarBlockToHeader(block) {
|
|
7
7
|
return {
|
|
8
8
|
blockHeight: block.sequence,
|
|
@@ -22,4 +22,5 @@ function calcInterval(api) {
|
|
|
22
22
|
return 6000;
|
|
23
23
|
}
|
|
24
24
|
exports.calcInterval = calcInterval;
|
|
25
|
+
exports.DEFAULT_PAGE_SIZE = 150;
|
|
25
26
|
//# sourceMappingURL=utils.stellar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAUnC,SAAgB,oBAAoB,CAClC,KAAoD;IAEpD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,QAAQ;QAC3B,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;QAChC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE;KACvC,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC;KACnD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function stellarBlockToHeader(\n block: StellarBlock | Horizon.ServerApi.LedgerRecord,\n): Header {\n return {\n blockHeight: block.sequence,\n blockHash: block.hash.toString(),\n parentHash: block.prev_hash.toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => stellarBlockToHeader(block.block),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.stellar.js","sourceRoot":"","sources":["../../src/stellar/utils.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAUnC,SAAgB,oBAAoB,CAClC,KAAoD;IAEpD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,QAAQ;QAC3B,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;QAChC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE;KACvC,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,eAAe,CAE7B,KAAQ;IACR,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC;KACnD,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,oCAEC;AAEY,QAAA,iBAAiB,GAAG,GAAG,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Horizon } from '@stellar/stellar-sdk';\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n StellarBlock,\n StellarBlockWrapper,\n} from '@subql/types-stellar';\n\nexport function stellarBlockToHeader(\n block: StellarBlock | Horizon.ServerApi.LedgerRecord,\n): Header {\n return {\n blockHeight: block.sequence,\n blockHash: block.hash.toString(),\n parentHash: block.prev_hash.toString(),\n };\n}\n\nexport function formatBlockUtil<\n B extends StellarBlockWrapper = StellarBlockWrapper,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => stellarBlockToHeader(block.block),\n };\n}\n\nexport function calcInterval(api: ApiWrapper): number {\n return 6000;\n}\n\nexport const DEFAULT_PAGE_SIZE = 150;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subql/node-stellar",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1-0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Ian He",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"@nestjs/schedule": "^3.0.1",
|
|
27
27
|
"@stellar/stellar-sdk": "^13.1.0",
|
|
28
28
|
"@subql/common": "^5.3.1",
|
|
29
|
-
"@subql/common-stellar": "4.2.2
|
|
29
|
+
"@subql/common-stellar": "4.2.2",
|
|
30
30
|
"@subql/node-core": "^16.2.1",
|
|
31
31
|
"@subql/testing": "^2.2.0",
|
|
32
|
-
"@subql/types-stellar": "4.
|
|
32
|
+
"@subql/types-stellar": "4.1.1-0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"pg": "^8.11.5",
|
|
35
35
|
"reflect-metadata": "^0.1.13",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"/dist",
|
|
59
59
|
"/bin"
|
|
60
60
|
],
|
|
61
|
-
"stableVersion": "4.
|
|
61
|
+
"stableVersion": "4.4.0"
|
|
62
62
|
}
|