2525 */
2626@ Slf4j
2727public class TxEvaluator {
28- private final SlotConfig slotConfig ;
28+
29+ private final SlotConfig .SlotConfigByReference slotConfig ;
30+ private final InitialBudgetConfig .InitialBudgetByReference initialBudgetConfig ;
2931
3032 public TxEvaluator () {
3133 this .slotConfig = getDefaultSlotConfig ();
34+ this .initialBudgetConfig = getDefaultInitialBudgetConfig ();
3235 }
3336
34- public TxEvaluator (SlotConfig slotConfig ) {
37+ public TxEvaluator (SlotConfig slotConfig , InitialBudgetConfig initialBudgetConfig ) {
3538 this .slotConfig = new SlotConfig .SlotConfigByReference ();
3639 this .slotConfig .zero_slot = slotConfig .zero_slot ;
3740 this .slotConfig .zero_time = slotConfig .zero_time ;
3841 this .slotConfig .slot_length = slotConfig .slot_length ;
42+
43+ this .initialBudgetConfig = new InitialBudgetConfig .InitialBudgetByReference ();
44+ this .initialBudgetConfig .mem = initialBudgetConfig .mem ;
45+ this .initialBudgetConfig .cpu = initialBudgetConfig .cpu ;
3946 }
4047
4148 /**
@@ -74,18 +81,25 @@ public List<Redeemer> evaluateTx(Transaction transaction, Set<Utxo> inputUtxos,
7481 }
7582 });
7683
77- SlotConfig .SlotConfigByReference slotConfig = getDefaultSlotConfig ();
7884 try {
7985 String costMdlsHex = HexUtil .encodeHexString (CborSerializationUtil .serialize (costMdls .serialize ()));
80- String response = CardanoJNAUtil .eval_phase_two_raw (transaction .serializeToHex (),
81- HexUtil .encodeHexString (CborSerializationUtil .serialize (inputArray )),
82- HexUtil .encodeHexString (CborSerializationUtil .serialize (outputArray )),
83- costMdlsHex , slotConfig );
86+ String trxCbor = transaction .serializeToHex ();
87+ String inputsCbor = HexUtil .encodeHexString (CborSerializationUtil .serialize (inputArray ));
88+ String outputsCbor = HexUtil .encodeHexString (CborSerializationUtil .serialize (outputArray ));
89+
90+ String response = CardanoJNAUtil .eval_phase_two_raw (
91+ trxCbor ,
92+ inputsCbor ,
93+ outputsCbor ,
94+ costMdlsHex ,
95+ initialBudgetConfig ,
96+ slotConfig
97+ );
8498
8599 if (log .isTraceEnabled ()) {
86- log .trace ("Transaction: " + transaction . serializeToHex () );
87- log .trace ("Inputs : " + HexUtil . encodeHexString ( CborSerializationUtil . serialize ( inputArray )) );
88- log .trace ("Outputs : " + HexUtil . encodeHexString ( CborSerializationUtil . serialize ( outputArray )) );
100+ log .trace ("Transaction: " + trxCbor );
101+ log .trace ("Inputs : " + inputsCbor );
102+ log .trace ("Outputs : " + outputsCbor );
89103 log .trace ("CostMdlsHex : " + costMdlsHex );
90104 }
91105
@@ -118,25 +132,35 @@ private List<Redeemer> deserializeRedeemerArray(String response) {
118132 }
119133 }
120134
121- private SlotConfig .SlotConfigByReference getDefaultSlotConfig () {
135+ private static SlotConfig .SlotConfigByReference getDefaultSlotConfig () {
122136 SlotConfig .SlotConfigByReference slotConfig = new SlotConfig .SlotConfigByReference ();
123137 slotConfig .zero_time = 1660003200000L ;
124138 slotConfig .zero_slot = 0 ;
125139 slotConfig .slot_length = 1000 ;
140+
126141 return slotConfig ;
127142 }
128143
144+ private static InitialBudgetConfig .InitialBudgetByReference getDefaultInitialBudgetConfig () {
145+ InitialBudgetConfig .InitialBudgetByReference initialBudgetConfig = new InitialBudgetConfig .InitialBudgetByReference ();
146+ initialBudgetConfig .mem = 1660003200000L ;
147+ initialBudgetConfig .cpu = 0 ;
148+
149+ return initialBudgetConfig ;
150+ }
151+
129152 private List <TransactionOutput > resolveTxInputs (List <TransactionInput > transactionInputs , Set <Utxo > utxos , List <PlutusScript > plutusScripts ) {
130153 return transactionInputs .stream ().map (input -> {
131154 try {
132-
133- Utxo utxo = utxos .stream ().filter (_utxo -> input .getTransactionId ().equals (_utxo .getTxHash ()) && input .getIndex () == _utxo .getOutputIndex ())
155+ Utxo utxo = utxos .stream ()
156+ .filter (_utxo -> input .getTransactionId ().equals (_utxo .getTxHash ()))
157+ .filter (_utxo -> input .getIndex () == _utxo .getOutputIndex ())
134158 .findFirst ()
135159 .orElseThrow ();
136160
137161 String address = utxo .getAddress ();
138162
139- //Calculate script ref
163+ // Calculate script ref
140164 PlutusScript plutusScript = plutusScripts .stream ().filter (script -> {
141165 try {
142166 return HexUtil .encodeHexString (script .getScriptHash ()).equals (utxo .getReferenceScriptHash ());
@@ -148,7 +172,6 @@ private List<TransactionOutput> resolveTxInputs(List<TransactionInput> transacti
148172 PlutusData inlineDatum = utxo .getInlineDatum () != null ? PlutusData .deserialize (HexUtil .decodeHexString (utxo .getInlineDatum ())) : null ;
149173 byte [] datumHash = utxo .getDataHash () != null ? HexUtil .decodeHexString (utxo .getDataHash ()) : null ;
150174
151-
152175 return TransactionOutput .builder ()
153176 .address (address )
154177 .value (utxo .toValue ())
0 commit comments