Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mapping cost models for old epochs (/epochs/:num/parameters) #141

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading