Skip to content

Commit

Permalink
Merge pull request #63 from 0LNetworkCommunity/fix/vfn-status
Browse files Browse the repository at this point in the history
Fix: Change VFN Status Type to Enum and Fix Web-App Build
  • Loading branch information
soaresa authored Nov 9, 2024
2 parents 5a525dd + 124f90e commit 82be75e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
12 changes: 9 additions & 3 deletions api/src/ol/models/validator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export class GqlValidatorGrade {
public failedBlocks: number;
}

export enum VfnStatusType {
InvalidAddress = 'invalidAddress',
Accessible = 'accessible',
NotAccessible = 'notAccessible',
}

interface ValidatorInput {
inSet: boolean;
index: BN;
Expand All @@ -100,7 +106,7 @@ interface ValidatorInput {
balance?: number;
unlocked?: number;
votingPower: BN;
vfnStatus?: String | null;
vfnStatus?: VfnStatusType | null;
grade?: GqlValidatorGrade | null;
vouches: Vouches;
currentBid: GqlValidatorCurrentBid;
Expand Down Expand Up @@ -150,7 +156,7 @@ export class Validator {
public votingPower: BN;

@Field(() => String, { nullable: true })
public vfnStatus?: String | null;
public vfnStatus?: VfnStatusType | null;

@Field(() => GqlValidatorGrade, { nullable: true })
public grade?: GqlValidatorGrade | null;
Expand Down Expand Up @@ -236,7 +242,7 @@ export class VouchDetails {

interface VfnStatusInput {
address: string;
status: string;
status: VfnStatusType;
}

@ObjectType()
Expand Down
17 changes: 9 additions & 8 deletions api/src/ol/validators/validators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ValidatorUtils,
//ThermostatMeasure,
VfnStatus,
VfnStatusType,
} from '../models/validator.model.js';
import { parseAddress } from '../../utils.js';
import { redisClient } from '../../redis/redis.service.js';
Expand Down Expand Up @@ -490,19 +491,19 @@ export class ValidatorsService {
return ret;
}

async getVfnStatus(address: string): Promise<string | null> {
async getVfnStatus(address: string): Promise<VfnStatusType | null> {
const cacheData = await this.getFromCache<VfnStatus[]>(VALIDATORS_VFN_STATUS_CACHE_KEY);
if (cacheData) {
const vfnStatus = cacheData.find((item) => item.address === address);
return vfnStatus ? vfnStatus.status : null;
return vfnStatus ? (vfnStatus.status as VfnStatusType) : null;
}

return null;
}

async queryVfnStatus(fullnodeAddress: String): Promise<string> {
async queryVfnStatus(fullnodeAddress: String): Promise<VfnStatusType> {
// Variable to store the status
let status: 'invalidAddress' | 'accessible' | 'notAccessible';
let status: VfnStatusType;

// Check the VFN address
const match = fullnodeAddress && fullnodeAddress.match(fullnodeRegex);
Expand All @@ -514,16 +515,16 @@ export class ValidatorsService {
// Check if the address is accessible
status = await checkAddressAccessibility(valIp, 6182)
.then((res) => {
return res ? 'accessible' : 'notAccessible';
return res ? VfnStatusType.Accessible : VfnStatusType.NotAccessible;
})
.catch(() => {
return 'notAccessible';
return VfnStatusType.NotAccessible;
});
} else {
status = 'invalidAddress';
status = VfnStatusType.InvalidAddress;
}

return status.toString();
return status;
}
}

Expand Down
8 changes: 7 additions & 1 deletion web-app/src/modules/interface/Validator.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ interface Vouches {
}[];
}

export enum VfnStatus {
InvalidAddress = 'invalidAddress',
Accessible = 'accessible',
NotAccessible = 'notAccessible',
}

export interface IValidator {
address: string;
family: string;
handle?: string;
inSet: boolean;
index: number;
votingPower: number;
vfnStatus: string;
vfnStatus: VfnStatus;
balance?: number;
unlocked?: number;
vouches: Vouches;
Expand Down

0 comments on commit 82be75e

Please sign in to comment.