#
Validation Scripts
#
Homework
Lecture 2, Part 5
Two modules are provided: Homework01.hs and Homework02.hs.
#
Homework 1
The redeemer has been changed to a pair of Bools. Validation should only
succeed if they match.
Before fixing it, the validator in the homework code always passes.
mkValidator _ _ _ = True -- FIX ME!
The correct validator can be written like so:
mkValidator _ (x, y) _ = traceIfFalse "Redeemer booleans do not match" $ x == y
Additionally, the homework code had a broken type instance and broken
validator, valHash, and scrAddress definitions. These are mostly
boilerplate that could be easily copied from the working examples written
earlier in the lecture.
#
Homework 2
It's the same as Homework 1 except the redeemer is a custom type called
MyRedeemer that has two fields called flag1 and flag2 that are just
Bools.
Since the redeemer is a custom type that looks like this:
data MyRedeemer = MyRedeemer
{ flag1 :: Bool
, flag2 :: Bool
} deriving (Generic, FromJSON, ToJSON, ToSchema)
The correct validator can be written like so:
mkValidator _ (MyRedeemer x y) _ =
traceIfFalse "Redeemer booleans do not match" $ x == y
And again, the homework code had broken boilerplate that could be copied from working examples written earlier in the lecture.