From a7b46a906b4abd9e939d65b62b7ea971dffb4489 Mon Sep 17 00:00:00 2001 From: Dmitry Tyshchenko Date: Mon, 3 Aug 2020 20:27:46 +0300 Subject: [PATCH] fix(core-api): fix transactions/${id} confirmations and timestamp fields (#3925) --- .github/workflows/unit.yml | 3 +-- .../core-api/controllers/transactions.test.ts | 3 +++ .../core-api/src/controllers/transactions.ts | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index b97d269b32..562fad9155 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -32,7 +32,6 @@ jobs: - core-webhooks - crypto - runs-on: ubuntu-latest strategy: @@ -488,7 +487,7 @@ jobs: run: yarn setup - name: Test - run: yarn test:parallel __tests__/unit/core-p2p/ --coverage --coverageDirectory .coverage/unit/${{ github.job }} + run: yarn test __tests__/unit/core-p2p/ --coverage --coverageDirectory .coverage/unit/${{ github.job }} - name: Archive code coverage uses: actions/upload-artifact@v2 diff --git a/__tests__/unit/core-api/controllers/transactions.test.ts b/__tests__/unit/core-api/controllers/transactions.test.ts index 03dac4aa32..d97ac63621 100644 --- a/__tests__/unit/core-api/controllers/transactions.test.ts +++ b/__tests__/unit/core-api/controllers/transactions.test.ts @@ -25,6 +25,8 @@ const transactionHistoryService = { listByCriteriaJoinBlock: jest.fn(), }; +const blockHistoryService = {}; + const block: Interfaces.IBlockData = { version: 0, timestamp: 103497376, @@ -50,6 +52,7 @@ beforeEach(() => { Managers.configManager.setConfig(config); app = initApp(); + app.bind(Identifiers.BlockHistoryService).toConstantValue(blockHistoryService); app.bind(Identifiers.TransactionHistoryService).toConstantValue(transactionHistoryService); // Triggers registration of indexes diff --git a/packages/core-api/src/controllers/transactions.ts b/packages/core-api/src/controllers/transactions.ts index 030583d7c9..146aac6afe 100644 --- a/packages/core-api/src/controllers/transactions.ts +++ b/packages/core-api/src/controllers/transactions.ts @@ -22,6 +22,9 @@ export class TransactionsController extends Controller { @Container.inject(Container.Identifiers.TransactionHistoryService) private readonly transactionHistoryService!: Contracts.Shared.TransactionHistoryService; + @Container.inject(Container.Identifiers.BlockHistoryService) + private readonly blockHistoryService!: Contracts.Shared.BlockHistoryService; + @Container.inject(Container.Identifiers.TransactionPoolProcessorFactory) private readonly createProcessor!: Contracts.TransactionPool.ProcessorFactory; @@ -70,7 +73,18 @@ export class TransactionsController extends Controller { if (!transaction) { return Boom.notFound("Transaction not found"); } - return this.respondWithResource(transaction, TransactionResource, request.query.transform); + + if (request.query.transform) { + const blockData = await this.blockHistoryService.findOneByCriteria({ id: transaction.blockId! }); + + return this.respondWithResource( + { data: transaction, block: blockData }, + TransactionWithBlockResource, + true, + ); + } else { + return this.respondWithResource(transaction, TransactionResource, false); + } } public async unconfirmed(request: Hapi.Request, h: Hapi.ResponseToolkit) {