content: {-# LANGUAGE DataKinds           #-}
  {-# LANGUAGE ImportQualifiedPost #-}
  {-# LANGUAGE NoImplicitPrelude   #-}
  {-# LANGUAGE OverloadedStrings   #-}
  {-# LANGUAGE TemplateHaskell     #-}
  
  module FortyTwo where
  
  import qualified Plutus.V2.Ledger.Api as PlutusV2
  import           PlutusTx             (BuiltinData, compile)
  import           PlutusTx.Builtins    as Builtins (mkI)
  import           PlutusTx.Prelude     (otherwise, traceError, (==))
  import           Prelude              (IO)
  import           Utilities            (writeValidatorToFile)
  
  ---------------------------------------------------------------------------------------------------
  ----------------------------------- ON-CHAIN / VALIDATOR ------------------------------------------
  
  -- This validator succeeds only if the redeemer is 42
  --                  Datum         Redeemer     ScriptContext
  mk42Validator :: BuiltinData -> BuiltinData -> BuiltinData -> ()
  mk42Validator _ r _
      | r == Builtins.mkI 42 = ()
      | otherwise            = traceError "expected 42"
  {-# INLINABLE mk42Validator #-}
  
  validator :: PlutusV2.Validator
  validator = PlutusV2.mkValidatorScript $$(PlutusTx.compile [|| mk42Validator ||])
  
  ---------------------------------------------------------------------------------------------------
  ------------------------------------- HELPER FUNCTIONS --------------------------------------------
  
  saveVal :: IO ()
  saveVal = writeValidatorToFile "./assets/fortytwo.plutus" validator
  