Skip to content

Commit

Permalink
refactor: remove warnings, unused imports etc
Browse files Browse the repository at this point in the history
  • Loading branch information
nau committed Dec 31, 2024
1 parent 6c3e14c commit 09f8549
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class TxEvaluator(
val r =
try
val resultTerm = vm.evaluateScript(applied, spender, logger)
CekResult(resultTerm, spender.getSpentBudget, logger.getLogs)
Result.Success(resultTerm, spender.getSpentBudget, Map.empty, logger.getLogs.toSeq)
catch
case e: Exception =>
throw new TxEvaluationException(e.getMessage, e, logger.getLogs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package scalus.examples;

import scalus.builtin.Data;
import scalus.builtin.JVMPlatformSpecific$;
import scalus.ledger.api.PlutusLedgerLanguage;
import scalus.uplc.eval.CekResult;
import scalus.uplc.eval.MachineParams;
import scalus.uplc.eval.StackTraceMachineError;
import scalus.uplc.eval.VM;
import scalus.uplc.DeBruijnedProgram;
import scalus.uplc.Constant;
import scalus.uplc.Term;
import scalus.uplc.eval.*;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;

class CekMachineExample {
class PlutusVMExample {
public static void evaluationExample1() throws Exception {
// Read Plutus script from a file
var script = Files.readAllBytes(Paths.get("bench/src/main/resources/data/auction_1-1.flat"));
var flatScript = Files.readAllBytes(Paths.get("bench/src/main/resources/data/auction_1-1.flat"));
var script = DeBruijnedProgram.fromFlatEncoded(flatScript);
// Evaluate the script
var machineParams = MachineParams.defaultParams();
var machineParams = MachineParams.defaultPlutusV2PostConwayParams();
var plutusVM = PlutusVM.makePlutusV2VM(machineParams, JVMPlatformSpecific$.MODULE$);
try {
var result = VM.evaluateScriptCounting(machineParams, script);
var result = plutusVM.evaluateScript(script, NoBudgetSpender$.MODULE$, NoLogger$.MODULE$);
System.out.println(result);
} catch (StackTraceMachineError e) {
String stacktrace = Arrays.stream(e.getCekStack()).map(Object::toString).reduce("", (a, b) -> a + "\n" + b);
Expand All @@ -27,6 +30,8 @@ public static void evaluationExample1() throws Exception {
return null;
});
System.out.println(stacktrace);
} catch (Exception e) {
e.printStackTrace();
}
}

Expand All @@ -36,10 +41,14 @@ public static void evaluationExample2() throws Exception {
var pparams = Files.readString(Paths.get("jvm/src/main/resources/protocol-params.json"));
var machineParams = MachineParams.fromCardanoCliProtocolParamsJson(pparams, PlutusLedgerLanguage.PlutusV2);
// Read Plutus script from a file
var script = Files.readAllBytes(Paths.get("bench/src/main/resources/data/auction_1-1.flat"));
var arg = Data.I.apply(scala.math.BigInt.apply(123));
var flatScript = Files.readAllBytes(Paths.get("bench/src/main/resources/data/auction_1-1.flat"));
var script = DeBruijnedProgram.fromFlatEncoded(flatScript);
var arg = Term.Const.apply(Constant.Data.apply(Data.I.apply(scala.math.BigInt.apply(123))));
var appliedScript = script.applyArg(arg);

// Evaluate the script
var result = VM.evaluateScriptCounting(machineParams, script, arg);
var plutusVM = PlutusVM.makePlutusV2VM(machineParams, JVMPlatformSpecific$.MODULE$);
var result = plutusVM.evaluateScriptDebug(appliedScript);
System.out.println(result);
}

Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scalus/builtin/ByteString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ByteString private (val bytes: Array[Byte]) {

object ByteString {
val empty = new ByteString(Array.empty)
def fromArray(bytes: Array[Byte]): ByteString = new ByteString(bytes.toArray)
def fromArray(bytes: Array[Byte]): ByteString = new ByteString(bytes)

def apply(bytes: Byte*): ByteString = new ByteString(bytes.toArray)

Expand All @@ -58,7 +58,7 @@ object ByteString {
* }}}
*/
def hex(args: Any*): ByteString =
val hexString = sc.s(args: _*).replace(" ", "")
val hexString = sc.s(args*).replace(" ", "")
fromHex(hexString)
}

Expand Down
6 changes: 3 additions & 3 deletions shared/src/main/scala/scalus/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ package object scalus {
spenderLogger.costs.toMap,
spenderLogger.getLogsWithBudget
)
def plutusV1: Program = Program((1, 0, 0), self)
def plutusV2: Program = Program((1, 0, 0), self)
def plutusV3: Program = Program((1, 1, 0), self)
def plutusV1: Program = Program.plutusV1(self)
def plutusV2: Program = Program.plutusV2(self)
def plutusV3: Program = Program.plutusV3(self)
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scalus/uplc/eval/Cek.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import scala.collection.immutable
import scala.collection.immutable.ArraySeq
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.Buffer
import scala.collection.mutable.HashMap
import scala.util.Try
import scala.util.control.NonFatal
Expand Down Expand Up @@ -559,6 +558,7 @@ enum Result:
| costs:\n${showCosts}
| logs: ${logs.mkString("\n")}""".stripMargin

@deprecated("Use Result instead", "0.8.4")
class CekResult(t: Term, val budget: ExBudget, val logs: Array[String]) {
lazy val term = DeBruijn.fromDeBruijnTerm(t)
override def toString: String = s"CekResult($term, $budget, ${logs.mkString(", ")})"
Expand Down

0 comments on commit 09f8549

Please sign in to comment.