Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core-api): fix transactions/${id} confirmations and timestamp fields #3925

Merged
merged 5 commits into from Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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