-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from crypitor/transaction_history
Transaction history
- Loading branch information
Showing
8 changed files
with
236 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
app/apps/onebox/src/modules/event_history/dto/event_history.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { | ||
EventHistory, | ||
WebhookCategory, | ||
WebhookType, | ||
} from '@app/shared_modules/event_history/schemas/event_history.schema'; | ||
import { ApiProperty, ApiResponseProperty } from '@nestjs/swagger'; | ||
import { Builder } from 'builder-pattern'; | ||
import { Transform } from 'class-transformer'; | ||
import { IsNotEmpty, Max, Min } from 'class-validator'; | ||
|
||
export class GetMonitorEventHistoryDto { | ||
@ApiProperty() | ||
@IsNotEmpty() | ||
monitorId: string; | ||
|
||
// @ApiProperty({ required: false }) | ||
// status?: 'succeeded' | 'pending' | 'failed'; | ||
|
||
@ApiProperty({ default: 10 }) | ||
@Max(10) | ||
@Min(1) | ||
@Transform(({ value }) => parseInt(value)) | ||
limit: number; | ||
|
||
@ApiProperty({ default: 0 }) | ||
@Min(0) | ||
@Transform(({ value }) => parseInt(value)) | ||
offset: number; | ||
} | ||
|
||
export class MonitorEventHistoryResponseDto { | ||
@ApiResponseProperty() | ||
eventId: string; // md5 of message exclude timestamp and confirm | ||
|
||
@ApiResponseProperty() | ||
chain: string; | ||
|
||
@ApiResponseProperty() | ||
monitorId: string; | ||
|
||
@ApiResponseProperty() | ||
associatedAddress: string; | ||
|
||
@ApiResponseProperty() | ||
hash: string; | ||
|
||
@ApiResponseProperty() | ||
blockNum: number; // decimal string | ||
|
||
@ApiResponseProperty() | ||
contract: { | ||
address: string; | ||
name: string; | ||
symbol: string; | ||
}; | ||
|
||
@ApiResponseProperty() | ||
fromAddress: string; | ||
|
||
@ApiResponseProperty() | ||
toAddress: string; | ||
|
||
@ApiResponseProperty() | ||
tokenId: string; // decimal string | ||
|
||
@ApiResponseProperty() | ||
tokenValue: string; // decimal string | ||
|
||
@ApiResponseProperty() | ||
nativeAmount: string; // decimal string | ||
|
||
@ApiResponseProperty() | ||
type: WebhookType; | ||
|
||
@ApiResponseProperty() | ||
confirm: boolean; | ||
|
||
@ApiResponseProperty() | ||
category: WebhookCategory; | ||
|
||
@ApiResponseProperty() | ||
rawLog: { | ||
topics: string[]; | ||
data: string; | ||
}; | ||
|
||
@ApiResponseProperty() | ||
logIndex: number; | ||
|
||
@ApiResponseProperty() | ||
txnIndex: number; | ||
|
||
@ApiResponseProperty() | ||
tags: string[]; | ||
|
||
@ApiResponseProperty() | ||
dateCreated: Date; | ||
|
||
@ApiResponseProperty() | ||
deliveryIds: string[]; | ||
|
||
static from(dto: EventHistory): MonitorEventHistoryResponseDto { | ||
return Builder<MonitorEventHistoryResponseDto>() | ||
.eventId(dto.eventId) | ||
.chain(dto.chain) | ||
.monitorId(dto.monitorId) | ||
.associatedAddress(dto.associatedAddress) | ||
.hash(dto.hash) | ||
.blockNum(dto.blockNum) | ||
.contract(dto.contract) | ||
.fromAddress(dto.fromAddress) | ||
.toAddress(dto.toAddress) | ||
.tokenId(dto.tokenId) | ||
.tokenValue(dto.tokenValue) | ||
.nativeAmount(dto.nativeAmount) | ||
.type(dto.type) | ||
.confirm(dto.confirm) | ||
.category(dto.category) | ||
.rawLog(dto.rawLog) | ||
.logIndex(dto.logIndex) | ||
.txnIndex(dto.txnIndex) | ||
.tags(dto.tags) | ||
.dateCreated(dto.dateCreated) | ||
.deliveryIds(dto.deliveryIds) | ||
.build(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/apps/onebox/src/modules/event_history/event_history.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { Request } from 'express'; | ||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; | ||
import { User } from '../users/schemas/user.schema'; | ||
import { | ||
GetMonitorEventHistoryDto, | ||
MonitorEventHistoryResponseDto, | ||
} from './dto/event_history.dto'; | ||
import { EventHistoryService } from './event_history.service'; | ||
|
||
@ApiTags('Monitor Event History') | ||
@Controller('/event') | ||
export class EventHistoryController { | ||
constructor(private readonly eventHistoryService: EventHistoryService) {} | ||
|
||
@ApiOperation({ summary: 'Get Monitor Event' }) | ||
@ApiBearerAuth('JWT') | ||
@UseGuards(JwtAuthGuard) | ||
@Get('') | ||
@ApiOkResponse({ type: [MonitorEventHistoryResponseDto] }) | ||
async getMonitorEvent( | ||
@Req() req: Request, | ||
@Query() body: GetMonitorEventHistoryDto, | ||
): Promise<MonitorEventHistoryResponseDto[]> { | ||
return await this.eventHistoryService.getMonitorEventHistory( | ||
req.user as User, | ||
body, | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/apps/onebox/src/modules/event_history/event_history.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { EventHistoryModelModule } from '@app/shared_modules/event_history/event_history.module'; | ||
import { Module } from '@nestjs/common'; | ||
import { MonitorModule } from '../monitor/monitor.module'; | ||
import { EventHistoryController } from './event_history.controller'; | ||
import { EventHistoryService } from './event_history.service'; | ||
@Module({ | ||
controllers: [EventHistoryController], | ||
providers: [EventHistoryService], | ||
exports: [EventHistoryService], | ||
imports: [EventHistoryModelModule, MonitorModule], | ||
}) | ||
export class EventHistoryModule {} |
42 changes: 42 additions & 0 deletions
42
app/apps/onebox/src/modules/event_history/event_history.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { EthEventHistoryRepository } from '@app/shared_modules/event_history/repositories/event_history.repository'; | ||
import { Inject, Injectable, Logger } from '@nestjs/common'; | ||
import { MonitorService } from '../monitor/monitor.service'; | ||
import { User } from '../users/schemas/user.schema'; | ||
import { | ||
GetMonitorEventHistoryDto, | ||
MonitorEventHistoryResponseDto, | ||
} from './dto/event_history.dto'; | ||
import { MonitorNetwork } from '@app/shared_modules/monitor/schemas/monitor.schema'; | ||
import { ErrorCode } from '@app/global/global.error'; | ||
|
||
@Injectable() | ||
export class EventHistoryService { | ||
private readonly logger = new Logger(EventHistoryService.name); | ||
constructor( | ||
private readonly ethEventHistoryRepository: EthEventHistoryRepository, | ||
private readonly monitorService: MonitorService, | ||
) {} | ||
|
||
async getMonitorEventHistory( | ||
user: User, | ||
request: GetMonitorEventHistoryDto, | ||
): Promise<MonitorEventHistoryResponseDto[]> { | ||
const monitor = await this.monitorService.findAndAuthMonitor( | ||
user, | ||
request.monitorId, | ||
); | ||
|
||
if (monitor.network === MonitorNetwork.Ethereum) { | ||
return this.ethEventHistoryRepository | ||
.getEventHistory(monitor.monitorId, request.limit, request.offset) | ||
.then((response) => { | ||
return response.map((event) => | ||
MonitorEventHistoryResponseDto.from(event), | ||
); | ||
}); | ||
} | ||
|
||
this.logger.error(`network ${monitor.network} not supported`); | ||
throw ErrorCode.INTERNAL_SERVER_ERROR.asException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters