Skip to content

Commit

Permalink
fix(core-api): fix transactions/${id} confirmations and timestamp fie…
Browse files Browse the repository at this point in the history
…lds (#3925)
  • Loading branch information
rainydio committed Aug 3, 2020
1 parent f2da0bd commit a7b46a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/unit.yml
Expand Up @@ -32,7 +32,6 @@ jobs:
- core-webhooks
- crypto


runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions __tests__/unit/core-api/controllers/transactions.test.ts
Expand Up @@ -25,6 +25,8 @@ const transactionHistoryService = {
listByCriteriaJoinBlock: jest.fn(),
};

const blockHistoryService = {};

const block: Interfaces.IBlockData = {
version: 0,
timestamp: 103497376,
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion packages/core-api/src/controllers/transactions.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a7b46a9

Please sign in to comment.