Skip to content
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
5 changes: 4 additions & 1 deletion packages/apps/dashboard/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ S3_SECRET_KEY=human-oracle-s3-secret
S3_BUCKET=dashboard-hcaptcha-historical-stats
S3_USE_SSL=false

#Web3
# Web3
WEB3_ENV=testnet
RPC_URL_POLYGON=https://rpc-amoy.polygon.technology
RPC_URL_BSC_TESTNET=https://bsc-testnet.drpc.org
RPC_URL_SEPOLIA=https://rpc.sepolia.org

# Reputation Oracle URL
REPUTATION_SOURCE_URL=http://0.0.0.0:5001

# hCaptcha stats
HCAPTCHA_STATS_ENABLED=false
8 changes: 8 additions & 0 deletions packages/apps/dashboard/server/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER } from '@nestjs/core';
import { ScheduleModule } from '@nestjs/schedule';

import * as Joi from 'joi';

import { AppController } from './app.controller';
import { CacheFactoryConfig } from './common/config/cache-factory.config';
import { CommonConfigModule } from './common/config/config.module';
import { ExceptionFilter } from './common/filters/exception.filter';
import Environment from './common/utils/environment';
import { DetailsModule } from './modules/details/details.module';
import { NetworksModule } from './modules/networks/networks.module';
import { StatsModule } from './modules/stats/stats.module';

@Module({
providers: [
{
provide: APP_FILTER,
useClass: ExceptionFilter,
},
],
imports: [
ConfigModule.forRoot({
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
ArgumentsHost,
Catch,
ExceptionFilter as IExceptionFilter,
HttpStatus,
HttpException,
} from '@nestjs/common';
import { Request, Response } from 'express';

import logger from '../../logger';

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

catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();

let status = HttpStatus.INTERNAL_SERVER_ERROR;
const responseBody: { message: string; [x: string]: unknown } = {
message: 'Internal server error',
};

if (exception instanceof HttpException) {
status = exception.getStatus();
const exceptionResponse = exception.getResponse();
if (typeof exceptionResponse === 'string') {
responseBody.message = exceptionResponse;
} else {
Object.assign(
responseBody,
{
message: exception.message,
},
exceptionResponse,
);
}
} else {
this.logger.error('Unhandled exception', {
error: exception,
path: request.url,
});
}

response.removeHeader('Cache-Control');

response.status(status).json(
Object.assign(
{
statusCode: status,
path: request.url,
timestamp: new Date().toISOString(),
},
responseBody,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Environment {
static readonly name: string =
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;

static readonly version: string = process.env.GIT_HASH || 'n/a';

static isDevelopment(): boolean {
return [
EnvironmentName.DEVELOPMENT,
Expand Down
19 changes: 17 additions & 2 deletions packages/apps/dashboard/server/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import { createLogger, NestLogger, LogLevel } from '@human-protocol/logger';
import {
createLogger,
NestLogger,
LogLevel,
isLogLevel,
} from '@human-protocol/logger';

import Environment from '../common/utils/environment';

const isDevelopment = Environment.isDevelopment();

const LOG_LEVEL_OVERRIDE = process.env.LOG_LEVEL;

let logLevel = LogLevel.INFO;
if (isLogLevel(LOG_LEVEL_OVERRIDE)) {
logLevel = LOG_LEVEL_OVERRIDE;
} else if (isDevelopment) {
logLevel = LogLevel.DEBUG;
}

const defaultLogger = createLogger(
{
name: 'DefaultLogger',
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
level: logLevel,
pretty: isDevelopment,
disabled: Environment.isTest(),
},
{
environment: Environment.name,
service: 'human-protocol-dashboard',
version: Environment.version,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class StatsService implements OnModuleInit {
private async fetchHistoricalHcaptchaStats(): Promise<void> {
let startDate = dayjs(HCAPTCHA_STATS_API_START_DATE);

this.logger.info('Fetching historical hCaptcha stats', {
this.logger.debug('Fetching historical hCaptcha stats', {
startDate,
});

Expand Down Expand Up @@ -169,7 +169,7 @@ export class StatsService implements OnModuleInit {
const from = today;
const to = today;

this.logger.info('Fetching hCaptcha stats for today', { from, to });
this.logger.debug('Fetching hCaptcha stats for today', { from, to });

try {
const { data } = await lastValueFrom(
Expand Down Expand Up @@ -235,7 +235,7 @@ export class StatsService implements OnModuleInit {

@Cron('*/15 * * * *')
async fetchHmtGeneralStats() {
this.logger.info('Fetching HMT general stats across multiple networks');
this.logger.debug('Fetching HMT general stats across multiple networks');

try {
const aggregatedStats: HmtGeneralStatsDto = {
Expand Down
13 changes: 7 additions & 6 deletions packages/apps/fortune/exchange-oracle/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
"start:prod": "node dist/src/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"migration:create": "yarn build && typeorm-ts-node-commonjs migration:create",
"migration:generate": "yarn build && typeorm-ts-node-commonjs migration:generate -p -d typeorm.config.ts",
"migration:revert": "yarn build && typeorm-ts-node-commonjs migration:revert -d typeorm.config.ts",
"migration:run": "yarn build && typeorm-ts-node-commonjs migration:run -d typeorm.config.ts",
"migration:show": "yarn build && typeorm-ts-node-commonjs migration:show -d typeorm.config.ts",
"migration:create": "yarn typeorm migration:create",
"migration:generate": "yarn typeorm migration:generate -p -d typeorm.config.ts",
"migration:revert": "yarn typeorm migration:revert -d typeorm.config.ts",
"migration:run": "yarn typeorm migration:run -d typeorm.config.ts",
"migration:show": "yarn typeorm migration:show -d typeorm.config.ts",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"setup:local": "ts-node ./scripts/setup-staking.ts && LOCAL=true yarn setup:kvstore",
"setup:kvstore": "ts-node ./scripts/setup-kv-store.ts",
"generate-env-doc": "ts-node scripts/generate-env-doc.ts"
"generate-env-doc": "ts-node scripts/generate-env-doc.ts",
"typeorm": "typeorm-ts-node-commonjs"
},
"dependencies": {
"@human-protocol/logger": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export class ExceptionFilter implements IExceptionFilter {
const message = exception.message || 'Internal server error';

if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
this.logger.error('Unhandled exception', exception);
this.logger.error('Unhandled exception', {
error: exception,
path: request.url,
});
}

response.removeHeader('Cache-Control');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Environment {
static readonly name: string =
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;

static readonly version: string = process.env.GIT_HASH || 'n/a';

static isDevelopment(): boolean {
return [
EnvironmentName.DEVELOPMENT,
Expand Down
18 changes: 16 additions & 2 deletions packages/apps/fortune/exchange-oracle/server/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { createLogger, NestLogger, LogLevel } from '@human-protocol/logger';
import {
createLogger,
NestLogger,
LogLevel,
isLogLevel,
} from '@human-protocol/logger';

import Environment from '../common/utils/environment';

const isDevelopment = Environment.isDevelopment();
const LOG_LEVEL_OVERRIDE = process.env.LOG_LEVEL;

let logLevel = LogLevel.INFO;
if (isLogLevel(LOG_LEVEL_OVERRIDE)) {
logLevel = LOG_LEVEL_OVERRIDE;
} else if (isDevelopment) {
logLevel = LogLevel.DEBUG;
}

const defaultLogger = createLogger(
{
name: 'DefaultLogger',
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
level: logLevel,
pretty: isDevelopment,
disabled: Environment.isTest(),
},
{
environment: Environment.name,
service: 'fortune-exchange-oracle',
version: Environment.version,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class CronJobService {
return;
}

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

try {
Expand All @@ -99,7 +99,7 @@ export class CronJobService {
this.logger.error('Error processing pending webhooks', error);
}

this.logger.info('Pending webhooks STOP');
this.logger.debug('Pending webhooks STOP');

await this.completeCronJob(cronJob);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ dotenv.config({

export default new DataSource({
type: 'postgres',
useUTC: true,
url: process.env.POSTGRES_URL,
host: process.env.POSTGRES_HOST,
port: Number(process.env.POSTGRES_PORT),
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DATABASE || 'exchange-oracle',
entities: ['dist/src/**/*.entity{.ts,.js}'],
ssl: process.env.POSTGRES_SSL?.toLowerCase() === 'true',
synchronize: false,
migrations: ['dist/src/database/migrations/*{.ts,.js}'],
migrationsTableName: 'migrations_typeorm',
migrationsRun: true,
migrations: ['src/database/migrations/*.ts'],
migrationsTableName: 'migrations_typeorm',
namingStrategy: new SnakeNamingStrategy(),
ssl: process.env.POSTGRES_SSL?.toLowerCase() === 'true',
entities: ['src/modules/**/*.entity.ts'],
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class ExceptionFilter implements IExceptionFilter {
const message = exception.message || 'Internal server error';

if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
this.logger.error('Unhandled exception', exception);
this.logger.error('Unhandled exception', {
error: exception,
path: request.url,
});
}

response.removeHeader('Cache-Control');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Environment {
static readonly name: string =
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;

static readonly version: string = process.env.GIT_HASH || 'n/a';

static isDevelopment(): boolean {
return [
EnvironmentName.DEVELOPMENT,
Expand Down
19 changes: 17 additions & 2 deletions packages/apps/fortune/recording-oracle/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import { createLogger, NestLogger, LogLevel } from '@human-protocol/logger';
import {
createLogger,
NestLogger,
LogLevel,
isLogLevel,
} from '@human-protocol/logger';

import Environment from '../common/utils/environment';

const isDevelopment = Environment.isDevelopment();

const LOG_LEVEL_OVERRIDE = process.env.LOG_LEVEL;

let logLevel = LogLevel.INFO;
if (isLogLevel(LOG_LEVEL_OVERRIDE)) {
logLevel = LOG_LEVEL_OVERRIDE;
} else if (isDevelopment) {
logLevel = LogLevel.DEBUG;
}

const defaultLogger = createLogger(
{
name: 'DefaultLogger',
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
level: logLevel,
pretty: isDevelopment,
disabled: Environment.isTest(),
},
{
environment: Environment.name,
service: 'fortune-recording-oracle',
version: Environment.version,
},
);

Expand Down
1 change: 0 additions & 1 deletion packages/apps/human-app/frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ VITE_NAVBAR__LINK__PROTOCOL_URL=https://humanprotocol.org/
VITE_PRIVACY_POLICY_URL=http://local.app/privacy-policy/
VITE_TERMS_OF_SERVICE_URL=http://local.app/terms-and-conditions/

VITE_GOVERNOR_ADDRESS=
VITE_GOVERNANCE_URL=

# Feature flags
Expand Down
Loading
Loading