@@ -26,7 +26,6 @@ import BotPlutusInterface.Effects (
2626 )
2727import BotPlutusInterface.Files (DummyPrivKey (FromSKey , FromVKey ))
2828import BotPlutusInterface.Files qualified as Files
29- import BotPlutusInterface.TimeSlot (ToWhichSlotTime (ToEndTime ), stackExchangeConvert )
3029import BotPlutusInterface.Types (
3130 ContractEnvironment (.. ),
3231 LogLevel (Debug , Warn ),
@@ -51,13 +50,11 @@ import Data.Map qualified as Map
5150import Data.Row (Row )
5251import Data.Text (Text )
5352import Data.Text qualified as Text
54- import Debug.Trace (traceM )
5553import Ledger (POSIXTime )
5654import Ledger qualified
5755import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash ))
5856import Ledger.Constraints.OffChain (UnbalancedTx (.. ))
5957import Ledger.Slot (Slot (Slot ))
60- import Ledger.TimeSlot (SlotConversionError , posixTimeToEnclosingSlot , slotToEndPOSIXTime )
6158import Ledger.Tx (CardanoTx )
6259import Ledger.Tx qualified as Tx
6360import Plutus.ChainIndex.TxIdState (fromTx , transactionStatus )
@@ -165,13 +162,8 @@ handlePABReq contractEnv req = do
165162 CurrentSlotReq -> CurrentSlotResp <$> currentSlot @ w contractEnv
166163 CurrentTimeReq -> CurrentTimeResp <$> currentTime @ w contractEnv
167164 PosixTimeRangeToContainedSlotRangeReq posixTimeRange ->
168- PosixTimeRangeToContainedSlotRangeResp
169- <$> posixTimeRangeToContainedSlotRange_ @ w posixTimeRange
170- -- PosixTimeRangeToContainedSlotRangeReq posixTimeRange ->
171- -- pure $
172- -- PosixTimeRangeToContainedSlotRangeResp $
173- -- Right $
174- -- posixTimeRangeToContainedSlotRange contractEnv.cePABConfig.pcSlotConfig posixTimeRange
165+ either (error . show ) (PosixTimeRangeToContainedSlotRangeResp . Right )
166+ <$> convertTimeRangeToSlotRange @ w posixTimeRange
175167 AwaitTxStatusChangeReq txId -> AwaitTxStatusChangeResp txId <$> awaitTxStatusChange @ w contractEnv txId
176168 ------------------------
177169 -- Unhandled requests --
@@ -362,27 +354,11 @@ awaitTime ::
362354 POSIXTime ->
363355 Eff effs POSIXTime
364356awaitTime ce pTime = do
365- startingTip <- CardanoCLI. queryTip @ w ce. cePABConfig
366- traceM $ " Starting tip: " ++ show startingTip
367-
368- slotFromTime <- posixTimeToSlot @ w pTime >>= either (error . show ) return
369- traceM $ " Converting " ++ show pTime ++ " to slot:"
370- traceM $ " - with node queries: " ++ show slotFromTime
371- traceM $ " - with stack exchng: " ++ show (stackExchangeConvert pTime)
372- traceM $ " - with ledger stuff: " ++ show oldSlotFromTime
357+ slotFromTime <- rightOrErr <$> posixTimeToSlot @ w pTime
373358 slot' <- awaitSlot ce slotFromTime
374- traceM $ " Converting " ++ show slot' ++ " to time:"
375- ethTime <- slotToPOSIXTime @ w ToEndTime slot'
376- time' <- either (error . show ) return ethTime
377- traceM $ " - with node queries: " ++ show time'
378- traceM $ " - with ledger stuff: " ++ show (oldTimeFromSlot slot')
379-
380- endTip <- CardanoCLI. queryTip @ w ce. cePABConfig
381- traceM $ " Current tip: " ++ show endTip
382- return time'
359+ rightOrErr <$> slotToPOSIXTime @ w slot'
383360 where
384- oldSlotFromTime = posixTimeToEnclosingSlot ce. cePABConfig. pcSlotConfig pTime
385- oldTimeFromSlot = slotToEndPOSIXTime ce. cePABConfig. pcSlotConfig
361+ rightOrErr = either (error . show ) id
386362
387363currentSlot ::
388364 forall (w :: Type ) (effs :: [Type -> Type ]).
@@ -407,14 +383,5 @@ currentTime ::
407383 Eff effs POSIXTime
408384currentTime contractEnv =
409385 currentSlot @ w contractEnv
410- >>= slotToPOSIXTime @ w ToEndTime
386+ >>= slotToPOSIXTime @ w
411387 >>= either (error . show ) return
412-
413- posixTimeRangeToContainedSlotRange_ ::
414- forall (w :: Type ) (effs :: [Type -> Type ]).
415- Member (PABEffect w ) effs =>
416- Ledger. POSIXTimeRange ->
417- Eff effs (Either SlotConversionError Ledger. SlotRange )
418- posixTimeRangeToContainedSlotRange_ posixTimeRange =
419- convertTimeRangeToSlotRange @ w posixTimeRange
420- >>= either (error . show ) (return . Right )
0 commit comments