@subql/node-stellar 3.11.2 → 3.11.3-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 +2 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/admin/admin.module.d.ts +2 -0
- package/dist/admin/admin.module.js +25 -0
- package/dist/admin/admin.module.js.map +1 -0
- package/dist/app.module.js +2 -0
- package/dist/app.module.js.map +1 -1
- package/dist/configure/SubqueryProject.js +15 -18
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -0
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -2
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +3 -3
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/stellarDictionary.service.js +2 -0
- package/dist/indexer/dictionary/stellarDictionary.service.js.map +1 -1
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.js +8 -5
- package/dist/indexer/dictionary/v1/stellarDictionaryV1.js.map +1 -1
- package/dist/indexer/ds-processor.service.js +1 -4
- package/dist/indexer/ds-processor.service.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.js +9 -2
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +5 -3
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.js +2 -0
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.js +9 -23
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.js +1 -1
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +1 -0
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker-fetch.module.js +4 -0
- package/dist/indexer/worker/worker-fetch.module.js.map +1 -1
- package/dist/indexer/worker/worker.service.js +2 -0
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/init.js +3 -6
- package/dist/init.js.map +1 -1
- package/dist/meta/meta.controller.js +1 -0
- package/dist/meta/meta.controller.js.map +1 -1
- package/dist/meta/meta.service.js +11 -9
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/stellar/api.connection.js +4 -1
- package/dist/stellar/api.connection.js.map +1 -1
- package/dist/stellar/api.service.stellar.js +6 -5
- package/dist/stellar/api.service.stellar.js.map +1 -1
- package/dist/stellar/api.service.stellar.spec.js +8 -2
- package/dist/stellar/api.service.stellar.spec.js.map +1 -1
- package/dist/stellar/api.stellar.js +40 -5
- package/dist/stellar/api.stellar.js.map +1 -1
- package/dist/stellar/block.stellar.js +7 -3
- package/dist/stellar/block.stellar.js.map +1 -1
- package/dist/stellar/safe-api.js +2 -0
- package/dist/stellar/safe-api.js.map +1 -1
- package/dist/stellar/soroban.server.js +7 -7
- package/dist/stellar/soroban.server.js.map +1 -1
- package/dist/subcommands/testing.init.js +1 -2
- package/dist/subcommands/testing.init.js.map +1 -1
- package/dist/utils/project.js +1 -1
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/string.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAA4E;AAC5E,gDAAmE;AACnE,qCAAwC;AACxC,mCAAqC;AACrC,6CAA4C;AAE5C,+DAA0D;AAC1D,+CAA2C;AAG3C,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,eAAuB;IAEvB,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,eAAe;YACf,OAAO,EAAE,wCAAwC;SAClD;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACgB,CAAC;AAClC,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EAChC,UAAkB,gBAAgB,EAClC,OAAyB,EACuB,EAAE;IAClD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,iCAA0B;YAC1B;gBACE,OAAO,EAAE,wBAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,kBAAkB;gBAC3B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"api.service.stellar.spec.js","sourceRoot":"","sources":["../../src/stellar/api.service.stellar.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAA4E;AAC5E,gDAAmE;AACnE,qCAAwC;AACxC,mCAAqC;AACrC,6CAA4C;AAE5C,+DAA0D;AAC1D,+CAA2C;AAG3C,MAAM,aAAa,GAAG,uCAAuC,CAAC;AAC9D,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,eAAuB;IAEvB,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,eAAe;YACf,OAAO,EAAE,wCAAwC;S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C9B,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CACjD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,gCAAgC,CACjD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC;QAC5C,MAAM,WAAW,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QACnD,MAAM,SAAS,GAAG,IAAA,2BAAa,EAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QAE/C,OAAO,CAAC,GAAG,CAAC,IAAA,2BAAa,EAAC,GAAG,CAAC,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport { ConnectionPoolService, delay, NodeConfig } from '@subql/node-core';\nimport { ConnectionPoolStateManager } from '@subql/node-core/dist';\nimport { GraphQLSchema } from 'graphql';\nimport { range, some } from 'lodash';\nimport { scValToNative } from 'stellar-sdk';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { StellarApiService } from './api.service.stellar';\nimport { StellarApi } from './api.stellar';\nimport { StellarBlockWrapped } from './block.stellar';\n\nconst HTTP_ENDPOINT = 'https://horizon-futurenet.stellar.org';\nconst SOROBAN_ENDPOINT = 'https://rpc-futurenet.stellar.org';\n\nfunction testSubqueryProject(\n endpoint: string,\n sorobanEndpoint: string,\n): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Future Network ; October 2022',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n soroban: string = SOROBAN_ENDPOINT,\n project?: SubqueryProject,\n): Promise<[StellarApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: 'IProjectUpgradeService',\n useFactory: () => ({}),\n },\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => project ?? testSubqueryProject(endpoint, soroban),\n },\n StellarApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(StellarApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n it('should instantiate api', () => {\n expect(apiService.api).toBeInstanceOf(StellarApi);\n });\n\n it('should fetch blocks', async () => {\n const latestHeight = await apiService.api.getFinalizedBlockHeight();\n const blocks = await apiService.fetchBlocks(\n range(latestHeight - 1, latestHeight),\n );\n expect(blocks).toBeDefined();\n expect(blocks[0].block.block.sequence).toEqual(latestHeight - 1);\n });\n\n it('should throw error when chainId does not match', async () => {\n const faultyProject = {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT),\n network: {\n ...testSubqueryProject(HTTP_ENDPOINT, SOROBAN_ENDPOINT).network,\n chainId: 'Incorrect ChainId',\n },\n };\n\n await expect(\n prepareApiService(\n HTTP_ENDPOINT,\n SOROBAN_ENDPOINT,\n faultyProject as unknown as SubqueryProject,\n ),\n ).rejects.toThrow();\n });\n\n it('fails after maximum retries', async () => {\n const api = apiService.unsafeApi;\n\n // Mock the fetchBlocks method to always throw an error\n (api as any).fetchBlocks = jest\n .fn()\n .mockRejectedValue(new Error('Network error'));\n\n await expect(\n (api as any).fetchBlocks(range(50000, 50100)),\n ).rejects.toThrow();\n });\n});\n\n// Skip test as rpc is pruned and block can be missing,\n// To test this, find any block with transfer event first\ndescribe.skip('testnet StellarApiService', () => {\n let apiService: StellarApiService;\n let app: INestApplication;\n\n function testSubqueryProject2(\n endpoint: string,\n sorobanEndpoint: string,\n ): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n sorobanEndpoint,\n chainId: 'Test SDF Network ; September 2015',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as unknown as SubqueryProject;\n }\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n testSubqueryProject2(\n 'https://horizon-testnet.stellar.org',\n 'https://soroban-testnet.stellar.org',\n ),\n );\n });\n\n it('should fetch blocks, and decode address', async () => {\n const blocks = await apiService.fetchBlocks([228236]);\n expect(blocks).toBeDefined();\n\n const block228236 = blocks[0];\n const transferEvent = block228236.block.events.find(\n (e) => e.id === '0000980266155778048-0000000001',\n );\n\n const [sys, from, to] = transferEvent.topic;\n const decodedFrom = scValToNative(from).toString();\n const decodedTo = scValToNative(to).toString();\n\n console.log(scValToNative(sys));\n console.log(decodedFrom);\n console.log(decodedTo);\n });\n});\n"]}
|
|
@@ -16,6 +16,13 @@ const utils_stellar_1 = require("./utils.stellar");
|
|
|
16
16
|
const { version: packageVersion } = require('../../package.json');
|
|
17
17
|
const logger = (0, node_core_1.getLogger)('api.Stellar');
|
|
18
18
|
class StellarApi {
|
|
19
|
+
endpoint;
|
|
20
|
+
eventEmitter;
|
|
21
|
+
sorobanClient;
|
|
22
|
+
//private client: Server;
|
|
23
|
+
stellarClient;
|
|
24
|
+
chainId;
|
|
25
|
+
name;
|
|
19
26
|
constructor(endpoint, eventEmitter, sorobanClient) {
|
|
20
27
|
this.endpoint = endpoint;
|
|
21
28
|
this.eventEmitter = eventEmitter;
|
|
@@ -111,21 +118,37 @@ class StellarApi {
|
|
|
111
118
|
filters: [],
|
|
112
119
|
});
|
|
113
120
|
return events.map((event) => {
|
|
114
|
-
const wrappedEvent =
|
|
121
|
+
const wrappedEvent = {
|
|
122
|
+
...event,
|
|
123
|
+
ledger: null,
|
|
124
|
+
transaction: null,
|
|
125
|
+
operation: null,
|
|
126
|
+
};
|
|
115
127
|
return wrappedEvent;
|
|
116
128
|
});
|
|
117
129
|
}
|
|
118
130
|
wrapEffectsForOperation(operationIndex, effectsForSequence) {
|
|
119
131
|
return effectsForSequence
|
|
120
132
|
.filter((effect) => this.getOperationIndex(effect.id) === operationIndex)
|
|
121
|
-
.map((effect) => (
|
|
133
|
+
.map((effect) => ({
|
|
134
|
+
...effect,
|
|
135
|
+
ledger: null,
|
|
136
|
+
transaction: null,
|
|
137
|
+
operation: null,
|
|
138
|
+
}));
|
|
122
139
|
}
|
|
123
140
|
wrapOperationsForTx(transactionId, applicationOrder, sequence, operationsForSequence, effectsForSequence, eventsForSequence) {
|
|
124
141
|
const operations = operationsForSequence.filter((op) => op.transaction_hash === transactionId);
|
|
125
142
|
return operations.map((op, index) => {
|
|
126
143
|
const effects = this.wrapEffectsForOperation(index, effectsForSequence);
|
|
127
144
|
const events = eventsForSequence.filter((event) => this.getTransactionApplicationOrder(event.id) === applicationOrder);
|
|
128
|
-
const wrappedOp =
|
|
145
|
+
const wrappedOp = {
|
|
146
|
+
...op,
|
|
147
|
+
ledger: null,
|
|
148
|
+
transaction: null,
|
|
149
|
+
effects: [],
|
|
150
|
+
events,
|
|
151
|
+
};
|
|
129
152
|
const clonedOp = (0, lodash_1.cloneDeep)(wrappedOp);
|
|
130
153
|
effects.forEach((effect) => {
|
|
131
154
|
effect.operation = clonedOp;
|
|
@@ -136,7 +159,13 @@ class StellarApi {
|
|
|
136
159
|
}
|
|
137
160
|
wrapTransactionsForLedger(sequence, transactions, operationsForSequence, effectsForSequence, eventsForSequence) {
|
|
138
161
|
return transactions.map((tx, index) => {
|
|
139
|
-
const wrappedTx =
|
|
162
|
+
const wrappedTx = {
|
|
163
|
+
...tx,
|
|
164
|
+
ledger: null,
|
|
165
|
+
operations: [],
|
|
166
|
+
effects: [],
|
|
167
|
+
events: [],
|
|
168
|
+
};
|
|
140
169
|
const clonedTx = (0, lodash_1.cloneDeep)(wrappedTx);
|
|
141
170
|
const operations = this.wrapOperationsForTx(
|
|
142
171
|
// TODO, this include other attribute from HorizonApi.TransactionResponse, but type assertion incorrect
|
|
@@ -194,7 +223,13 @@ class StellarApi {
|
|
|
194
223
|
throw e;
|
|
195
224
|
}
|
|
196
225
|
}
|
|
197
|
-
const wrappedLedger =
|
|
226
|
+
const wrappedLedger = {
|
|
227
|
+
...ledger,
|
|
228
|
+
transactions: [],
|
|
229
|
+
operations: [],
|
|
230
|
+
effects: [],
|
|
231
|
+
events: eventsForSequence,
|
|
232
|
+
};
|
|
198
233
|
const wrapperTxs = this.wrapTransactionsForLedger(sequence, transactions, operations, effects, eventsForSequence);
|
|
199
234
|
const clonedLedger = (0, lodash_1.cloneDeep)(wrappedLedger);
|
|
200
235
|
wrapperTxs.forEach((tx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.stellar.js","sourceRoot":"","sources":["../../src/stellar/api.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAGnC,gDAAqD;AAUrD,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAkD;AAElD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAOrB,YACU,QAAgB,EAChB,YAA2B,EAC3B,aAA6B;QAF7B,aAAQ,G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AAO;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-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock } 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';\nimport { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n 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<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) {\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 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(): 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,gDAAqD;AAUrD,mCAAmC;AAEnC,4DAA+D;AAC/D,0DAA6C;AAE7C,qDAAiD;AACjD,mDAAkD;AAElD,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;AAExC,MAAa,UAAU;IAQX;IACA;IACA;IATV,yBAAyB;IACjB,aAAa,CAAgB;IAE7B,OAAO,CAAS;IAChB,IAAI,CAAS;IAErB,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,EAA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CAAwC,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-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock } 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';\nimport { formatBlockUtil } from './utils.stellar';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.Stellar');\n\nexport class StellarApi implements ApiWrapper {\n //private client: Server;\n private stellarClient: StellarServer;\n\n private chainId: string;\n 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<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) {\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 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(): 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"]}
|
|
@@ -7,6 +7,11 @@ const node_core_1 = require("@subql/node-core");
|
|
|
7
7
|
const stellar_sdk_1 = require("stellar-sdk");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
class StellarBlockWrapped {
|
|
10
|
+
_block;
|
|
11
|
+
_transactions;
|
|
12
|
+
_operations;
|
|
13
|
+
_effects;
|
|
14
|
+
_events;
|
|
10
15
|
constructor(_block, _transactions, _operations, _effects, _events) {
|
|
11
16
|
this._block = _block;
|
|
12
17
|
this._transactions = _transactions;
|
|
@@ -32,7 +37,7 @@ class StellarBlockWrapped {
|
|
|
32
37
|
static filterBlocksProcessor(block, filter, address) {
|
|
33
38
|
if (!filter)
|
|
34
39
|
return true;
|
|
35
|
-
if (
|
|
40
|
+
if (filter?.modulo && block.sequence % filter.modulo !== 0) {
|
|
36
41
|
return false;
|
|
37
42
|
}
|
|
38
43
|
if (!(0, node_core_1.filterBlockTimestamp)(new Date(block.closed_at).getTime(), filter)) {
|
|
@@ -71,14 +76,13 @@ class StellarBlockWrapped {
|
|
|
71
76
|
return true;
|
|
72
77
|
}
|
|
73
78
|
static filterEventProcessor(event, filter, address) {
|
|
74
|
-
var _a;
|
|
75
79
|
if (address && !(0, string_1.stringNormalizedEq)(address, event.contractId.toString())) {
|
|
76
80
|
return false;
|
|
77
81
|
}
|
|
78
82
|
if (!filter)
|
|
79
83
|
return true;
|
|
80
84
|
if (filter.contractId &&
|
|
81
|
-
filter.contractId !==
|
|
85
|
+
filter.contractId !== event.contractId?.toString()) {
|
|
82
86
|
return false;
|
|
83
87
|
}
|
|
84
88
|
if (filter.topics) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAwD;AAcxD,6CAA4C;AAE5C,4CAAqD;AAErD,MAAa,mBAAmB;
|
|
1
|
+
{"version":3,"file":"block.stellar.js","sourceRoot":"","sources":["../../src/stellar/block.stellar.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAwD;AAcxD,6CAA4C;AAE5C,4CAAqD;AAErD,MAAa,mBAAmB;IAEpB;IACA;IACA;IACA;IACA;IALV,YACU,MAAoB,EACpB,aAAmC,EACnC,WAA+B,EAC/B,QAAyB,EACzB,OAAuB;QAJvB,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAAsB;QACnC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,aAAQ,GAAR,QAAQ,CAAiB;QACzB,YAAO,GAAP,OAAO,CAAgB;IAC9B,CAAC;IAEJ,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,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;AAjID,kDAiIC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { filterBlockTimestamp } from '@subql/node-core';\nimport {\n StellarBlock,\n StellarBlockFilter,\n StellarBlockWrapper,\n StellarEffect,\n StellarEffectFilter,\n SorobanEvent,\n SorobanEventFilter,\n StellarOperation,\n StellarOperationFilter,\n StellarTransaction,\n StellarTransactionFilter,\n} from '@subql/types-stellar';\nimport { scValToNative } from 'stellar-sdk';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { stringNormalizedEq } from '../utils/string';\n\nexport class StellarBlockWrapped implements StellarBlockWrapper {\n constructor(\n private _block: StellarBlock,\n private _transactions: StellarTransaction[],\n private _operations: StellarOperation[],\n private _effects: StellarEffect[],\n private _events: SorobanEvent[],\n ) {}\n\n get block(): StellarBlock {\n return this._block;\n }\n\n get transactions(): StellarTransaction[] {\n return this._transactions;\n }\n\n get operations(): StellarOperation[] {\n return this._operations;\n }\n\n get effects(): StellarEffect[] {\n return this._effects;\n }\n\n get events(): SorobanEvent[] {\n return this._events;\n }\n\n static filterBlocksProcessor(\n block: StellarBlock,\n filter: StellarBlockFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter?.modulo && block.sequence % filter.modulo !== 0) {\n return false;\n }\n if (\n !filterBlockTimestamp(\n new Date(block.closed_at).getTime(),\n filter as SubqlProjectBlockFilter,\n )\n ) {\n return false;\n }\n return true;\n }\n\n static filterTransactionProcessor(\n tx: StellarTransaction,\n filter: StellarTransactionFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== (tx as any).source_account) {\n return false;\n }\n\n return true;\n }\n\n static filterOperationProcessor(\n op: StellarOperation,\n filter: StellarOperationFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.sourceAccount && filter.sourceAccount !== op.source_account) {\n return false;\n }\n if (filter.type && filter.type !== op.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEffectProcessor(\n effect: StellarEffect,\n filter: StellarEffectFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\n if (filter.account && filter.account !== effect.account) {\n return false;\n }\n if (filter.type && filter.type !== effect.type) {\n return false;\n }\n\n return true;\n }\n\n static filterEventProcessor(\n event: SorobanEvent,\n filter: SorobanEventFilter,\n address?: string,\n ): boolean {\n if (address && !stringNormalizedEq(address, event.contractId.toString())) {\n return false;\n }\n\n if (!filter) return true;\n\n if (\n filter.contractId &&\n filter.contractId !== event.contractId?.toString()\n ) {\n return false;\n }\n\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n\n if (!event.topic[i]) {\n return false;\n }\n if (topic !== scValToNative(event.topic[i])) {\n return false;\n }\n }\n }\n return true;\n }\n}\n"]}
|
package/dist/stellar/safe-api.js
CHANGED
|
@@ -8,6 +8,8 @@ const soroban_1 = require("stellar-sdk/lib/soroban");
|
|
|
8
8
|
const soroban_server_1 = require("./soroban.server");
|
|
9
9
|
const logger = (0, node_core_1.getLogger)('safe.api.stellar');
|
|
10
10
|
class SafeStellarProvider extends soroban_server_1.SorobanServer {
|
|
11
|
+
blockHeight;
|
|
12
|
+
baseApi;
|
|
11
13
|
constructor(baseApi, blockHeight) {
|
|
12
14
|
super(baseApi.serverURL.toString());
|
|
13
15
|
this.blockHeight = blockHeight;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-api.js","sourceRoot":"","sources":["../../src/stellar/safe-api.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,gDAA6C;AAU7C,qDAAqD;AAErD,0DAA0D;AAC1D,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,kBAAkB,CAAC,CAAC;AAE7C,MAAqB,mBAAoB,SAAQ,8BAAa;
|
|
1
|
+
{"version":3,"file":"safe-api.js","sourceRoot":"","sources":["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Z,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,mBAAmB,CACvB,WAA6C;QAE7C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,kBAAkB,CACtB,WAA6C;QAE7C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,eAAe,CACnB,WAA6C;QAE7C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,cAAc,CAClB,OAA4C,EAC5C,YAAqB;QAErB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;CACF;AA3FD,sCA2FC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Memo, MemoType, Operation } from '@stellar/stellar-base';\nimport { getLogger } from '@subql/node-core';\nimport {\n Account,\n Address,\n Contract,\n FeeBumpTransaction,\n SorobanRpc,\n Transaction,\n xdr,\n} from 'stellar-sdk';\nimport { Durability } from 'stellar-sdk/lib/soroban';\n\n// import { Durability } from 'soroban-client/lib/server';\nimport { SorobanServer } from './soroban.server';\n\nconst logger = getLogger('safe.api.stellar');\n\nexport default class SafeStellarProvider extends SorobanServer {\n private blockHeight: number;\n private baseApi: SorobanRpc.Server;\n\n constructor(baseApi: SorobanRpc.Server, blockHeight: number) {\n super(baseApi.serverURL.toString());\n this.blockHeight = blockHeight;\n this.baseApi = baseApi;\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getAccount(address: string): Promise<Account> {\n throw new Error('Method getAccount is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getHealth(): Promise<SorobanRpc.Api.GetHealthResponse> {\n throw new Error('Method getHealth is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getContractData(\n contract: string | Address | Contract,\n key: xdr.ScVal,\n durability: Durability = Durability.Persistent,\n ): Promise<SorobanRpc.Api.LedgerEntryResult> {\n throw new Error('Method getContractData is not implemented.');\n }\n\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/require-await\n async getLedgerEntries(\n keys: xdr.LedgerKey[],\n ): Promise<SorobanRpc.Api.GetLedgerEntriesResponse> {\n throw new Error('Method getLedgerEntries is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getTransaction(\n hash: string,\n ): Promise<SorobanRpc.Api.GetTransactionResponse> {\n throw new Error('Method getTransaction is not implemented.');\n }\n\n async getEvents(\n request: SorobanRpc.Server.GetEventsRequest,\n ): Promise<SorobanRpc.Api.GetEventsResponse> {\n return this.baseApi.getEvents({\n startLedger: this.blockHeight,\n filters: [],\n });\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getNetwork(): Promise<SorobanRpc.Api.GetNetworkResponse> {\n throw new Error('Method getNetwork is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async getLatestLedger(): Promise<SorobanRpc.Api.GetLatestLedgerResponse> {\n throw new Error('Method getLatestLedger is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async simulateTransaction(\n transaction: Transaction | FeeBumpTransaction,\n ): Promise<SorobanRpc.Api.SimulateTransactionResponse> {\n throw new Error('Method simulateTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async prepareTransaction(\n transaction: Transaction | FeeBumpTransaction,\n ): Promise<Transaction<Memo<MemoType>, Operation[]>> {\n throw new Error('Method prepareTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async sendTransaction(\n transaction: Transaction | FeeBumpTransaction,\n ): Promise<SorobanRpc.Api.SendTransactionResponse> {\n throw new Error('Method sendTransaction is not implemented.');\n }\n\n //eslint-disable-next-line @typescript-eslint/require-await\n async requestAirdrop(\n address: string | Pick<Account, 'accountId'>,\n friendbotUrl?: string,\n ): Promise<Account> {\n throw new Error('Method requestAirdrop is not implemented.');\n }\n}\n"]}
|
|
@@ -7,12 +7,8 @@ const lodash_1 = require("lodash");
|
|
|
7
7
|
const stellar_sdk_1 = require("stellar-sdk");
|
|
8
8
|
const DEFAULT_PAGE_SIZE = 100;
|
|
9
9
|
class SorobanServer extends stellar_sdk_1.SorobanRpc.Server {
|
|
10
|
-
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.eventsCache = {};
|
|
13
|
-
}
|
|
10
|
+
eventsCache = {};
|
|
14
11
|
async fetchEventsForSequence(sequence, request, accEvents = []) {
|
|
15
|
-
var _a;
|
|
16
12
|
const response = await super.getEvents(request);
|
|
17
13
|
// Separate the events for the current sequence and the subsequent sequences
|
|
18
14
|
const groupedEvents = (0, lodash_1.groupBy)(response.events, (event) => event.ledger === sequence ? 'events' : 'eventsToCache');
|
|
@@ -20,7 +16,7 @@ class SorobanServer extends stellar_sdk_1.SorobanRpc.Server {
|
|
|
20
16
|
let eventsToCache = (0, lodash_1.compact)(groupedEvents.eventsToCache);
|
|
21
17
|
// Update the accumulated events with the events from the current sequence
|
|
22
18
|
const newEvents = accEvents.concat(events);
|
|
23
|
-
if (eventsToCache
|
|
19
|
+
if (eventsToCache?.length) {
|
|
24
20
|
if (response.events.length === DEFAULT_PAGE_SIZE) {
|
|
25
21
|
const lastSequence = (0, lodash_1.last)(response.events).ledger;
|
|
26
22
|
eventsToCache = eventsToCache.filter((event) => event.ledger !== lastSequence);
|
|
@@ -40,7 +36,11 @@ class SorobanServer extends stellar_sdk_1.SorobanRpc.Server {
|
|
|
40
36
|
};
|
|
41
37
|
}
|
|
42
38
|
// Prepare the next request
|
|
43
|
-
const nextRequest =
|
|
39
|
+
const nextRequest = {
|
|
40
|
+
...request,
|
|
41
|
+
cursor: response.events[response.events.length - 1]?.pagingToken,
|
|
42
|
+
startLedger: undefined,
|
|
43
|
+
};
|
|
44
44
|
// Continue fetching events for the sequence
|
|
45
45
|
return this.fetchEventsForSequence(sequence, nextRequest, newEvents);
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,mCAAgD;AAChD,6CAAyC;AAEzC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAa,aAAc,SAAQ,wBAAU,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"soroban.server.js","sourceRoot":"","sources":["../../src/stellar/soroban.server.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,mCAAgD;AAChD,6CAAyC;AAEzC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAa,aAAc,SAAQ,wBAAU,CAAC,MAAM;IAC1C,WAAW,GAAwD,EAAE,CAAC;IAEtE,KAAK,CAAC,sBAAsB,CAClC,QAAgB,EAChB,OAA2C,EAC3C,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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CACF;AA9FD,sCA8FC","sourcesContent":["// Copyright 2020-2024 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 { SorobanRpc } from 'stellar-sdk';\n\nconst DEFAULT_PAGE_SIZE = 100;\n\nexport class SorobanServer extends SorobanRpc.Server {\n private eventsCache: { [key: number]: SorobanRpc.Api.GetEventsResponse } = {};\n\n private async fetchEventsForSequence(\n sequence: number,\n request: SorobanRpc.Server.GetEventsRequest,\n accEvents: SorobanRpcEventResponse[] = [],\n ): Promise<{\n events: SorobanRpc.Api.GetEventsResponse;\n eventsToCache: SorobanRpc.Api.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.Api.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.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: SorobanRpc.Server.GetEventsRequest,\n ): Promise<SorobanRpc.Api.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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,
|
|
1
|
+
{"version":3,"file":"testing.init.js","sourceRoot":"","sources":["../../src/subcommands/testing.init.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAA4D;AAC5D,oEAAgE;AAChE,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;AAC7B,KAAK,UAAU,WAAW;IAC/B,IAAI;QACF,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,kCAAe,CAAC,WAAW,EAAE,CAAC;QAEpE,MAAM,cAAc,GAAG,IAAI,gCAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,cAAc,CAAC,GAAG,EAAE,CAAC;KAC5B;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,yBAAa,EAAC,IAAI,KAAK,CAAC,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;KAClE;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAVD,kCAUC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { exitWithError, getLogger } from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { TestingService } from './testing.service';\n\nconst logger = getLogger('Testing');\nexport async function testingInit(): Promise<void> {\n try {\n const { nodeConfig, project } = await ConfigureModule.getInstance();\n\n const testingService = new TestingService(nodeConfig, project);\n await testingService.run();\n } catch (e) {\n exitWithError(new Error('Testing failed', { cause: e }), logger);\n }\n process.exit(0);\n}\n"]}
|
package/dist/utils/project.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.isCustomHandler = isCustomHandler;
|
|
|
16
16
|
const handledErrors = ['timeout'];
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
18
18
|
async function retryOnFailEth(request, errors = handledErrors) {
|
|
19
|
-
return (0, node_core_1.retryOnFail)(request, (e) => !!errors.find((t) => t ===
|
|
19
|
+
return (0, node_core_1.retryOnFail)(request, (e) => !!errors.find((t) => t === e?.reason));
|
|
20
20
|
}
|
|
21
21
|
exports.retryOnFailEth = retryOnFailEth;
|
|
22
22
|
//# sourceMappingURL=project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,0DAK+B;AAC/B,gDAA+C;AAE/C,SAAgB,aAAa,CAC3B,OAAqB;IAErB,OAAO,MAAM,CAAC,MAAM,CAAS,mCAAkB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC;AAJD,sCAIC;AAED,SAAgB,eAAe,CAC7B,OAAqB;IAErB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAJD,0CAIC;AAED,MAAM,aAAa,GAAG,CAAC,SAAS,CAAC,CAAC;AAClC,4DAA4D;AACrD,KAAK,UAAU,cAAc,CAClC,OAAyB,EACzB,MAAM,GAAG,aAAa;IAEtB,OAAO,IAAA,uBAAW,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,0DAK+B;AAC/B,gDAA+C;AAE/C,SAAgB,aAAa,CAC3B,OAAqB;IAErB,OAAO,MAAM,CAAC,MAAM,CAAS,mCAAkB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC;AAJD,sCAIC;AAED,SAAgB,eAAe,CAC7B,OAAqB;IAErB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAJD,0CAIC;AAED,MAAM,aAAa,GAAG,CAAC,SAAS,CAAC,CAAC;AAClC,4DAA4D;AACrD,KAAK,UAAU,cAAc,CAClC,OAAyB,EACzB,MAAM,GAAG,aAAa;IAEtB,OAAO,IAAA,uBAAW,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC5E,CAAC;AALD,wCAKC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n SubqlRuntimeHandler,\n SubqlCustomHandler,\n SubqlHandler,\n StellarHandlerKind,\n} from '@subql/common-stellar';\nimport { retryOnFail } from '@subql/node-core';\n\nexport function isBaseHandler(\n handler: SubqlHandler,\n): handler is SubqlRuntimeHandler {\n return Object.values<string>(StellarHandlerKind).includes(handler.kind);\n}\n\nexport function isCustomHandler(\n handler: SubqlHandler,\n): handler is SubqlCustomHandler {\n return !isBaseHandler(handler);\n}\n\nconst handledErrors = ['timeout'];\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function retryOnFailEth<T>(\n request: () => Promise<T>,\n errors = handledErrors,\n): Promise<T> {\n return retryOnFail(request, (e) => !!errors.find((t) => t === e?.reason));\n}\n"]}
|
package/dist/utils/string.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.stringNormalizedEq = void 0;
|
|
6
6
|
function stringNormalizedEq(a, b) {
|
|
7
|
-
return a.toLowerCase() ===
|
|
7
|
+
return a.toLowerCase() === b?.toLowerCase();
|
|
8
8
|
}
|
|
9
9
|
exports.stringNormalizedEq = stringNormalizedEq;
|
|
10
10
|
//# sourceMappingURL=string.js.map
|
package/dist/utils/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,SAAgB,kBAAkB,CAAC,CAAS,EAAE,CAAS;IACrD,OAAO,CAAC,CAAC,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,SAAgB,kBAAkB,CAAC,CAAS,EAAE,CAAS;IACrD,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;AAC9C,CAAC;AAFD,gDAEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nexport function stringNormalizedEq(a: string, b: string): boolean {\n return a.toLowerCase() === b?.toLowerCase();\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subql/node-stellar",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.3-0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Ian He",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -24,11 +24,10 @@
|
|
|
24
24
|
"@nestjs/event-emitter": "^2.0.0",
|
|
25
25
|
"@nestjs/platform-express": "^9.4.0",
|
|
26
26
|
"@nestjs/schedule": "^3.0.1",
|
|
27
|
-
"@subql/common": "
|
|
28
|
-
"@subql/
|
|
29
|
-
"@subql/node-core": "10.1.0",
|
|
27
|
+
"@subql/common-stellar": "3.5.1-0",
|
|
28
|
+
"@subql/node-core": "10.10.0",
|
|
30
29
|
"@subql/testing": "^2.0.0",
|
|
31
|
-
"@subql/types-stellar": "3.4.0",
|
|
30
|
+
"@subql/types-stellar": "3.4.1-0",
|
|
32
31
|
"lodash": "^4.17.21",
|
|
33
32
|
"pg": "^8.11.5",
|
|
34
33
|
"reflect-metadata": "^0.1.13",
|
|
@@ -57,5 +56,6 @@
|
|
|
57
56
|
"files": [
|
|
58
57
|
"/dist",
|
|
59
58
|
"/bin"
|
|
60
|
-
]
|
|
59
|
+
],
|
|
60
|
+
"stableVersion": "3.11.2"
|
|
61
61
|
}
|