From af0abffaab02dcf64c19a6582bc61ec9814028b8 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Thu, 17 Aug 2023 04:33:28 +0000 Subject: [PATCH] code cleanup --- package.json | 5 +-- packages/common-stellar/package.json | 3 +- packages/common-stellar/src/project/models.ts | 4 +-- packages/node/package.json | 1 + packages/node/src/stellar/api.stellar.ts | 33 ++++++++----------- packages/types/package.json | 3 +- packages/types/src/stellar/interfaces.ts | 2 +- 7 files changed, 21 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 8cdae887..e25041bf 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,5 @@ "prettier --write" ] }, - "packageManager": "yarn@3.1.1", - "dependencies": { - "stellar-sdk": "^10.4.1" - } + "packageManager": "yarn@3.1.1" } diff --git a/packages/common-stellar/package.json b/packages/common-stellar/package.json index 1d95e1fe..70589444 100644 --- a/packages/common-stellar/package.json +++ b/packages/common-stellar/package.json @@ -17,7 +17,8 @@ "@subql/types-stellar": "workspace:*", "js-yaml": "^4.1.0", "pino": "^6.13.3", - "reflect-metadata": "^0.1.13" + "reflect-metadata": "^0.1.13", + "stellar-sdk": "^10.4.1" }, "peerDependencies": { "class-transformer": "*", diff --git a/packages/common-stellar/src/project/models.ts b/packages/common-stellar/src/project/models.ts index f2371a37..37e9de59 100644 --- a/packages/common-stellar/src/project/models.ts +++ b/packages/common-stellar/src/project/models.ts @@ -1,11 +1,9 @@ // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -import {forbidNonWhitelisted} from '@subql/common'; import { StellarHandlerKind, StellarDatasourceKind, - StellarEventFilter, SubqlCustomHandler, SubqlMapping, SubqlHandler, @@ -25,7 +23,7 @@ import { } from '@subql/types-stellar'; import {plainToClass, Transform, Type} from 'class-transformer'; import {IsArray, IsEnum, IsInt, IsOptional, IsString, IsObject, ValidateNested} from 'class-validator'; -import {Horizon, ServerApi} from 'stellar-sdk'; +import {Horizon} from 'stellar-sdk'; import {SubqlStellarProcessorOptions} from './types'; export class BlockFilter implements StellarBlockFilter { diff --git a/packages/node/package.json b/packages/node/package.json index 7a26f462..a1e9eafc 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -41,6 +41,7 @@ "rimraf": "^3.0.2", "rxjs": "^7.5.2", "soroban-client": "^0.9.1", + "stellar-sdk": "^10.4.1", "yargs": "^16.2.0" }, "peerDependencies": { diff --git a/packages/node/src/stellar/api.stellar.ts b/packages/node/src/stellar/api.stellar.ts index f560e213..a82b3190 100644 --- a/packages/node/src/stellar/api.stellar.ts +++ b/packages/node/src/stellar/api.stellar.ts @@ -11,6 +11,7 @@ import { StellarOperation, StellarTransaction, } from '@subql/types-stellar'; +import { cloneDeep } from 'lodash'; import { Server, ServerApi } from 'stellar-sdk'; import { StellarBlockWrapped } from '../stellar/block.stellar'; import SafeStellarProvider from './safe-api'; @@ -97,20 +98,12 @@ export class StellarApi implements ApiWrapper { ): Promise { const effects = (await this.api.effects().forOperation(operationId).call()) .records; - const wrappedEffects: StellarEffect[] = []; - - effects.forEach((effect) => { - const wrappedEffect: StellarEffect = { - ...effect, - ledger: null, - transaction: null, - operation: null, - }; - - wrappedEffects.push(wrappedEffect); - }); - - return wrappedEffects; + return effects.map((effect) => ({ + ...effect, + ledger: null, + transaction: null, + operation: null, + })); } private async fetchOperationsForTransaction( @@ -131,7 +124,7 @@ export class StellarApi implements ApiWrapper { const effects = (await this.fetchEffectsForOperation(op.id)).map( (effect) => { - effect.operation = JSON.parse(JSON.stringify(wrappedOp)); + effect.operation = cloneDeep(wrappedOp); return effect; }, ); @@ -174,9 +167,9 @@ export class StellarApi implements ApiWrapper { const operations = ( await this.fetchOperationsForTransaction(tx.id) ).map((op) => { - op.transaction = JSON.parse(JSON.stringify(wrappedTx)); + op.transaction = cloneDeep(wrappedTx); op.effects = op.effects.map((effect) => { - effect.transaction = JSON.parse(JSON.stringify(wrappedTx)); + effect.transaction = cloneDeep(wrappedTx); return effect; }); return op; @@ -207,11 +200,11 @@ export class StellarApi implements ApiWrapper { const transactions = (await this.fetchTransactionsForLedger(sequence)).map( (tx) => { - tx.ledger = JSON.parse(JSON.stringify(wrappedLedger)); + tx.ledger = cloneDeep(wrappedLedger); tx.operations = tx.operations.map((op) => { - op.ledger = JSON.parse(JSON.stringify(wrappedLedger)); + op.ledger = cloneDeep(wrappedLedger); op.effects = op.effects.map((effect) => { - effect.ledger = JSON.parse(JSON.stringify(wrappedLedger)); + effect.ledger = cloneDeep(wrappedLedger); return effect; }); return op; diff --git a/packages/types/package.json b/packages/types/package.json index b907fcc4..144af0e7 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -16,7 +16,8 @@ "/dist" ], "dependencies": { - "soroban-client": "0.9.2" + "soroban-client": "0.9.2", + "stellar-sdk": "^10.4.1" }, "stableVersion": "2.2.3-2" } diff --git a/packages/types/src/stellar/interfaces.ts b/packages/types/src/stellar/interfaces.ts index ed019f93..96d0b9bb 100644 --- a/packages/types/src/stellar/interfaces.ts +++ b/packages/types/src/stellar/interfaces.ts @@ -31,7 +31,7 @@ export type StellarOperation = T & { +export type StellarEffect = Omit & { operation: StellarOperation; transaction: StellarTransaction; ledger: StellarBlock;