@@ -31,6 +31,7 @@ module Cardano.Ledger.Conway.TxInfo (
31
31
transTxOutV1 ,
32
32
transMintValue ,
33
33
transTxBodyId ,
34
+ transValidityInterval ,
34
35
transVotingProcedures ,
35
36
transProposal ,
36
37
toPlutusV3Args ,
@@ -103,6 +104,7 @@ import Cardano.Ledger.Plutus.Data (Data)
103
104
import Cardano.Ledger.Plutus.Language (Language (.. ), PlutusArgs (.. ), SLanguage (.. ))
104
105
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (.. ))
105
106
import Cardano.Ledger.Plutus.TxInfo (
107
+ slotToPOSIXTime ,
106
108
transBoundedRational ,
107
109
transCoinToLovelace ,
108
110
transCoinToValue ,
@@ -116,6 +118,8 @@ import Cardano.Ledger.Plutus.TxInfo (
116
118
)
117
119
import qualified Cardano.Ledger.Plutus.TxInfo as TxInfo
118
120
import Cardano.Ledger.TxIn (TxId (.. ), TxIn (.. ))
121
+ import Cardano.Slotting.EpochInfo (EpochInfo )
122
+ import Cardano.Slotting.Time (SystemStart )
119
123
import Control.Arrow (ArrowChoice (.. ))
120
124
import Control.DeepSeq (NFData )
121
125
import Control.Monad (unless , when , zipWithM )
@@ -125,6 +129,7 @@ import Data.List.NonEmpty (NonEmpty (..))
125
129
import qualified Data.Map.Strict as Map
126
130
import qualified Data.OSet.Strict as OSet
127
131
import qualified Data.Set as Set
132
+ import Data.Text (Text )
128
133
import GHC.Generics hiding (to )
129
134
import Lens.Micro ((^.) )
130
135
import NoThunks.Class (NoThunks )
@@ -398,7 +403,7 @@ instance EraPlutusTxInfo 'PlutusV1 ConwayEra where
398
403
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
399
404
guardConwayFeaturesForPlutusV1V2 ltiTx
400
405
timeRange <-
401
- Alonzo. transValidityInterval ltiTx ltiProtVer ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
406
+ transValidityInterval ltiTx ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
402
407
inputs <- mapM (transTxInInfoV1 ltiUTxO) (Set. toList (txBody ^. inputsTxBodyL))
403
408
mapM_ (transTxInInfoV1 ltiUTxO) (Set. toList (txBody ^. referenceInputsTxBodyL))
404
409
outputs <-
@@ -433,7 +438,7 @@ instance EraPlutusTxInfo 'PlutusV2 ConwayEra where
433
438
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
434
439
guardConwayFeaturesForPlutusV1V2 ltiTx
435
440
timeRange <-
436
- Alonzo. transValidityInterval ltiTx ltiProtVer ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
441
+ transValidityInterval ltiTx ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
437
442
inputs <- mapM (Babbage. transTxInInfoV2 ltiUTxO) (Set. toList (txBody ^. inputsTxBodyL))
438
443
refInputs <- mapM (Babbage. transTxInInfoV2 ltiUTxO) (Set. toList (txBody ^. referenceInputsTxBodyL))
439
444
outputs <-
@@ -470,7 +475,7 @@ instance EraPlutusTxInfo 'PlutusV3 ConwayEra where
470
475
471
476
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
472
477
timeRange <-
473
- Alonzo. transValidityInterval ltiTx ltiProtVer ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
478
+ transValidityInterval ltiTx ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
474
479
let
475
480
txInputs = txBody ^. inputsTxBodyL
476
481
refInputs = txBody ^. referenceInputsTxBodyL
@@ -764,3 +769,30 @@ class
764
769
765
770
instance ConwayEraPlutusTxInfo 'PlutusV3 ConwayEra where
766
771
toPlutusChangedParameters _ x = PV3. ChangedParameters (PV3. dataToBuiltinData (toPlutusData x))
772
+
773
+ -- | Translate a validity interval to POSIX time
774
+ transValidityInterval ::
775
+ forall proxy era a .
776
+ Inject (AlonzoContextError era ) a =>
777
+ proxy era ->
778
+ EpochInfo (Either Text ) ->
779
+ SystemStart ->
780
+ ValidityInterval ->
781
+ Either a PV1. POSIXTimeRange
782
+ transValidityInterval _ epochInfo systemStart = \ case
783
+ ValidityInterval SNothing SNothing -> pure PV1. always
784
+ ValidityInterval (SJust i) SNothing -> PV1. from <$> transSlotToPOSIXTime i
785
+ ValidityInterval SNothing (SJust i) -> do
786
+ t <- transSlotToPOSIXTime i
787
+ pure $ PV1. Interval (PV1. LowerBound PV1. NegInf True ) (PV1. strictUpperBound t)
788
+ ValidityInterval (SJust i) (SJust j) -> do
789
+ t1 <- transSlotToPOSIXTime i
790
+ t2 <- transSlotToPOSIXTime j
791
+ pure $
792
+ PV1. Interval
793
+ (PV1. lowerBound t1)
794
+ (PV1. strictUpperBound t2)
795
+ where
796
+ transSlotToPOSIXTime =
797
+ left (inject . TimeTranslationPastHorizon @ era )
798
+ . slotToPOSIXTime epochInfo systemStart
0 commit comments