fixing week03/homework

This commit is contained in:
Claudio Maradonna 2021-07-30 19:17:43 +02:00
parent a45c7866c1
commit a1ff9ba5ee
Signed by untrusted user who does not match committer: claudiomaradonna
GPG key ID: 0CBA58694C5680D9
2 changed files with 9 additions and 6 deletions

View file

@ -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 -- 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. -- or if beneficiary2 has signed the transaction and the deadline has passed.
mkValidator :: VestingDatum -> () -> ScriptContext -> Bool mkValidator :: VestingDatum -> () -> ScriptContext -> Bool
mkValidator dat () ctx = (traceIfFalse "beneficiary 1 not signed" signedBeneficiary1 && mkValidator dat () ctx
traceIfFalse "beneficiary 1 deadline expired" (not $ deadlineExpired)) || | (signedBeneficiary1 && deadlineValid) = True
(traceIfFalse "beneficiary 2 not signed" signedBeneficiary2 && | (signedBeneficiary2 && deadlineExpired) = True
traceIfFalse "beneficiary 2 deadline not reached yet" deadlineExpired) | otherwise = False
where where
info :: TxInfo info :: TxInfo
info = scriptContextTxInfo ctx info = scriptContextTxInfo ctx
@ -61,7 +61,10 @@ mkValidator dat () ctx = (traceIfFalse "beneficiary 1 not signed" signedBenefici
signedBeneficiary2 = txSignedBy info $ beneficiary2 dat signedBeneficiary2 = txSignedBy info $ beneficiary2 dat
deadlineExpired :: Bool 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 data Vesting
instance Scripts.ValidatorTypes Vesting where instance Scripts.ValidatorTypes Vesting where

View file

@ -116,7 +116,7 @@ grab = do
Just d -> d <= now Just d -> d <= now
endpoints :: Contract () VestingSchema Text () endpoints :: Contract () VestingSchema Text ()
endpoints = (give' + grab') >> endpoints endpoints = (give' `select` grab') >> endpoints
where where
give' = endpoint @"give" >>= give give' = endpoint @"give" >>= give
grab' = endpoint @"grab" >> grab grab' = endpoint @"grab" >> grab