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

Mantle #59

Merged
merged 3 commits into from
May 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/apps/monitor-service/src/mantle/mantle.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TopicName } from '@app/utils/topicUtils';
import { Controller, Logger } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';
import { MantleService } from './mantle.service';

@Controller()
export class MantleController {
private readonly logger = new Logger(MantleController.name);
constructor(private readonly mantle: MantleService) {}

@EventPattern(TopicName.MANTLE_NATIVE_TRANSFER)
async handleNativeTransfer(data: any) {
const start = Date.now();
await this.mantle.handleNativeTransfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle native transfer in : ${Date.now() - start}`);
}

@EventPattern(TopicName.MANTLE_ERC20_TRANSFER)
async handleErc20Transfer(data: any) {
const start = Date.now();
await this.mantle.handleErc20Transfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle erc20 transfer in : ${Date.now() - start}`);
}

@EventPattern(TopicName.MANTLE_ERC721_TRANSFER)
async handleErc721Transfer(data: any) {
const start = Date.now();
await this.mantle.handleErc721Transfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle erc721 transfer in : ${Date.now() - start}`);
}
}
54 changes: 54 additions & 0 deletions app/apps/monitor-service/src/mantle/mantle.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { EventHistoryModelModule } from '@app/shared_modules/event_history/event_history.module';
import { MonitorModule } from '@app/shared_modules/monitor/monitor.module';
import { ProjectModule } from '@app/shared_modules/project/project.module';
import { WebhookModule } from '@app/shared_modules/webhook/webhook.module';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { MantleController } from './mantle.controller';
import { MantleService } from './mantle.service';

@Module({
providers: [MantleService],
controllers: [MantleController],
exports: [MantleService],
imports: [
ClientsModule.registerAsync([
{
name: 'WEBHOOK_SERVICE',
useFactory: () => ({
transport: Transport.KAFKA,
options: {
client: {
clientId: 'webhook',
brokers: process.env.KAFKA_BROKERS.split(','),
ssl: process.env.KAFKA_SSL === 'true',
sasl:
process.env.KAFKA_AUTH_ENABLE === 'true'
? {
mechanism: 'plain',
username: process.env.KAFKA_USERNAME || '',
password: process.env.KAFKA_PASSWORD || '',
}
: null,
retry: {
restartOnFailure: async (e) => {
console.log('RESTART ON FAILURE mantle module');
console.log(e);
return true;
},
},
},
consumer: {
groupId: 'webhook-consumer',
},
},
}),
},
]),
WebhookModule,
MonitorModule,
ProjectModule,
EventHistoryModelModule,
],
})
export class MantleModule {}
Loading