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

use TH-generated plutus scripts #5048

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
plutus-scripts-bench: Hide suffixes & Either from users.
  • Loading branch information
NadiaYvette committed Apr 7, 2023
commit 2c9d74e560b3c7550af84b658e3a1a9d0cf136fc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusS

scriptName :: Haskell.String
scriptName
= $(LitE . StringL . loc_module <$> qLocation)
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)


instance Plutus.Eq CustomCallData where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Prelude as Haskell (String, (.), (<$>))

scriptName :: Haskell.String
scriptName
= $(LitE . StringL . loc_module <$> qLocation)
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)

script :: PlutusBenchScript
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV2 scriptSerialized))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import PlutusTx.Prelude hiding (Semigroup (..), unless, (.), (<$>))

scriptName :: String
scriptName
= $(LitE . StringL . loc_module <$> qLocation)
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)

script :: PlutusBenchScript
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV1 scriptSerialized))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Prelude as Haskell (String, (.), (<$>))

scriptName :: Haskell.String
scriptName
= $(LitE . StringL . loc_module <$> qLocation)
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)

script :: PlutusBenchScript
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV2 scriptSerialized))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module Cardano.Benchmarking.ScriptAPI
, psName
, psScript
, mkPlutusBenchScript
, prepareScriptName
) where

import Prelude as Haskell (String)
import Prelude as Haskell (String, dropWhile, head, last, map, reverse, (.), (==))
import Data.Text (pack, split, unpack)
import Cardano.Api (ScriptInAnyLang)

data PlutusBenchScript
Expand All @@ -18,3 +20,14 @@ data PlutusBenchScript

mkPlutusBenchScript :: String -> ScriptInAnyLang -> PlutusBenchScript
mkPlutusBenchScript = PlutusBenchScript

prepareScriptName :: String -> String
prepareScriptName
= head
. dropWhile (=="hs")
. map unpack
. reverse
. split (=='.')
. last
. split (=='/')
. pack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 changes: 4 additions & 7 deletions nix/nixos/tx-generator-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ let
## Basically do something like:
## script = "${pkgs.plutus-scripts}/generated-plutus-scripts/${cfg.plutus.script}";
## except for having to weave the Either through things
script = if (cfg.plutus.script?Left)
## The internal ID doesn't need path qualification.
then { Left = cfg.plutus.script.Left; }
else { Right = pkgs.plutus-scripts
+ "/generated-plutus-scripts/"
+ cfg.plutus.script.Right; };
## To refer to a plutus script file, do something like:
## { Right = pkgs.plutus-scripts + "/generated-plutus-scripts/" + cfg.plutus.script; }
script = { Left = cfg.plutus.script; };
redeemer = pkgs.writeText "plutus-redeemer.json" (__toJSON cfg.plutus.redeemer);
datum = if cfg.plutus.datum == null then null else
pkgs.writeText "plutus-datum.json" (__toJSON cfg.plutus.datum);
Expand Down Expand Up @@ -74,7 +71,7 @@ in pkgs.commonLib.defServiceModule
##
plutus = {
type = mayOpt str "Plutus script type.";
script = mayOpt attrs "Name of the Plutus script from plutus-apps, prefixed with either of v1/v2.";
script = mayOpt str "Name of the Plutus script from plutus-apps, prefixed with either of v1/v2.";
limitExecutionMem = mayOpt int "Limit for saturation tuning: mem; null means per-Tx limit from ProtocolParameters.";
limitExecutionSteps = mayOpt int "Limit for saturation tuning: steps; null means per-Tx limit from ProtocolParameters.";
datum = mayOpt attrs "Plutus script datum.";
Expand Down
6 changes: 3 additions & 3 deletions nix/workbench/profile/prof1-variants.jq
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def all_profile_variants:
({ generator:
{ plutus:
{ type: "LimitSaturationLoop"
, script: { "Left": "Loop.hs" }
, script: "Loop"
, redeemer:
{ "int": 1000000 }
}
Expand All @@ -288,7 +288,7 @@ def all_profile_variants:
({ generator:
{ plutus:
{ type: "LimitTxPerBlock_8"
, script: { "Left": "EcdsaSecp256k1Loop.hs" }
, script: "EcdsaSecp256k1Loop"
, redeemer:
{ constructor: 0
, fields:
Expand All @@ -311,7 +311,7 @@ def all_profile_variants:
({ generator:
{ plutus:
{ type: "LimitTxPerBlock_8"
, script: { "Left": "SchnorrSecp256k1Loop.hs" }
, script: "SchnorrSecp256k1Loop"
, redeemer:
{ constructor: 0
, fields:
Expand Down