Skip to content

Commit

Permalink
chore: fix mapping cost models for old epochs
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Feb 15, 2024
1 parent c99e310 commit 81461a7
Show file tree
Hide file tree
Showing 4 changed files with 1,085 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- port configuration via config option `dbSync.port`
- error in `/epochs/n/parameters` for epochs without PlutusV1/PlutusV2 cost models

## [1.7.0] - 2023-08-30

Expand Down
10 changes: 6 additions & 4 deletions src/utils/cost-models-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,17 @@ const plutusV2Names: Array<string> = [

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const costModelsMap = (costModels: any) => {
if (costModels === null || typeof costModels !== 'object') return null;

costModels = sortKeysInObject(costModels);

if (Object.keys(costModels.PlutusV1).length !== plutusV1Names.length)
if ('PlutusV1' in costModels && Object.keys(costModels.PlutusV1).length !== plutusV1Names.length)
throw new Error('The size of the Plutus V1 cost model mismatched');

if (Object.keys(costModels.PlutusV2).length !== plutusV2Names.length)
if ('PlutusV2' in costModels && Object.keys(costModels.PlutusV2).length !== plutusV2Names.length)
throw new Error('The size of the Plutus V1 cost model mismatched');

if (validation.isNumber(Object.keys(costModels.PlutusV1)[0])) {
if ('PlutusV1' in costModels && validation.isNumber(Object.keys(costModels.PlutusV1)[0])) {
const PlutusV1: Record<string, number> = {};

for (let index = 0; index < plutusV1Names.length; index++)
Expand All @@ -372,7 +374,7 @@ export const costModelsMap = (costModels: any) => {
costModels = { ...costModels, PlutusV1 };
}

if (validation.isNumber(Object.keys(costModels.PlutusV2)[0])) {
if ('PlutusV2' in costModels && validation.isNumber(Object.keys(costModels.PlutusV2)[0])) {
const PlutusV2: Record<string, number> = {};

for (let index = 0; index < plutusV2Names.length; index++)
Expand Down
Loading

0 comments on commit 81461a7

Please sign in to comment.