Created
December 16, 2022 20:12
-
-
Save caike/43f579ad6fa10835432c4c4ec1652426 to your computer and use it in GitHub Desktop.
Plutus Pioneers Week03 Homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# INLINABLE mkValidator #-} | |
-- 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 datum _ sc = traceIfFalse "cannot grab" (beneficiary1Grab || beneficiary2Grab) | |
where | |
info :: TxInfo | |
info = scriptContextTxInfo sc | |
beneficiary1Grab :: Bool | |
beneficiary1Grab = currentSlotBeforeOrAtDeadline && signedByBeneficiary1 | |
currentSlotBeforeOrAtDeadline :: Bool | |
-- the current slot is before or at the deadline | |
currentSlotBeforeOrAtDeadline = contains (to $ deadline datum) $ txInfoValidRange info | |
signedByBeneficiary1 :: Bool | |
signedByBeneficiary1 = txSignedBy info $ unPaymentPubKeyHash $ beneficiary1 datum | |
beneficiary2Grab :: Bool | |
beneficiary2Grab = currentSlotAfterDeadline && signedByBeneficiary2 | |
currentSlotAfterDeadline :: Bool | |
-- the current slot is AFTER the deadline | |
currentSlotAfterDeadline = not $ overlaps (to $ deadline datum) $ txInfoValidRange info | |
signedByBeneficiary2 :: Bool | |
signedByBeneficiary2 = txSignedBy info $ unPaymentPubKeyHash $ beneficiary2 datum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment