From d63f1f1d2ba775b110ec4f8eb07746e5aa7932a9 Mon Sep 17 00:00:00 2001 From: Enzo Cioppettini Date: Tue, 5 Dec 2023 13:59:54 -0300 Subject: [PATCH] refactor getEarliestStart* functions --- .../paima-runtime/src/cde-config/utils.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/engine/paima-runtime/src/cde-config/utils.ts b/packages/engine/paima-runtime/src/cde-config/utils.ts index ddf5dcf83..00d9d92c7 100644 --- a/packages/engine/paima-runtime/src/cde-config/utils.ts +++ b/packages/engine/paima-runtime/src/cde-config/utils.ts @@ -5,24 +5,22 @@ import { ChainDataExtensionType, doLog } from '@paima/utils'; import type { ChainDataExtension } from '@paima/sm'; export function getEarliestStartBlockheight(config: ChainDataExtension[]): number { - const startBlockheights = config.reduce((arr, cde) => { + const minStartBlockheight = config.reduce((min, cde) => { if (cde.cdeType !== ChainDataExtensionType.CardanoPool) { - arr.push(cde.startBlockHeight); + return Math.min(min, cde.startBlockHeight); } - return arr; - }, [] as number[]); - const minStartBlockheight = Math.min(...startBlockheights); + return min; + }, 0); return isFinite(minStartBlockheight) ? minStartBlockheight : -1; } export function getEarliestStartSlot(config: ChainDataExtension[]): number { - const startSlots = config.reduce((arr, cde) => { + const minStartSlot = config.reduce((min, cde) => { if (cde.cdeType === ChainDataExtensionType.CardanoPool) { - arr.push(cde.startSlot); + return Math.min(min, cde.startSlot); } - return arr; - }, [] as number[]); - const minStartSlot = Math.min(...startSlots); + return min; + }, 0); return isFinite(minStartSlot) ? minStartSlot : -1; }