Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Mary token examples: timelocks & sigs #1987

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/Timelocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,26 @@ pattern RequireTimeStart mslot <-
-- =================================================================
-- Evaluating and validating a Timelock

-- PLEASE SOMEONE VERIFY I AM USING atOrAfter and strictlyBefore RIGHT
-- | less-than-equal comparison, where Nothing is negative infinity
lteNegInfty :: SlotNo -> StrictMaybe SlotNo -> Bool
lteNegInfty _ SNothing = False -- i > -∞
lteNegInfty i (SJust j) = i <= j

atOrAfter :: StrictMaybe SlotNo -> SlotNo -> Bool
atOrAfter SNothing _ = True
atOrAfter (SJust i) j = i <= j

strictlyBefore :: SlotNo -> StrictMaybe SlotNo -> Bool
strictlyBefore _i SNothing = True
strictlyBefore i (SJust j) = i < j
-- | less-than-equal comparison, where Nothing is positive infinity
ltePosInfty :: StrictMaybe SlotNo -> SlotNo -> Bool
ltePosInfty SNothing _ = False -- ∞ > j
ltePosInfty (SJust i) j = i <= j

evalTimelock ::
Era era =>
Set (KeyHash 'Witness (Crypto era)) ->
ValidityInterval ->
Timelock era ->
Bool
evalTimelock _vhks (ValidityInterval mstart _) (RequireTimeStart slot) =
atOrAfter mstart slot
evalTimelock _vhks (ValidityInterval _ mexpire) (RequireTimeExpire slot) =
strictlyBefore slot mexpire
evalTimelock _vhks (ValidityInterval txStart _) (RequireTimeStart lockStart) =
lockStart `lteNegInfty` txStart
evalTimelock _vhks (ValidityInterval _ txExp) (RequireTimeExpire lockExp) =
txExp `ltePosInfty` lockExp
evalTimelock vhks _vi (RequireSignature hash) = member hash vhks
evalTimelock vhks vi (RequireAllOf xs) =
all (evalTimelock vhks vi) xs
Expand Down
Loading