Skip to content

Commit ffb88f3

Browse files
committed
chore: Conway era script data hash changes
1 parent aa07e29 commit ffb88f3

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

function/src/main/java/com/bloxbean/cardano/client/function/helper/ScriptDataHashCalculator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ public static void calculateScriptDataHash(TxBuilderContext ctx, Transaction tra
6060
costMdls.add(costModel.orElse(PlutusV3CostModel));
6161
}
6262

63-
if (costMdls.isEmpty()) { //Check if costmodel can be decided from other fields //TODO Impl : Check what to do for v3 reference scripts
64-
if (transaction.getBody().getReferenceInputs() != null
65-
&& transaction.getBody().getReferenceInputs().size() > 0) { //If reference input is there, then plutus v2
66-
var refInputLanguage = ctx.getReferenceInputLanguage();
67-
Optional<CostModel> costModel = CostModelUtil.getCostModelFromProtocolParams(ctx.getProtocolParams(), refInputLanguage);
68-
costMdls.add(costModel.orElse(PlutusV2CostModel));
63+
if (transaction.getBody().getReferenceInputs() != null
64+
&& transaction.getBody().getReferenceInputs().size() > 0) { //If reference input is there, the check the language from that
65+
if (!ctx.getRefScriptLanguages().isEmpty()) {
66+
for (Language language : ctx.getRefScriptLanguages()) {
67+
Optional<CostModel> costModel =
68+
CostModelUtil.getCostModelFromProtocolParams(ctx.getProtocolParams(), language);
69+
costMdls.add(costModel.orElseThrow(() -> new IllegalArgumentException("Cost model not found for language : " + language)));
70+
}
6971
}
7072
}
7173
}

plutus/src/main/java/com/bloxbean/cardano/client/plutus/util/ScriptDataHashGenerator.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@ public static byte[] generate(List<Redeemer> redeemers, List<PlutusData> datums,
6464

6565
encodedBytes = Bytes.concat(redeemerBytes, plutusDataBytes, langViewsBytes);
6666
} else {
67-
/**
68-
; Finally, note that in the case that a transaction includes datums but does not
69-
; include any redeemers, the script data format becomes (in hex):
70-
; [ 80 | datums | A0 ]
71-
; corresponding to a CBOR empty list and an empty map.
72-
**/
73-
encodedBytes = Bytes.concat(HexUtil.decodeHexString("0x80"), plutusDataBytes, HexUtil.decodeHexString("0xA0"));
67+
if (EraSerializationConfig.INSTANCE.useConwayEraFormat()) {
68+
encodedBytes = Bytes.concat(HexUtil.decodeHexString("0xA0"), plutusDataBytes, langViewsBytes);
69+
} else { //Pre conway era
70+
/**
71+
; Finally, note that in the case that a transaction includes datums but does not
72+
; include any redeemers, the script data format becomes (in hex):
73+
; [ 80 | datums | A0 ]
74+
; corresponding to a CBOR empty list and an empty map.
75+
**/
76+
encodedBytes = Bytes.concat(HexUtil.decodeHexString("0x80"), plutusDataBytes, HexUtil.decodeHexString("0xA0"));
77+
}
7478
}
7579

7680
return Blake2bUtil.blake2bHash256(encodedBytes);

0 commit comments

Comments
 (0)