Skip to content

Commit e512b3a

Browse files
Add toLedgerValidityInterval and fromLedgerValidityInterval
1 parent 49bac63 commit e512b3a

File tree

1 file changed

+31
-1
lines changed
  • cardano-api/src/Cardano/Api/Tx/Internal

1 file changed

+31
-1
lines changed

cardano-api/src/Cardano/Api/Tx/Internal/Body.hs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ module Cardano.Api.Tx.Internal.Body
207207
, fromByronTxIn
208208
, fromLedgerTxOuts
209209
, renderTxIn
210+
, toLedgerValidityInterval
211+
, fromLedgerValidityInterval
210212

211213
-- ** Misc helpers
212214
, calculateExecutionUnitsLovelace
@@ -276,7 +278,7 @@ import Cardano.Ledger.Alonzo.Tx qualified as Alonzo (hashScriptIntegrity)
276278
import Cardano.Ledger.Alonzo.TxWits qualified as Alonzo
277279
import Cardano.Ledger.Api qualified as L
278280
import Cardano.Ledger.Babbage.UTxO qualified as L
279-
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
281+
import Cardano.Ledger.BaseTypes (StrictMaybe (..), maybeToStrictMaybe)
280282
import Cardano.Ledger.Binary (Annotated (..))
281283
import Cardano.Ledger.Binary qualified as CBOR
282284
import Cardano.Ledger.Coin qualified as L
@@ -3129,3 +3131,31 @@ getReferenceInputsSizeForTxIds beo utxo txIds = babbageEraOnwardsConstraints beo
31293131
calculateExecutionUnitsLovelace :: Ledger.Prices -> ExecutionUnits -> Maybe L.Coin
31303132
calculateExecutionUnitsLovelace prices eUnits =
31313133
return $ Alonzo.txscriptfee prices (toAlonzoExUnits eUnits)
3134+
3135+
toLedgerValidityInterval
3136+
:: (TxValidityLowerBound era, TxValidityUpperBound era)
3137+
-> L.ValidityInterval
3138+
toLedgerValidityInterval (lowerBound, upperBound) =
3139+
L.ValidityInterval
3140+
{ L.invalidBefore =
3141+
case lowerBound of
3142+
TxValidityNoLowerBound -> SNothing
3143+
TxValidityLowerBound _ s -> SJust s
3144+
, L.invalidHereafter =
3145+
case upperBound of
3146+
TxValidityUpperBound _ s -> maybeToStrictMaybe s
3147+
}
3148+
3149+
fromLedgerValidityInterval
3150+
:: AllegraEraOnwards era
3151+
-> L.ValidityInterval
3152+
-> (TxValidityLowerBound era, TxValidityUpperBound era)
3153+
fromLedgerValidityInterval aeo validityInterval =
3154+
let L.ValidityInterval{L.invalidBefore = invalidBefore, L.invalidHereafter = invalidHereAfter} = validityInterval
3155+
lowerBound = case invalidBefore of
3156+
SNothing -> TxValidityNoLowerBound
3157+
SJust s -> TxValidityLowerBound aeo s
3158+
upperBound = case invalidHereAfter of
3159+
SNothing -> TxValidityUpperBound (convert aeo) Nothing
3160+
SJust s -> TxValidityUpperBound (convert aeo) (Just s)
3161+
in (lowerBound, upperBound)

0 commit comments

Comments
 (0)