Created
November 4, 2024 04:59
-
-
Save ahaxu/47de1d8d8b0d1fa91a93456f6dd37844 to your computer and use it in GitHub Desktop.
Always true validtor in haskell
This file contains hidden or 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
{-# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment