Skip to content

Commit

Permalink
Merge pull request #768 from aura-nw/baseline/main_20230419
Browse files Browse the repository at this point in the history
Baseline/euphoria 20230417
  • Loading branch information
nhphuc2411 authored Apr 19, 2023
2 parents 34ed872 + e2e32bb commit ccabe68
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/components/validator/dtos/lite-validator-output.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ export class LiteValidatorOutput {

@Expose()
image_url: string;

@Expose()
voting_power_level: string;
}
15 changes: 12 additions & 3 deletions src/components/validator/repositories/validator.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityRepository, In, Repository } from 'typeorm';
import { EntityRepository, In, Not, Repository } from 'typeorm';

import { Validator } from '../../../shared';

Expand Down Expand Up @@ -37,11 +37,20 @@ export class ValidatorRepository extends Repository<Validator> {
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();
Expand Down
7 changes: 5 additions & 2 deletions src/components/validator/services/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -73,6 +74,8 @@ export class ValidatorService {
),
]);

const validatorsRes = [...activeValidator, ...inActiveValidator];

// Get total proposal on indexer
const proposalCount = proposal?.data?.count || 0;

Expand Down
19 changes: 19 additions & 0 deletions src/migrations/1681266400447-create-column-voting-power-level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class createColumnVotingPowerLevel1681266400447
implements MigrationInterface
{
name = 'createColumnVotingPowerLevel1681266400447';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`validators\` ADD \`voting_power_level\` varchar(255) NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`validators\` DROP COLUMN \`voting_power_level\``,
);
}
}
3 changes: 3 additions & 0 deletions src/shared/entities/validator.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit ccabe68

Please sign in to comment.