Skip to content

Commit

Permalink
Koios/Ogmios - IndexOutofBound exception for PlutusV3 cost models (#474)
Browse files Browse the repository at this point in the history
* fix: #473 use index nos if length of default plutus ops is not same as fetched values size.

* Next snapshot version
  • Loading branch information
satran004 authored Dec 13, 2024
1 parent f5b6151 commit a00dd48
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,45 @@ private LinkedHashMap<String, LinkedHashMap<String, Long>> convertToCostModels(J
LinkedHashMap<String, Long> plutusV3CostModelsMap = new LinkedHashMap<>();
result.forEach((key, value) -> {
if (key.equals("PlutusV1")) {
value.forEach(aLong -> {
final int index = plutusV1IndexHolder.getAndIncrement();
plutusV1CostModelsMap.put(PlutusOps.getOperations(1).get(index), aLong);
});
if (value.size() == PlutusOps.getOperations(1).size()) {
value.forEach(aLong -> {
final int index = plutusV1IndexHolder.getAndIncrement();
plutusV1CostModelsMap.put(PlutusOps.getOperations(1).get(index), aLong);
});
} else {
value.forEach(aLong -> {
final int index = plutusV1IndexHolder.getAndIncrement();
plutusV1CostModelsMap.put(String.format("%03d", index), aLong);
});
}
res.put(key, plutusV1CostModelsMap);
} else if (key.equals("PlutusV2")) {
value.forEach(aLong -> {
final int index = plutusV2IndexHolder.getAndIncrement();
plutusV2CostModelsMap.put(PlutusOps.getOperations(2).get(index), aLong);
});
if (value.size() == PlutusOps.getOperations(2).size()) {
value.forEach(aLong -> {
final int index = plutusV2IndexHolder.getAndIncrement();
plutusV2CostModelsMap.put(PlutusOps.getOperations(2).get(index), aLong);
});
} else {
value.forEach(aLong -> {
final int index = plutusV2IndexHolder.getAndIncrement();
plutusV2CostModelsMap.put(String.format("%03d", index), aLong);
});
}

res.put(key, plutusV2CostModelsMap);
} else if (key.equals("PlutusV3")) {
value.forEach(aLong -> {
final int index = plutusV3IndexHolder.getAndIncrement();
plutusV3CostModelsMap.put(PlutusOps.getOperations(3).get(index), aLong);
});

if (value.size() == PlutusOps.getOperations(3).size()) {
value.forEach(aLong -> {
final int index = plutusV3IndexHolder.getAndIncrement();
plutusV3CostModelsMap.put(PlutusOps.getOperations(3).get(index), aLong);
});
} else {
value.forEach(aLong -> {
final int index = plutusV3IndexHolder.getAndIncrement();
plutusV3CostModelsMap.put(String.format("%03d", index), aLong);
});
}
res.put(key, plutusV3CostModelsMap);
}
});
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = com.bloxbean.cardano
artifactId = cardano-client-lib
version = 0.6.2
version = 0.6.2.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,42 @@ public ProtocolParams toProtocolParams() {
costModels.put("PlutusV1",
new LinkedHashMap<>() {{
List<String> plutusOps = PlutusOps.getOperations(1);
for (int i = 0; i < plutusCostModels.get("plutus:v1").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v1")[i]);
if (plutusOps.size() == plutusCostModels.get("plutus:v1").length) {
for (int i = 0; i < plutusCostModels.get("plutus:v1").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v1")[i]);
}
} else {
for (int i = 0; i < plutusCostModels.get("plutus:v1").length; i++) {
put(String.format("%03d", i), plutusCostModels.get("plutus:v1")[i]);
}
}
}}
);
costModels.put("PlutusV2",
new LinkedHashMap<>() {{
List<String> plutusOps = PlutusOps.getOperations(2);
for (int i = 0; i < plutusCostModels.get("plutus:v2").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v2")[i]);
if (plutusOps.size() == plutusCostModels.get("plutus:v2").length) {
for (int i = 0; i < plutusCostModels.get("plutus:v2").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v2")[i]);
}
} else {
for (int i = 0; i < plutusCostModels.get("plutus:v2").length; i++) {
put(String.format("%03d", i), plutusCostModels.get("plutus:v2")[i]);
}
}
}}
);
costModels.put("PlutusV3",
new LinkedHashMap<>() {{
List<String> plutusOps = PlutusOps.getOperations(3);
for (int i = 0; i < plutusCostModels.get("plutus:v3").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v3")[i]);
if (plutusOps.size() == plutusCostModels.get("plutus:v3").length) {
for (int i = 0; i < plutusCostModels.get("plutus:v3").length; i++) {
put(plutusOps.get(i), plutusCostModels.get("plutus:v3")[i]);
}
} else {
for (int i = 0; i < plutusCostModels.get("plutus:v3").length; i++) {
put(String.format("%03d", i), plutusCostModels.get("plutus:v3")[i]);
}
}
}}
);
Expand Down

0 comments on commit a00dd48

Please sign in to comment.