From e2e32bb7bc5f968becb8c66d7338a4c20e614687 Mon Sep 17 00:00:00 2001 From: Duc Nguyen <119287881+nthduc95@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:34:12 +0700 Subject: [PATCH] Baseline/euphoria 20230417 (#767) --- .../dtos/lite-validator-output.dto.ts | 3 +++ .../repositories/validator.repository.ts | 15 ++++++++++++--- .../validator/services/validator.service.ts | 7 +++++-- ...400447-create-column-voting-power-level.ts | 19 +++++++++++++++++++ src/shared/entities/validator.entity.ts | 3 +++ 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/migrations/1681266400447-create-column-voting-power-level.ts diff --git a/src/components/validator/dtos/lite-validator-output.dto.ts b/src/components/validator/dtos/lite-validator-output.dto.ts index 42bdfbe7..6818b983 100644 --- a/src/components/validator/dtos/lite-validator-output.dto.ts +++ b/src/components/validator/dtos/lite-validator-output.dto.ts @@ -58,4 +58,7 @@ export class LiteValidatorOutput { @Expose() image_url: string; + + @Expose() + voting_power_level: string; } diff --git a/src/components/validator/repositories/validator.repository.ts b/src/components/validator/repositories/validator.repository.ts index 0ba1d661..22321abf 100644 --- a/src/components/validator/repositories/validator.repository.ts +++ b/src/components/validator/repositories/validator.repository.ts @@ -1,4 +1,4 @@ -import { EntityRepository, In, Repository } from 'typeorm'; +import { EntityRepository, In, Not, Repository } from 'typeorm'; import { Validator } from '../../../shared'; @@ -37,11 +37,20 @@ export class ValidatorRepository extends Repository { return await rankBuilder.getRawMany(); } - async getAllValidators() { + async getAllActiveValidators() { return await this.createQueryBuilder('v') .select('v.*') + .where({ status: 3 }) + .addOrderBy('power', 'DESC') + .addOrderBy('updated_at', 'DESC') + .getRawMany(); + } + + async getAllInActiveValidators() { + return await this.createQueryBuilder('v') + .select('v.*') + .where({ status: Not(3) }) .orderBy('jailed', 'ASC') - .addOrderBy('status', 'DESC') .addOrderBy('power', 'DESC') .addOrderBy('updated_at', 'DESC') .getRawMany(); diff --git a/src/components/validator/services/validator.service.ts b/src/components/validator/services/validator.service.ts index a65d8c17..7dc88375 100644 --- a/src/components/validator/services/validator.service.ts +++ b/src/components/validator/services/validator.service.ts @@ -59,8 +59,9 @@ export class ValidatorService { ctx: RequestContext, ): Promise<{ validators: LiteValidatorOutput[] }> { this.logger.log(ctx, `${this.getValidators.name} was called!`); - const [validatorsRes, proposal] = await Promise.all([ - this.validatorRepository.getAllValidators(), + const [activeValidator, inActiveValidator, proposal] = await Promise.all([ + this.validatorRepository.getAllActiveValidators(), + this.validatorRepository.getAllInActiveValidators(), this.serviceUtil.getDataAPI( `${this.indexerUrl}${util.format( INDEXER_API.GET_PROPOSAL, @@ -73,6 +74,8 @@ export class ValidatorService { ), ]); + const validatorsRes = [...activeValidator, ...inActiveValidator]; + // Get total proposal on indexer const proposalCount = proposal?.data?.count || 0; diff --git a/src/migrations/1681266400447-create-column-voting-power-level.ts b/src/migrations/1681266400447-create-column-voting-power-level.ts new file mode 100644 index 00000000..63c5c1dc --- /dev/null +++ b/src/migrations/1681266400447-create-column-voting-power-level.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class createColumnVotingPowerLevel1681266400447 + implements MigrationInterface +{ + name = 'createColumnVotingPowerLevel1681266400447'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE \`validators\` ADD \`voting_power_level\` varchar(255) NULL`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE \`validators\` DROP COLUMN \`voting_power_level\``, + ); + } +} diff --git a/src/shared/entities/validator.entity.ts b/src/shared/entities/validator.entity.ts index 46ae8707..109b19a6 100644 --- a/src/shared/entities/validator.entity.ts +++ b/src/shared/entities/validator.entity.ts @@ -75,4 +75,7 @@ export class Validator extends BaseEntity { @Column({ name: 'image_url', nullable: true, type: 'nvarchar' }) image_url: string; + + @Column({ name: 'voting_power_level', nullable: true }) + voting_power_level: string; }