I'm working through the Plutus Pioneer program and I have a bug in my implementation of the validator for homework one. I'd like to add some logging to the validator to get more insight into what I'm doing wrong.
I've seen that the logInfo
function is used in the wallet code and I've tried adding that to the validator like:
mkValidator dat _ ctx = do
logInfo @P.String $ printf "deadline %s" (P.show $ deadline dat)
False -- dummy value to figure out how to get logging to work
but when I do that I get the following error:
• Couldn't match expected type ‘Bool’
with actual type ‘Contract w0 s0 e0 b0’
• In a stmt of a 'do' block:
logInfo @P.String $ printf "deadline %s" (P.show $ deadline dat)
In the expression:
do logInfo @P.String $ printf "deadline %s" (P.show $ deadline dat)
False
In an equation for ‘mkValidator’:
mkValidator dat _ ctx
= do logInfo @P.String
$ printf "deadline %s" (P.show $ deadline dat)
False
Upon checking the type of logInfo
I see that it has the type logInfo :: forall a w (s :: Row *) e. ToJSON a => a -> Contract w s e ()
which seems to match up with the error that's given.
How come I can't use this logging function if I'm later returning False
? I suspect I'm misunderstanding something fairly basic about how haskell works.
EDIT: I've also tried using trace
with
mkValidator dat _ ctx = do
trace $ printf "deadline %s" (P.show $ deadline dat)
False
but that also results in an error:
• Couldn't match expected type ‘Bool’ with actual type ‘a0 -> b0’
• In a stmt of a 'do' block:
trace $ printf "deadline %s" (P.show $ deadline dat)
In the expression:
do trace $ printf "deadline %s" (P.show $ deadline dat)
False
In an equation for ‘mkValidator’:
mkValidator dat _ ctx
= do trace $ printf "deadline %s" (P.show $ deadline dat)
False