Skip to content
Closed
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"scripts": {
"clean": "yarn workspaces foreach --all -p run clean",
"lint": "yarn workspaces foreach --all -p run lint",
"test": "yarn workspaces foreach --all -p run test",
"build:core": "yarn workspace @human-protocol/core build",
"build:sdk": "yarn workspace @human-protocol/sdk build",
"build:libs": "yarn build:core && yarn build:sdk",
"build:logger": "yarn workspace @human-protocol/logger build",
"build:libs": "yarn build:core && yarn build:sdk && yarn build:logger",
"docker:infra-up": "make -C ./docker-setup -f Makefile.dev infra-up",
"docker:infra-stop": "make -C ./docker-setup -f Makefile.dev infra-stop",
"docker:infra-down": "make -C ./docker-setup -f Makefile.dev infra-down",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/dashboard/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@human-protocol/core": "workspace:*",
"@human-protocol/logger": "workspace:*",
"@human-protocol/sdk": "workspace:*",
"@nestjs/axios": "^3.1.2",
"@nestjs/cache-manager": "^2.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { ConfigModule } from '@nestjs/config';
import * as _ from 'lodash';
import { RedisConfigService } from './redis-config.service';
import { redisStore } from 'cache-manager-redis-yet';
import { Logger } from '@nestjs/common';
import Logger from '@human-protocol/logger';

const logger = new Logger('CacheFactoryRedisStore');
const logger = Logger.child({
context: 'CacheFactoryRedisStore',
});

const throttledRedisErrorLog = _.throttle((error) => {
logger.error('Redis client network error', error);
Expand Down
13 changes: 8 additions & 5 deletions packages/apps/dashboard/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import { AppModule } from './app.module';
import { EnvironmentConfigService } from './common/config/env-config.service';
import {
createServiceLogger,
nestLoggerOverride,
} from '@human-protocol/logger';

const logger = createServiceLogger('dashboard');

async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger:
process.env.NODE_ENV === 'development'
? ['log', 'debug', 'error', 'verbose', 'warn']
: ['log', 'error', 'warn'],
logger: nestLoggerOverride,
});

const configService: ConfigService = app.get(ConfigService);
Expand All @@ -35,7 +38,7 @@ async function bootstrap() {
const port = envConfigService.port;

await app.listen(port, host, async () => {
console.info(`Dashboard server is running on http://${host}:${port}`);
logger.info(`Dashboard server is running on http://${host}:${port}`);
});
}
bootstrap();
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { plainToInstance } from 'class-transformer';
import {
BadRequestException,
Injectable,
Logger,
Inject,
} from '@nestjs/common';
import { BadRequestException, Injectable, Inject } from '@nestjs/common';
import { Cache, CACHE_MANAGER } from '@nestjs/cache-manager';
import {
ChainId,
Expand Down Expand Up @@ -40,10 +35,14 @@ import {
} from '../../common/constants/operator';
import { GetOperatorsPaginationOptions } from 'src/common/types';
import { KVStoreDataDto } from './dto/details-response.dto';
import Logger from '@human-protocol/logger';

@Injectable()
export class DetailsService {
private readonly logger = new Logger(DetailsService.name);
private readonly logger = Logger.child({
context: DetailsService.name,
});

constructor(
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
private readonly configService: EnvironmentConfigService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { ChainId, NETWORKS, StatisticsClient } from '@human-protocol/sdk';
import { Cache, CACHE_MANAGER } from '@nestjs/cache-manager';

Expand All @@ -9,10 +9,14 @@ import {
} from '../../common/config/env-config.service';
import { OPERATING_NETWORKS_CACHE_KEY } from '../../common/config/redis-config.service';
import { NetworkConfigService } from '../../common/config/network-config.service';
import Logger from '@human-protocol/logger';

@Injectable()
export class NetworksService {
private readonly logger = new Logger(NetworksService.name);
private readonly logger = Logger.child({
context: NetworksService.name,
});

constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
private readonly envConfigService: EnvironmentConfigService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { lastValueFrom } from 'rxjs';
import dayjs from 'dayjs';
Expand All @@ -25,10 +25,14 @@ import { StorageService } from '../storage/storage.service';
import { CronJob } from 'cron';
import { SchedulerRegistry } from '@nestjs/schedule';
import { NetworksService } from '../networks/networks.service';
import Logger from '@human-protocol/logger';

@Injectable()
export class StatsService implements OnModuleInit {
private readonly logger = new Logger(StatsService.name);
private readonly logger = Logger.child({
context: StatsService.name,
});

constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
private readonly redisConfigService: RedisConfigService,
Expand Down Expand Up @@ -75,7 +79,7 @@ export class StatsService implements OnModuleInit {
}

private async fetchHistoricalHcaptchaStats(): Promise<void> {
this.logger.log('Fetching historical hCaptcha stats.');
this.logger.info('Fetching historical hCaptcha stats.');
let startDate = dayjs(HCAPTCHA_STATS_API_START_DATE);
const currentDate = dayjs();
const dates = [];
Expand Down Expand Up @@ -132,7 +136,7 @@ export class StatsService implements OnModuleInit {
}

async fetchTodayHcaptchaStats() {
this.logger.log('Fetching hCaptcha stats for today.');
this.logger.info('Fetching hCaptcha stats for today.');
const today = dayjs().format('YYYY-MM-DD');
const from = today;
const to = today;
Expand Down Expand Up @@ -188,7 +192,7 @@ export class StatsService implements OnModuleInit {

@Cron('*/15 * * * *')
async fetchHmtGeneralStats() {
this.logger.log('Fetching HMT general stats across multiple networks.');
this.logger.info('Fetching HMT general stats across multiple networks.');
const aggregatedStats: HmtGeneralStatsDto = {
totalHolders: 0,
totalTransactions: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import * as Minio from 'minio';
import { S3ConfigService } from '../../common/config/s3-config.service';
import { Readable } from 'stream';
import Logger from '@human-protocol/logger';

@Injectable()
export class StorageService {
private readonly logger = new Logger(StorageService.name);
private readonly logger = Logger.child({
context: StorageService.name,
});

public readonly minioClient: Minio.Client;

constructor(private s3ConfigService: S3ConfigService) {
Expand Down Expand Up @@ -52,7 +56,7 @@ export class StorageService {
});
});
} catch (e) {
this.logger.log(e);
this.logger.info(e);
return [];
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/apps/fortune/exchange-oracle/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"generate-env-doc": "ts-node scripts/generate-env-doc.ts"
},
"dependencies": {
"@human-protocol/logger": "workspace:*",
"@human-protocol/sdk": "workspace:*",
"@nestjs/axios": "^3.1.2",
"@nestjs/common": "^10.2.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Catch,
ExceptionFilter as IExceptionFilter,
HttpStatus,
Logger,
} from '@nestjs/common';
import { Request, Response } from 'express';
import {
Expand All @@ -15,10 +14,13 @@ import {
ServerError,
DatabaseError,
} from '../errors';
import Logger from '@human-protocol/logger';

@Catch()
export class ExceptionFilter implements IExceptionFilter {
private logger = new Logger(ExceptionFilter.name);
private logger = Logger.child({
context: ExceptionFilter.name,
});

private getStatus(exception: any): number {
if (exception instanceof ValidationError) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { EscrowUtils } from '@human-protocol/sdk';
import {
CanActivate,
ExecutionContext,
Injectable,
Logger,
} from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AssignmentRepository } from '../../modules/assignment/assignment.repository';
import { HEADER_SIGNATURE_KEY } from '../constant';
import { ErrorAssignment, ErrorSignature } from '../constant/errors';
import { AuthSignatureRole } from '../enums/role';
import { AuthError, NotFoundError } from '../errors';
import { verifySignature } from '../utils/signature';
import Logger from '@human-protocol/logger';

@Injectable()
export class SignatureAuthGuard implements CanActivate {
private readonly logger = new Logger(SignatureAuthGuard.name);
private readonly logger = Logger.child({
context: SignatureAuthGuard.name,
});

constructor(
private reflector: Reflector,
private readonly assignmentRepository: AssignmentRepository,
Expand Down
6 changes: 5 additions & 1 deletion packages/apps/fortune/exchange-oracle/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import { useContainer } from 'class-validator';
import { AppModule } from './app.module';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { ServerConfigService } from './common/config/server-config.service';
import { createServiceLogger, nestLoggerOverride } from '@human-protocol/logger';

const logger = createServiceLogger('fortune-exchange-oracle');

async function bootstrap() {
const app = await NestFactory.create<INestApplication>(AppModule, {
cors: true,
logger: nestLoggerOverride,
});

const configService: ConfigService = app.get(ConfigService);
Expand Down Expand Up @@ -51,7 +55,7 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ transform: true }));

await app.listen(port, host, async () => {
console.info(`API server is running on http://${host}:${port}`);
logger.info(`API server is running on http://${host}:${port}`);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Escrow__factory } from '@human-protocol/core/typechain-types';
import { Injectable, Logger } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { ServerConfigService } from '../../common/config/server-config.service';
import { ErrorAssignment, ErrorJob } from '../../common/constant/errors';
import { AssignmentStatus, JobStatus, JobType } from '../../common/enums/job';
Expand All @@ -20,10 +20,13 @@ import {
} from './assignment.dto';
import { AssignmentEntity } from './assignment.entity';
import { AssignmentRepository } from './assignment.repository';
import Logger from '@human-protocol/logger';

@Injectable()
export class AssignmentService {
private readonly logger = new Logger(AssignmentService.name);
private readonly logger = Logger.child({
context: AssignmentService.name,
});

constructor(
private readonly assignmentRepository: AssignmentRepository,
Expand All @@ -43,16 +46,13 @@ export class AssignmentService {
);

if (!jobEntity) {
this.logger.log(ErrorAssignment.JobNotFound, AssignmentService.name);
this.logger.info(ErrorAssignment.JobNotFound);
throw new ServerError(ErrorAssignment.JobNotFound);
} else if (jobEntity.status !== JobStatus.ACTIVE) {
this.logger.log(ErrorJob.InvalidStatus, AssignmentService.name);
this.logger.info(ErrorJob.InvalidStatus);
throw new ConflictError(ErrorJob.InvalidStatus);
} else if (jobEntity.reputationNetwork !== jwtUser.reputationNetwork) {
this.logger.log(
ErrorAssignment.ReputationNetworkMismatch,
AssignmentService.name,
);
this.logger.info(ErrorAssignment.ReputationNetworkMismatch);
throw new ValidationError(ErrorAssignment.ReputationNetworkMismatch);
}

Expand All @@ -66,7 +66,7 @@ export class AssignmentService {
assignmentEntity &&
assignmentEntity.status !== AssignmentStatus.CANCELED
) {
this.logger.log(ErrorAssignment.AlreadyExists, AssignmentService.name);
this.logger.info(ErrorAssignment.AlreadyExists);
throw new ConflictError(ErrorAssignment.AlreadyExists);
}

Expand All @@ -90,15 +90,15 @@ export class AssignmentService {
}

if (currentAssignments >= manifest.submissionsRequired) {
this.logger.log(ErrorAssignment.FullyAssigned, AssignmentService.name);
this.logger.info(ErrorAssignment.FullyAssigned);
throw new ValidationError(ErrorAssignment.FullyAssigned);
}

const signer = this.web3Service.getSigner(data.chainId);
const escrow = Escrow__factory.connect(data.escrowAddress, signer);
const expirationDate = new Date(Number(await escrow.duration()) * 1000);
if (expirationDate < new Date()) {
this.logger.log(ErrorAssignment.ExpiredEscrow, AssignmentService.name);
this.logger.info(ErrorAssignment.ExpiredEscrow);
throw new ValidationError(ErrorAssignment.ExpiredEscrow);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Injectable } from '@nestjs/common';

import { Cron } from '@nestjs/schedule';
import { ErrorCronJob } from '../../common/constant/errors';
Expand All @@ -8,10 +8,13 @@ import { WebhookRepository } from '../webhook/webhook.repository';
import { WebhookService } from '../webhook/webhook.service';
import { CronJobEntity } from './cron-job.entity';
import { CronJobRepository } from './cron-job.repository';
import Logger from '@human-protocol/logger';

@Injectable()
export class CronJobService {
private readonly logger = new Logger(CronJobService.name);
private readonly logger = Logger.child({
context: CronJobService.name,
});

constructor(
private readonly cronJobRepository: CronJobRepository,
Expand Down Expand Up @@ -39,7 +42,7 @@ export class CronJobService {
return false;
}

this.logger.log('Previous cron job is not completed yet');
this.logger.info('Previous cron job is not completed yet');
return true;
}

Expand Down Expand Up @@ -69,7 +72,7 @@ export class CronJobService {
return;
}

this.logger.log('Pending webhooks START');
this.logger.info('Pending webhooks START');
const cronJob = await this.startCronJob(CronJobType.ProcessPendingWebhook);

try {
Expand All @@ -92,7 +95,7 @@ export class CronJobService {
this.logger.error(e);
}

this.logger.log('Pending webhooks STOP');
this.logger.info('Pending webhooks STOP');
await this.completeCronJob(cronJob);
}
}
Loading
Loading