-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Recording Oracle] - Refactored (#732)
* Added interfaces and enums * Refactored job service and unit tests * Refactored services * Refactored configs * Added config files * Resolved comments * Call StoreResults only once (#733) * Fixed lint errors * Updated lint (#783)
- Loading branch information
1 parent
e8db754
commit 60ecff3
Showing
44 changed files
with
988 additions
and
491 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"singleQuote": false | ||
} | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
10 changes: 5 additions & 5 deletions
10
packages/apps/fortune/recording-oracle/src/app.controller.spec.ts
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { AppController } from "./app.controller"; | ||
import { AppController } from './app.controller'; | ||
|
||
describe("AppController", () => { | ||
describe('AppController', () => { | ||
let appController: AppController; | ||
|
||
beforeEach(() => { | ||
appController = new AppController(); | ||
}); | ||
|
||
describe("Health Check", () => { | ||
it("should return OK", async () => { | ||
expect(await appController.health()).toBe("OK"); | ||
describe('Health Check', () => { | ||
it('should return OK', async () => { | ||
expect(await appController.health()).toBe('OK'); | ||
}); | ||
}); | ||
}); |
14 changes: 7 additions & 7 deletions
14
packages/apps/fortune/recording-oracle/src/app.controller.ts
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { Controller, Get } from "@nestjs/common"; | ||
import { ApiTags } from "@nestjs/swagger"; | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
|
||
import { Public } from "@/common/decorators"; | ||
import { Public } from '@/common/decorators'; | ||
|
||
@Controller("/") | ||
@Controller('/') | ||
export class AppController { | ||
@Public() | ||
@Get("/") | ||
@ApiTags("Health Check") | ||
@Get('/') | ||
@ApiTags('Health Check') | ||
public health(): string { | ||
return "OK"; | ||
return 'OK'; | ||
} | ||
} |
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
7 changes: 0 additions & 7 deletions
7
packages/apps/fortune/recording-oracle/src/common/config/ethereum.config.ts
This file was deleted.
Oops, something went wrong.
7 changes: 4 additions & 3 deletions
7
packages/apps/fortune/recording-oracle/src/common/config/index.ts
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./ethereum.config"; | ||
export * from "./server.config"; | ||
export * from "./storage.config"; | ||
export * from './web3'; | ||
export * from './server'; | ||
export * from './s3'; | ||
export * from './validation'; |
13 changes: 13 additions & 0 deletions
13
packages/apps/fortune/recording-oracle/src/common/config/s3.ts
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 @@ | ||
import { ConfigType, registerAs } from '@nestjs/config'; | ||
|
||
export const s3Config = registerAs('s3', () => ({ | ||
endPoint: process.env.S3_ENDPOINT!, | ||
port: +process.env.S3_PORT!, | ||
accessKey: process.env.S3_ACCESS_KEY!, | ||
secretKey: process.env.S3_SECRET_KEY!, | ||
bucket: process.env.S3_BACKET!, | ||
useSSL: process.env.S3_USE_SSL === 'true', | ||
})); | ||
|
||
export const s3ConfigKey = s3Config.KEY; | ||
export type S3ConfigType = ConfigType<typeof s3Config>; |
11 changes: 0 additions & 11 deletions
11
packages/apps/fortune/recording-oracle/src/common/config/server.config.ts
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
packages/apps/fortune/recording-oracle/src/common/config/server.ts
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,11 @@ | ||
import { ConfigType, registerAs } from '@nestjs/config'; | ||
|
||
export const serverConfig = registerAs('server', () => ({ | ||
host: process.env.HOST!, | ||
port: +process.env.PORT!, | ||
sessionSecret: process.env.SESSION_SECRET!, | ||
feUrl: process.env.FE_URL!, | ||
reputationOracleWebhookUrl: process.env.REPUTATION_ORACLE_WEBHOOK_URL!, | ||
})); | ||
export const serverConfigKey = serverConfig.KEY; | ||
export type ServerConfigType = ConfigType<typeof serverConfig>; |
12 changes: 0 additions & 12 deletions
12
packages/apps/fortune/recording-oracle/src/common/config/storage.config.ts
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
packages/apps/fortune/recording-oracle/src/common/config/validation.ts
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,36 @@ | ||
import * as Joi from 'joi'; | ||
|
||
export const ConfigNames = { | ||
NODE_ENV: 'NODE_ENV', | ||
HOST: 'HOST', | ||
PORT: 'PORT', | ||
FE_URL: 'FE_URL', | ||
SESSION_SECRET: 'SESSION_SECRET', | ||
WEB3_PRIVATE_KEY: 'WEB3_PRIVATE_KEY', | ||
REPUTATION_ORACLE_WEBHOOK_URL: 'REPUTATION_ORACLE_WEBHOOK_URL', | ||
S3_ENDPOINT: 'S3_ENDPOINT', | ||
S3_PORT: 'S3_PORT', | ||
S3_ACCESS_KEY: 'S3_ACCESS_KEY', | ||
S3_SECRET_KEY: 'S3_SECRET_KEY', | ||
S3_BACKET: 'S3_BACKET', | ||
S3_USE_SSL: 'S3_USE_SSL', | ||
}; | ||
|
||
export const envValidator = Joi.object({ | ||
// General | ||
NODE_ENV: Joi.string().default('development'), | ||
HOST: Joi.string().default('localhost'), | ||
PORT: Joi.string().default(5000), | ||
FE_URL: Joi.string().default('http://localhost:3001'), | ||
SESSION_SECRET: Joi.string().default('session_key'), | ||
// Web3 | ||
WEB3_PRIVATE_KEY: Joi.string().required(), | ||
REPUTATION_ORACLE_WEBHOOK_URL: Joi.string().default('http://localhost:4005'), | ||
// S3 | ||
S3_ENDPOINT: Joi.string().default('127.0.0.1'), | ||
S3_PORT: Joi.string().default(9000), | ||
S3_ACCESS_KEY: Joi.string().required(), | ||
S3_SECRET_KEY: Joi.string().required(), | ||
S3_BACKET: Joi.string().default('solution'), | ||
S3_USE_SSL: Joi.string().default(false), | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/apps/fortune/recording-oracle/src/common/config/web3.ts
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 { ConfigType, registerAs } from '@nestjs/config'; | ||
|
||
export const web3Config = registerAs('web3', () => ({ | ||
web3PrivateKey: process.env.WEB3_PRIVATE_KEY!, | ||
})); | ||
|
||
export const web3ConfigKey = web3Config.KEY; | ||
export type Web3ConfigType = ConfigType<typeof web3Config>; |
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
1 change: 0 additions & 1 deletion
1
packages/apps/fortune/recording-oracle/src/common/constants/index.ts
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
packages/apps/fortune/recording-oracle/src/common/constants/network.ts
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
packages/apps/fortune/recording-oracle/src/common/constants/networks.ts
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,32 @@ | ||
import { NetworkMapDto } from '../interfaces/network'; | ||
|
||
export const networkMap: NetworkMapDto = { | ||
polygon: { | ||
chainId: 137, | ||
rpcUrl: | ||
'https://polygon-mainnet.g.alchemy.com/v2/0Lorh5KRkGl5FsRwy2epTg8fEFFoqUfY', | ||
}, | ||
bsc: { | ||
chainId: 56, | ||
rpcUrl: 'https://bsc-dataseed1.binance.org/', | ||
}, | ||
mumbai: { | ||
chainId: 80001, | ||
rpcUrl: | ||
'https://polygon-mumbai.g.alchemy.com/v2/vKNSJzJf6SW2sdW-05bgFwoyFxUrMzii', | ||
}, | ||
goerli: { | ||
chainId: 5, | ||
rpcUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', | ||
}, | ||
moonbeam: { | ||
chainId: 1284, | ||
rpcUrl: 'https://rpc.api.moonbeam.network', | ||
}, | ||
bsctest: { | ||
chainId: 97, | ||
rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/', | ||
}, | ||
}; | ||
|
||
export const networks = Object.values(networkMap).map((network) => network); |
2 changes: 1 addition & 1 deletion
2
packages/apps/fortune/recording-oracle/src/common/decorators/index.ts
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./public"; | ||
export * from './public'; |
5 changes: 3 additions & 2 deletions
5
packages/apps/fortune/recording-oracle/src/common/decorators/public.ts
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { SetMetadata } from "@nestjs/common"; | ||
import { SetMetadata } from '@nestjs/common'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const Public = (): ((target: any, key?: any, descriptor?: any) => any) => SetMetadata("isPublic", true); | ||
export const Public = (): ((target: any, key?: any, descriptor?: any) => any) => | ||
SetMetadata('isPublic', true); |
3 changes: 3 additions & 0 deletions
3
packages/apps/fortune/recording-oracle/src/common/enums/job.ts
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,3 @@ | ||
export enum JobRequestType { | ||
FORTUNE = 'FORTUNE', | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/apps/fortune/recording-oracle/src/common/filter/index.ts
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./global-exceptions.filter"; | ||
export * from './global-exceptions.filter'; |
16 changes: 16 additions & 0 deletions
16
packages/apps/fortune/recording-oracle/src/common/interfaces/job.ts
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,16 @@ | ||
import { ChainId } from '@human-protocol/sdk'; | ||
import { JobRequestType } from '../enums/job'; | ||
|
||
export interface IManifest { | ||
submissionsRequired: number; | ||
requesterTitle: string; | ||
requesterDescription: string; | ||
fundAmount: string; | ||
requestType: JobRequestType; | ||
} | ||
|
||
export interface ISolution { | ||
exchangeAddress: string; | ||
workerAddress: string; | ||
solution: string; | ||
} |
Oops, something went wrong.