Skip to content

Commit

Permalink
refactor getEarliestStart* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Dec 5, 2023
1 parent a2c3b33 commit d63f1f1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/engine/paima-runtime/src/cde-config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d63f1f1

Please sign in to comment.