mirror of
https://github.com/FiloSpaTeam/plutus-pioneer-program.git
synced 2024-11-25 00:02:18 +01:00
fixing week03/homework
This commit is contained in:
parent
a45c7866c1
commit
a1ff9ba5ee
2 changed files with 9 additions and 6 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue