-
Notifications
You must be signed in to change notification settings - Fork 211
/
Validity.hs
65 lines (57 loc) · 2.07 KB
/
Validity.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeFamilies #-}
-- |
-- Copyright: © 2020-2022 IOHK
-- License: Apache-2.0
--
module Cardano.Wallet.Read.Primitive.Tx.Features.Validity
( getValidity
, afterShelleyValidityInterval
, shelleyValidityInterval
)
where
import Prelude
import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Tx.Validity
( Validity (..) )
import Cardano.Wallet.Transaction
( ValidityIntervalExplicit (ValidityIntervalExplicit) )
import Data.Quantity
( Quantity (..) )
import qualified Cardano.Ledger.ShelleyMA.TxBody as MA
import qualified Ouroboros.Network.Block as O
getValidity :: EraFun Validity (K (Maybe ValidityIntervalExplicit))
getValidity = EraFun
{ byronFun = noValidity
, shelleyFun = yesShelleyValidity
, allegraFun = yesMaryValidity
, maryFun = yesMaryValidity
, alonzoFun = yesMaryValidity
, babbageFun = yesMaryValidity
, conwayFun = yesMaryValidity
}
where
noValidity = const $ K Nothing
yesShelleyValidity (Validity ttl)
= K . Just . shelleyValidityInterval $ ttl
yesMaryValidity (Validity validity')
= K . Just $ afterShelleyValidityInterval validity'
afterShelleyValidityInterval
:: MA.ValidityInterval
-> ValidityIntervalExplicit
afterShelleyValidityInterval (MA.ValidityInterval from to) =
case (from, to) of
(MA.SNothing, MA.SJust (O.SlotNo s)) ->
ValidityIntervalExplicit (Quantity 0) (Quantity s)
(MA.SNothing, MA.SNothing) ->
ValidityIntervalExplicit (Quantity 0) (Quantity maxBound)
(MA.SJust (O.SlotNo s1), MA.SJust (O.SlotNo s2)) ->
ValidityIntervalExplicit (Quantity s1) (Quantity s2)
(MA.SJust (O.SlotNo s1), MA.SNothing) ->
ValidityIntervalExplicit (Quantity s1) (Quantity maxBound)
shelleyValidityInterval :: O.SlotNo -> ValidityIntervalExplicit
shelleyValidityInterval (O.SlotNo n)
= ValidityIntervalExplicit (Quantity 0) $ Quantity n