-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4776 from IntersectMBO/ldan/plutus-debug-cli
Create CLI for `plutus-debug`
- Loading branch information
Showing
8 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module CLI ( | ||
Opts (..), | ||
optsParser, | ||
) where | ||
|
||
import Cardano.Ledger.Binary (mkVersion64) | ||
import Cardano.Ledger.Plutus.Evaluate | ||
import Options.Applicative | ||
|
||
data Opts = Opts | ||
{ optsScriptWithContext :: !String | ||
, optsOverrides :: !PlutusDebugOverrides | ||
} | ||
deriving (Show) | ||
|
||
overridesParser :: Parser PlutusDebugOverrides | ||
overridesParser = | ||
PlutusDebugOverrides | ||
<$> option | ||
(Just <$> str) | ||
( long "script" | ||
<> value Nothing | ||
<> help "Plutus script hex without context" | ||
) | ||
<*> option | ||
(mkVersion64 <$> auto) | ||
( long "protocol-version" | ||
<> short 'v' | ||
<> value Nothing | ||
<> help "Major protocol version" | ||
) | ||
<*> option | ||
(Just <$> auto) | ||
( long "language" | ||
<> value Nothing | ||
<> help "Plutus language version" | ||
) | ||
<*> option | ||
(str >>= pure . Just . map read . words) | ||
( long "cost-model-values" | ||
<> value Nothing | ||
<> help "" | ||
) | ||
<*> option | ||
(Just <$> auto) | ||
( long "execution-units-memory" | ||
<> value Nothing | ||
<> help "" | ||
) | ||
<*> option | ||
(Just <$> auto) | ||
( long "execution-units-steps" | ||
<> value Nothing | ||
<> help "" | ||
) | ||
|
||
optsParser :: Parser Opts | ||
optsParser = | ||
Opts | ||
<$> strArgument | ||
(metavar "SCRIPT_WITH_CONTEXT(BASE64)") | ||
<*> overridesParser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main where | ||
|
||
import CLI | ||
import Cardano.Ledger.Crypto (StandardCrypto) | ||
import Cardano.Ledger.Plutus.Evaluate (debugPlutus) | ||
import Control.Monad ((<=<)) | ||
import System.Environment (getArgs) | ||
import Cardano.Ledger.Plutus.Evaluate | ||
import Options.Applicative | ||
|
||
main :: IO () | ||
main = mapM_ (print <=< debugPlutus @StandardCrypto) =<< getArgs | ||
main = do | ||
Opts {..} <- | ||
execParser $ | ||
info | ||
(optsParser <* abortOption (ShowHelpText Nothing) (long "help")) | ||
( header "plutus-debug - A Plutus script debugger" | ||
<> progDesc | ||
( "The purpose of this tool is to troubleshoot failing Plutus scripts. " | ||
<> "When you encounter a `PlutusFailure`, you can pass the `Base64-encoded script bytes` " | ||
<> "to `plutus-debug` for debugging purposes and override the context of the failed script " | ||
<> "and the script itself with the available command line options." | ||
) | ||
<> footer | ||
( "EXAMPLE: plutus-debug \"hgmCAVksj...\" --script \"5906ab010...\" " | ||
<> "Note when rewriting the script with the `--script` option " | ||
<> "you will have to provide the hex of the Plutus script as seen in " | ||
<> "`Test.Cardano.Ledger.Plutus.Examples`." | ||
) | ||
) | ||
debugPlutus @StandardCrypto optsScriptWithContext optsOverrides >>= print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters