From 640ad0978dd089bff6a44d1dc1e733357c919cb4 Mon Sep 17 00:00:00 2001 From: onmax Date: Mon, 18 Nov 2024 23:45:48 -0600 Subject: [PATCH] chore: more fixes --- server/api/[version]/scores/index.get.ts | 3 +- server/api/[version]/validators/index.get.ts | 9 ++++++ server/utils/schemas.ts | 2 +- server/utils/validators.ts | 29 ++++++++++---------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/server/api/[version]/scores/index.get.ts b/server/api/[version]/scores/index.get.ts index 8a1d1a8..35338e0 100644 --- a/server/api/[version]/scores/index.get.ts +++ b/server/api/[version]/scores/index.get.ts @@ -49,7 +49,8 @@ export default defineEventHandler(async (event) => { availability: tables.scores.availability, total: tables.scores.total, dominance: tables.scores.dominance, - dominanceRatio: tables.activity.dominanceRatio, + dominanceRatioViaBalance: tables.activity.dominanceRatioViaBalance, + dominanceRatioViaSlots: tables.activity.dominanceRatioViaSlots, reliability: tables.scores.reliability, reason: tables.scores.reason, }) diff --git a/server/api/[version]/validators/index.get.ts b/server/api/[version]/validators/index.get.ts index 6768010..00f16b3 100644 --- a/server/api/[version]/validators/index.get.ts +++ b/server/api/[version]/validators/index.get.ts @@ -2,6 +2,8 @@ import type { Validator } from 'nimiq-rpc-client-ts' import { getRpcClient } from '~~/server/lib/client' import { mainQuerySchema } from '~~/server/utils/schemas' import { fetchValidators } from '~~/server/utils/validators' +import { consola } from 'consola' +import { getRange } from 'nimiq-validators-trustscore' export default defineCachedEventHandler(async (event) => { const params = await getValidatedQuery(event, mainQuerySchema.parse) @@ -16,6 +18,13 @@ export default defineCachedEventHandler(async (event) => { addresses = activeValidators.map(v => v.address) } + const range = await getRange(getRpcClient()) + if (!(await checkIfScoreExistsInDb(range))) { + const { data, error } = await calculateScores(range) + if (!data || error) + consola.warn(`Error calculating scores for range ${range}`, error) + } + const { data: validators, error: errorValidators } = await fetchValidators({ ...params, addresses }) if (errorValidators || !validators) throw createError(errorValidators) diff --git a/server/utils/schemas.ts b/server/utils/schemas.ts index c336758..033dc2c 100644 --- a/server/utils/schemas.ts +++ b/server/utils/schemas.ts @@ -15,7 +15,7 @@ export const rangeQuerySchema = z.object({ export const validatorSchema = z.object({ name: z.string().optional(), address: z.string().regex(/^NQ\d{2}(\s\w{4}){8}$/, 'Invalid Nimiq address format'), - fee: z.literal(-1).or(z.number().min(0).max(1)).default(-1), + fee: z.literal(null).or(z.number().min(0).max(1)).default(null), payoutType: z.nativeEnum(PayoutType).default(PayoutType.None), payoutSchedule: z.string().optional().default(''), isMaintainedByNimiq: z.boolean().optional(), diff --git a/server/utils/validators.ts b/server/utils/validators.ts index b4359a0..a4f215d 100644 --- a/server/utils/validators.ts +++ b/server/utils/validators.ts @@ -166,12 +166,12 @@ export async function fetchValidators(params: FetchValidatorsOptions): Result` // CASE // WHEN ${tables.scores.total} IS NOT NULL THEN json_object( @@ -189,14 +189,15 @@ export async function fetchValidators(params: FetchValidatorsOptions): Result