Skip to content

Commit

Permalink
Use traceFile (bad)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa McHale committed Apr 17, 2019
1 parent 82a1649 commit 5789eb0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .hlint.yaml
@@ -1,6 +1,6 @@
---
- functions:
- {name: unsafePerformIO, within: [PlutusPrelude, Language.PlutusCore.Generators.Internal.Entity, Language.PlutusCore.Constant.Dynamic.Call, Language.PlutusCore.Constant.Dynamic.Emit, Language.PlutusCore.Constant.Dynamic.Instances, Language.PlutusCore.StdLib.Type, Language.PlutusTx.Plugin, Language.PlutusTx.Evaluation]}
- {name: unsafePerformIO, within: [PlutusPrelude, Language.PlutusCore.Generators.Internal.Entity, Language.PlutusCore.Constant.Dynamic.Call, Language.PlutusCore.Constant.Dynamic.Emit, Language.PlutusCore.Constant.Dynamic.Instances, Language.PlutusCore.StdLib.Type, Language.PlutusTx.Plugin, Language.PlutusTx.Evaluation, Debug.Trace.Ext]}
- {name: error, within: [Main, PlutusPrelude, Language.PlutusCore.StdLib.Meta, Evaluation.Constant.Success, Language.PlutusCore.Constant.Apply, Language.PlutusCore.Evaluation.CkMachine, Language.PlutusCore.TypeSynthesis, Language.PlutusCore.Generators.Internal.Dependent, Language.PlutusCore.Generators.Internal.Entity, Language.PlutusCore.Generators.Internal.Utils, Language.PlutusCore.Constant.Make, DynamicBuiltins.Definition, Language.PlutusCore.TH, Language.PlutusTx.Utils, Language.PlutusIR.Compiler.Datatype, LedgerBytes]}
- {name: undefined, within: [Language.PlutusCore.Constant.Apply, Language.PlutusTx.Lift.Class, Language.PlutusTx.Lift.Instances]}
- {name: fromJust, within: [Language.PlutusTx.Lift]}
Expand Down
7 changes: 7 additions & 0 deletions wallet-api/src/Debug/Trace/Ext.hs
@@ -0,0 +1,7 @@
module Debug.Trace.Ext ( traceFile ) where

import Data.Functor (($>))
import System.IO.Unsafe (unsafePerformIO)

traceFile :: FilePath -> String -> a -> a
traceFile fp contents x = unsafePerformIO $ writeFile fp contents $> x
3 changes: 2 additions & 1 deletion wallet-api/src/Ledger/Scripts.hs
Expand Up @@ -48,6 +48,7 @@ import Language.PlutusTx.Lift (unsafeLiftProgram)
import Language.PlutusTx.Lift.Class (Lift)
import Language.PlutusTx (CompiledCode, compile, getPlc)
import PlutusPrelude
import Debug.Trace.Ext

-- | A script on the chain. This is an opaque type as far as the chain is concerned.
newtype Script = Script { unScript :: PLC.Program PLC.TyName PLC.Name () }
Expand Down Expand Up @@ -100,7 +101,7 @@ applyScript (unScript -> s1) (unScript -> s2) = Script $ s1 `PLC.applyProgram` s
evaluateScript :: Script -> ([String], Bool)
evaluateScript (unScript -> s) =
case check s of
(Left e) -> ([logTypeErr e], False)
(Left e) -> traceFile "invalid.plc" (PLC.prettyPlcDefString s) ([logTypeErr e], False)
Right{} -> (isJust . reoption) <$> evaluateCekTrace s

where check = PLC.runQuoteT . PLC.typecheckPipeline PLC.defOnChainConfig
Expand Down
2 changes: 2 additions & 0 deletions wallet-api/wallet-api.cabal
Expand Up @@ -72,6 +72,8 @@ library
Ledger.Value
Ledger.Value.TH
LedgerBytes
other-modules:
Debug.Trace.Ext
hs-source-dirs: src
default-language: Haskell2010
build-depends:
Expand Down

0 comments on commit 5789eb0

Please sign in to comment.