-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add events support * fixes and improvements
- Loading branch information
Showing
14 changed files
with
416 additions
and
5 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
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,13 @@ | ||
export class Events { | ||
_id: string = ''; | ||
logAddress: string = ''; | ||
identifier: string = ''; | ||
address: string = ''; | ||
data: string = ''; | ||
topics: string[] = []; | ||
shardID: number = 0; | ||
additionalData: string[] = []; | ||
txOrder: number = 0; | ||
order: number = 0; | ||
timestamp: number = 0; | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
export class EventsFilter { | ||
constructor(init?: Partial<EventsFilter>) { | ||
Object.assign(this, init); | ||
} | ||
|
||
identifier: string = ''; | ||
address: string = ''; | ||
txHash: string = ''; | ||
shard: number = 0; | ||
before: number = 0; | ||
after: number = 0; | ||
} |
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 { ObjectType } from '@nestjs/graphql'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
@ObjectType("Events", { description: "Events object type." }) | ||
export class Events { | ||
constructor(init?: Partial<Events>) { | ||
Object.assign(this, init); | ||
} | ||
|
||
@ApiProperty({ description: "Transaction hash." }) | ||
txHash: string = ''; | ||
|
||
@ApiProperty({ description: "Log address." }) | ||
logAddress: string = ''; | ||
|
||
@ApiProperty({ description: "Event identifier." }) | ||
identifier: string = ''; | ||
|
||
@ApiProperty({ description: "Event address." }) | ||
address: string = ''; | ||
|
||
@ApiProperty({ description: "Event data." }) | ||
data: string = ''; | ||
|
||
@ApiProperty({ description: "Event topics." }) | ||
topics: string[] = []; | ||
|
||
@ApiProperty({ description: "Event shard ID." }) | ||
shardID: number = 0; | ||
|
||
@ApiProperty({ description: "Event additional data." }) | ||
additionalData: string[] = []; | ||
|
||
@ApiProperty({ description: "Event tx order." }) | ||
txOrder: number = 0; | ||
|
||
@ApiProperty({ description: "Event block order." }) | ||
order: number = 0; | ||
|
||
@ApiProperty({ description: "Event timestamp." }) | ||
timestamp: number = 0; | ||
} |
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,78 @@ | ||
import { Controller, DefaultValuePipe, Get, NotFoundException, Param, Query } from '@nestjs/common'; | ||
import { ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'; | ||
import { EventsService } from './events.service'; | ||
import { QueryPagination } from '../../common/entities/query.pagination'; | ||
import { ParseAddressPipe, ParseIntPipe } from '@multiversx/sdk-nestjs-common'; | ||
|
||
import { Events } from './entities/events'; | ||
import { EventsFilter } from './entities/events.filter'; | ||
|
||
@Controller() | ||
@ApiTags('events') | ||
export class EventsController { | ||
constructor( | ||
private readonly eventsService: EventsService, | ||
) { } | ||
|
||
@Get('/events') | ||
@ApiOperation({ summary: 'Events', description: 'Returns events' }) | ||
@ApiOkResponse({ type: [Events] }) | ||
@ApiQuery({ name: 'from', description: 'Number of items to skip for the result set', required: false }) | ||
@ApiQuery({ name: 'size', description: 'Number of items to retrieve', required: false }) | ||
@ApiQuery({ name: 'address', description: 'Event address', required: false }) | ||
@ApiQuery({ name: 'identifier', description: 'Event identifier', required: false }) | ||
@ApiQuery({ name: 'txHash', description: 'Event transaction hash', required: false }) | ||
@ApiQuery({ name: 'shard', description: 'Event shard id', required: false }) | ||
@ApiQuery({ name: 'before', description: 'Event before timestamp', required: false }) | ||
@ApiQuery({ name: 'after', description: 'Event after timestamp', required: false }) | ||
async getEvents( | ||
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number, | ||
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number, | ||
@Query('address', ParseAddressPipe) address: string, | ||
@Query('identifier') identifier: string, | ||
@Query('txHash') txHash: string, | ||
@Query('shard', ParseIntPipe) shard: number, | ||
@Query('before', ParseIntPipe) before: number, | ||
@Query('after', ParseIntPipe) after: number, | ||
): Promise<Events[]> { | ||
return await this.eventsService.getEvents( | ||
new QueryPagination({ from, size }), | ||
new EventsFilter({ address, identifier, txHash, shard, after, before })); | ||
} | ||
|
||
@Get('/events/count') | ||
@ApiOperation({ summary: 'Events count', description: 'Returns events count' }) | ||
@ApiOkResponse({ type: Number }) | ||
@ApiQuery({ name: 'address', description: 'Event address', required: false }) | ||
@ApiQuery({ name: 'identifier', description: 'Event identifier', required: false }) | ||
@ApiQuery({ name: 'txHash', description: 'Event transaction hash', required: false }) | ||
@ApiQuery({ name: 'shard', description: 'Event shard id', required: false }) | ||
@ApiQuery({ name: 'before', description: 'Event before timestamp', required: false }) | ||
@ApiQuery({ name: 'after', description: 'Event after timestamp', required: false }) | ||
async getEventsCount( | ||
@Query('address', ParseAddressPipe) address: string, | ||
@Query('identifier') identifier: string, | ||
@Query('txHash') txHash: string, | ||
@Query('shard', ParseIntPipe) shard: number, | ||
@Query('before', ParseIntPipe) before: number, | ||
@Query('after', ParseIntPipe) after: number, | ||
): Promise<number> { | ||
return await this.eventsService.getEventsCount( | ||
new EventsFilter({ address, identifier, txHash, shard, after, before })); | ||
} | ||
|
||
@Get('/events/:txHash') | ||
@ApiOperation({ summary: 'Event', description: 'Returns event' }) | ||
@ApiOkResponse({ type: Events }) | ||
async getEvent( | ||
@Param('txHash') txHash: string, | ||
): Promise<Events | undefined> { | ||
const result = await this.eventsService.getEvent(txHash); | ||
|
||
if (!result) { | ||
throw new NotFoundException('Event not found'); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { EventsService } from './events.service'; | ||
|
||
@Module({ | ||
providers: [EventsService], | ||
exports: [EventsService], | ||
}) | ||
export class EventsModule { } |
Oops, something went wrong.