-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathplutus-alwayssucceeds.hs
41 lines (32 loc) · 1.54 KB
/
plutus-alwayssucceeds.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Prelude
import System.Environment
import Cardano.Api
import Cardano.Api.Shelley
import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Plutus.V1.Ledger.Api as Plutus
import qualified Data.ByteString.Short as SBS
import Cardano.PlutusExample.AlwaysSucceeds (alwaysSucceedsScriptShortBs, alwaysSucceedsScript)
main :: IO ()
main = do
args <- getArgs
let nargs = length args
let scriptnum = if nargs > 0 then read (args!!0) else 42
let scriptname = if nargs > 1 then args!!1 else "result.plutus"
putStrLn $ "Writing output to: " ++ scriptname
writePlutusScript scriptnum scriptname alwaysSucceedsScript alwaysSucceedsScriptShortBs
writePlutusScript :: Integer -> FilePath -> PlutusScript PlutusScriptV1 -> SBS.ShortByteString -> IO ()
writePlutusScript scriptnum filename scriptSerial scriptSBS =
do
case Plutus.defaultCostModelParams of
Just m ->
let Alonzo.Data pData = toAlonzoData (ScriptDataNumber scriptnum)
(logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose m scriptSBS [pData]
in do print ("Log output" :: String) >> print logout
case e of
Left evalErr -> print ("Eval Error" :: String) >> print evalErr
Right exbudget -> print ("Ex Budget" :: String) >> print exbudget
Nothing -> error "defaultCostModelParams failed"
result <- writeFileTextEnvelope filename Nothing scriptSerial
case result of
Left err -> print $ displayError err
Right () -> return ()