Skip to content

Commit

Permalink
Merge pull request #20 from bloxbean/costmdl_hash
Browse files Browse the repository at this point in the history
feat: Added costmodel hash to ProtocolParamUpdate
  • Loading branch information
satran004 committed Aug 25, 2023
2 parents cd0564b + 9afa737 commit 0389d7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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

0 comments on commit 0389d7a

Please sign in to comment.