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

feat: Added costmodel hash to ProtocolParamUpdate #20

Merged
merged 1 commit into from
Aug 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ProtocolParamUpdate {

//Alonzo changes
private Map<Integer, String> costModels; //18
private String costModelsHash; //derived field

//ex_unit_prices
private BigDecimal priceMem; //19
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bloxbean.cardano.yaci.core.model.serializers;

import co.nstant.in.cbor.model.*;
import com.bloxbean.cardano.client.crypto.Blake2bUtil;
import com.bloxbean.cardano.client.util.Tuple;
import com.bloxbean.cardano.yaci.core.model.ProtocolParamUpdate;
import com.bloxbean.cardano.yaci.core.model.Update;
Expand Down Expand Up @@ -122,6 +123,7 @@ public ProtocolParamUpdate getProtocolParams(Map genesisProtocolParamsMap) {

//CostModels
java.util.Map<Integer, String> costModelMap = null;
String costModelsHash = null;
itemDI = genesisProtocolParamsMap.get(new UnsignedInteger(18));
if (itemDI != null) {
costModelMap = new LinkedHashMap<>();
Expand All @@ -131,6 +133,9 @@ public ProtocolParamUpdate getProtocolParams(Map genesisProtocolParamsMap) {
String costModel = HexUtil.encodeHexString(CborSerializationUtil.serialize(itemDIMap.get(key)));
costModelMap.put(version, costModel);
}

var cbor = CborSerializationUtil.serialize(itemDI);
costModelsHash = HexUtil.encodeHexString(Blake2bUtil.blake2bHash256(cbor));
}

//exUnits prices
Expand Down Expand Up @@ -196,6 +201,7 @@ public ProtocolParamUpdate getProtocolParams(Map genesisProtocolParamsMap) {
.minPoolCost(minPoolCost)
.adaPerUtxoByte(adaPerUtxoBytes)
.costModels(costModelMap)
.costModelsHash(costModelsHash)
.priceMem(priceMem)
.priceStep(priceSteps)
.maxTxExMem(maxTxExMem)
Expand Down
Loading