Skip to content

Commit 2f66ea7

Browse files
committed
fixes
- review comments resolved - link to sources for mintining policies sorting comment corrected - overlooked redundant Slot conversion in `convertExtended` removed
1 parent 944b904 commit 2f66ea7

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/BotPlutusInterface/ExBudget.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mkBudgetMaps exUnitsMap txBody = do
151151
CAPI.TxMintValue _ value _ ->
152152
{- The minting policies are indexed in policy id order in the value
153153
reference:
154-
https://github.com/input-output-hk/cardano-node/blob/e31455eaeca98530ce561b79687a8e465ebb3fdd/cardano-api/src/Cardano/Api/TxBody.hs#L2851
154+
https://github.com/input-output-hk/cardano-node/blob/e31455eaeca98530ce561b79687a8e465ebb3fdd/cardano-api/src/Cardano/Api/TxBody.hs#L2881
155155
-}
156156
let CAPI.ValueNestedRep bundle = CAPI.valueToNestedRep value
157157
in Map.fromList

src/BotPlutusInterface/TimeSlot.hs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import BotPlutusInterface.Types (
2323
)
2424
import Cardano.Api (CardanoMode, EraHistory)
2525
import Cardano.Api qualified as CAPI
26-
import Cardano.Ledger.Alonzo.PParams (_protocolVersion)
26+
import Cardano.Ledger.Alonzo.PParams (_protocolVersion, PParams)
2727
import Cardano.Ledger.Alonzo.TxInfo (slotToPOSIXTime)
2828
import Cardano.Ledger.Slot (EpochInfo)
2929
import Cardano.Slotting.EpochInfo (hoistEpochInfo)
@@ -53,6 +53,8 @@ import Ouroboros.Consensus.HardFork.History qualified as Consensus
5353
import Ouroboros.Consensus.HardFork.History.Qry qualified as HF
5454
import System.Environment (getEnv)
5555
import Prelude
56+
import Cardano.Ledger.Crypto (StandardCrypto)
57+
import Cardano.Ledger.Alonzo (AlonzoEra)
5658

5759
-- | Error returned by the functions of this module
5860
data TimeSlotConversionError
@@ -65,9 +67,9 @@ data TimeSlotConversionError
6567
slotToPOSIXTimeIO :: PABConfig -> Ledger.Slot -> IO (Either TimeSlotConversionError Ledger.POSIXTime)
6668
slotToPOSIXTimeIO pabConf lSlot = runEitherT $ do
6769
nodeInfo <- liftIO $ mkNodeInfo pabConf
68-
eraHsitory <- newET (queryEraHistory nodeInfo)
70+
eraHistory <- newET (queryEraHistory nodeInfo)
6971
sysStart <- newET $ querySystemStart nodeInfo
70-
let epochInfo = toLedgerEpochInfo eraHsitory
72+
let epochInfo = toLedgerEpochInfo eraHistory
7173
pparams =
7274
CAPI.toLedgerPParams
7375
CAPI.ShelleyBasedEraAlonzo
@@ -105,21 +107,22 @@ posixTimeRangeToContainedSlotRangeIO
105107
-- getting required info from node
106108
nodeInfo <- liftIO $ mkNodeInfo pabConf
107109
sysStart <- newET $ querySystemStart nodeInfo
108-
eraHsitory <- newET $ queryEraHistory nodeInfo
109-
let epochInfo = toLedgerEpochInfo eraHsitory
110+
eraHistory <- newET $ queryEraHistory nodeInfo
111+
let epochInfo = toLedgerEpochInfo eraHistory
110112
pparams =
111113
CAPI.toLedgerPParams
112114
CAPI.ShelleyBasedEraAlonzo
113115
(pcProtocolParams pabConf)
114116

115-
let extTimeToExtSlot = convertExtended sysStart eraHsitory
117+
let extTimeToExtSlot = convertExtended sysStart eraHistory
116118
getClosure = getExtClosure pparams epochInfo sysStart
117119

118120
-- conversions
119121
startSlot <- extTimeToExtSlot start
120122
startSlotClosure <- getClosure startSlot startIncl
121123
endSlot <- extTimeToExtSlot end
122124
endSlotClosure <- getClosure endSlot endIncl
125+
123126
let lowerB :: LowerBound Ledger.Slot
124127
lowerB = LowerBound startSlot startSlotClosure
125128

@@ -131,14 +134,30 @@ posixTimeRangeToContainedSlotRangeIO
131134

132135
pure range
133136
where
137+
-- helper to convert `Extended POSIXTime` to `Extended Slot`
138+
-- using `posixTimeToSlot`
139+
convertExtended ::
140+
Monad m =>
141+
SystemStart ->
142+
EraHistory CardanoMode ->
143+
Extended Ledger.POSIXTime ->
144+
EitherT TimeSlotConversionError m (Extended Ledger.Slot)
134145
convertExtended sysStart eraHist =
135146
firstEitherT toError . hoistEither . \case
136-
Finite pTime -> do
137-
s <- posixTimeToSlot sysStart eraHist pTime
138-
pure . Finite . Ledger.Slot . toInteger $ s
147+
Finite pTime -> Finite <$> posixTimeToSlot sysStart eraHist pTime
139148
NegInf -> pure NegInf
140149
PosInf -> pure PosInf
141150

151+
-- helper to calulate bound's closure
152+
-- if bound is not `NegInf` or `PosInf`, then `Closure` need to be calculated
153+
-- https://github.com/input-output-hk/plutus-apps/blob/e51f57fa99f4cc0942ba6476b0689e43f0948eb3/plutus-ledger/src/Ledger/TimeSlot.hs#L125-L130
154+
getExtClosure ::
155+
PParams (AlonzoEra StandardCrypto) ->
156+
EpochInfo (Either CAPI.TransactionValidityError) ->
157+
SystemStart ->
158+
Extended Ledger.Slot ->
159+
Bool -> -- current `Closure` of lower or upper bound of `Ledger.POSIXTimeRange`
160+
EitherT TimeSlotConversionError IO Bool
142161
getExtClosure pparams epochInfo sysStart exSlot currentClosure =
143162
firstEitherT toError . hoistEither $
144163
case exSlot of

0 commit comments

Comments
 (0)