Skip to content

Commit fd2a04b

Browse files
committed
fix: chain id usage on jl
1 parent 24c5f18 commit fd2a04b

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

packages/apps/job-launcher/server/src/common/guards/jwt.auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import {
66
} from '@nestjs/common';
77
import { ModuleRef, Reflector } from '@nestjs/core';
88
import { AuthGuard } from '@nestjs/passport';
9+
import logger from '../../logger';
910
import { AuthError, ForbiddenError } from '../errors';
1011
import { ApiKeyGuard } from './apikey.auth';
1112

1213
@Injectable()
1314
export class JwtAuthGuard extends AuthGuard('jwt-http') implements CanActivate {
15+
private readonly logger = logger.child({ context: JwtAuthGuard.name });
16+
1417
constructor(
1518
private readonly reflector: Reflector,
1619
private readonly moduleRef: ModuleRef,
@@ -29,7 +32,9 @@ export class JwtAuthGuard extends AuthGuard('jwt-http') implements CanActivate {
2932
try {
3033
return apiKeyGuard.canActivate(context);
3134
} catch (apiKeyError) {
32-
console.error('API key auth failed:', apiKeyError);
35+
this.logger.error('API key auth failed', {
36+
error: apiKeyError,
37+
});
3338
}
3439
}
3540

packages/apps/job-launcher/server/src/modules/cron-job/cron-job.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,15 @@ export class CronJobService {
468468
await this.cronJobRepository.save(cronJob);
469469
}
470470
} catch (error) {
471-
this.logger.error('Error in syncJobStatuses cron job', error);
471+
this.logger.error('Error in syncJobStatuses cron job', {
472+
error,
473+
});
472474
}
473475

474476
this.logger.debug('Update jobs STOP');
475477
await this.completeCronJob(cronJob);
476478
}
479+
477480
private async createCancellationWebhooks(
478481
jobEntity: JobEntity,
479482
oracleType: OracleType,

packages/apps/job-launcher/server/src/modules/web3/web3.controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AvailableOraclesDto,
99
GetAvailableOraclesDto,
1010
GetReputationOraclesDto,
11+
validChainIds,
1112
} from './web3.dto';
1213

1314
@ApiTags('Web3')
@@ -29,9 +30,7 @@ export class Web3Controller {
2930
type: 'array',
3031
items: {
3132
type: 'number',
32-
enum: Object.values(ChainId).filter(
33-
(value) => typeof value === 'number' && value > 0,
34-
) as number[],
33+
enum: validChainIds,
3534
},
3635
},
3736
})

packages/apps/job-launcher/server/src/modules/web3/web3.dto.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ChainId, IOperator } from '@human-protocol/sdk';
2+
import { applyDecorators } from '@nestjs/common';
23
import { ApiProperty } from '@nestjs/swagger';
3-
import { IsString } from 'class-validator';
4+
import { Transform } from 'class-transformer';
5+
import { IsIn, IsString } from 'class-validator';
46

57
export class OracleDataDto implements Partial<IOperator> {
68
address: string;
@@ -9,6 +11,17 @@ export class OracleDataDto implements Partial<IOperator> {
911
jobTypes?: string[] | null;
1012
}
1113

14+
export const validChainIds = Object.values(ChainId).filter(
15+
(value) => typeof value === 'number' && value > 0,
16+
) as number[];
17+
18+
function IsValidChainId() {
19+
return applyDecorators(
20+
IsIn(validChainIds),
21+
Transform(({ value }) => Number(value)),
22+
);
23+
}
24+
1225
export class AvailableOraclesDto {
1326
@ApiProperty({
1427
description: 'List of addresses of exchange oracles',
@@ -22,8 +35,8 @@ export class AvailableOraclesDto {
2235
}
2336

2437
export class GetAvailableOraclesDto {
25-
@ApiProperty({ name: 'chain_id' })
26-
@IsString()
38+
@ApiProperty({ name: 'chain_id', enum: validChainIds })
39+
@IsValidChainId()
2740
chainId: ChainId;
2841

2942
@ApiProperty({ name: 'job_type' })
@@ -36,8 +49,8 @@ export class GetAvailableOraclesDto {
3649
}
3750

3851
export class GetReputationOraclesDto {
39-
@ApiProperty({ name: 'chain_id' })
40-
@IsString()
52+
@ApiProperty({ name: 'chain_id', enum: validChainIds })
53+
@IsValidChainId()
4154
chainId: ChainId;
4255

4356
@ApiProperty({ name: 'job_type' })

0 commit comments

Comments
 (0)