forked from matter-labs/block-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.controller.ts
More file actions
52 lines (48 loc) · 1.66 KB
/
stats.controller.ts
File metadata and controls
52 lines (48 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Controller, Get } from "@nestjs/common";
import { ApiTags, ApiOkResponse, ApiExcludeController } from "@nestjs/swagger";
import { Not, IsNull } from "typeorm";
import { BatchService } from "../batch/batch.service";
import { BlockService } from "../block/block.service";
import { TransactionService } from "../transaction/transaction.service";
import { BalanceService } from "../balance/balance.service";
import { StatsDto } from "./stats.dto";
import { swagger } from "../config/featureFlags";
const entityName = "stats";
@ApiTags("Stats BFF")
@ApiExcludeController(!swagger.bffEnabled)
@Controller(entityName)
export class StatsController {
constructor(
private readonly batchService: BatchService,
private readonly blocksService: BlockService,
private readonly transactionService: TransactionService,
private readonly balanceService: BalanceService
) {}
@Get()
@ApiOkResponse({ description: "Blockchain stats", type: StatsDto })
public async stats(): Promise<StatsDto> {
const [
lastSealedBatch,
lastVerifiedBatch,
lastSealedBlock,
lastVerifiedBlock,
totalTransactions,
totalActiveAccounts,
] = await Promise.all([
this.batchService.getLastBatchNumber(),
this.batchService.getLastBatchNumber({ executedAt: Not(IsNull()) }),
this.blocksService.getLastBlockNumber(),
this.blocksService.getLastVerifiedBlockNumber(),
this.transactionService.count(),
this.balanceService.getTotalActiveAccounts(),
]);
return {
lastSealedBatch,
lastVerifiedBatch,
lastSealedBlock,
lastVerifiedBlock,
totalTransactions,
totalActiveAccounts,
};
}
}