diff --git a/code/week03/src/Week03/Homework1.hs b/code/week03/src/Week03/Homework1.hs index cb786ad..7c6a6a9 100644 --- a/code/week03/src/Week03/Homework1.hs +++ b/code/week03/src/Week03/Homework1.hs @@ -46,10 +46,10 @@ PlutusTx.unstableMakeIsData ''VestingDatum -- This should validate if either beneficiary1 has signed the transaction and the current slot is before or at the deadline -- or if beneficiary2 has signed the transaction and the deadline has passed. mkValidator :: VestingDatum -> () -> ScriptContext -> Bool -mkValidator dat () ctx = (traceIfFalse "beneficiary 1 not signed" signedBeneficiary1 && - traceIfFalse "beneficiary 1 deadline expired" (not $ deadlineExpired)) || - (traceIfFalse "beneficiary 2 not signed" signedBeneficiary2 && - traceIfFalse "beneficiary 2 deadline not reached yet" deadlineExpired) +mkValidator dat () ctx + | (signedBeneficiary1 && deadlineValid) = True + | (signedBeneficiary2 && deadlineExpired) = True + | otherwise = False where info :: TxInfo info = scriptContextTxInfo ctx @@ -61,7 +61,10 @@ mkValidator dat () ctx = (traceIfFalse "beneficiary 1 not signed" signedBenefici signedBeneficiary2 = txSignedBy info $ beneficiary2 dat deadlineExpired :: Bool - deadlineExpired = contains (from $ deadline dat) $ txInfoValidRange info + deadlineExpired = contains (from $ (1 + deadline dat)) $ txInfoValidRange info + + deadlineValid :: Bool + deadlineValid = contains (to $ deadline dat) $ txInfoValidRange info data Vesting instance Scripts.ValidatorTypes Vesting where diff --git a/code/week03/src/Week03/Homework2.hs b/code/week03/src/Week03/Homework2.hs index 3ace17c..2fcf6e7 100644 --- a/code/week03/src/Week03/Homework2.hs +++ b/code/week03/src/Week03/Homework2.hs @@ -116,7 +116,7 @@ grab = do Just d -> d <= now endpoints :: Contract () VestingSchema Text () -endpoints = (give' + grab') >> endpoints +endpoints = (give' `select` grab') >> endpoints where give' = endpoint @"give" >>= give grab' = endpoint @"grab" >> grab