Skip to content

Commit 7534388

Browse files
committed
resolving review comments
1 parent eda445f commit 7534388

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ balanceTxIO pabConf ownPkh unbalancedTx =
9595
lift $ printBpiLog @w Debug $ viaShow utxoIndex
9696

9797
-- We need this folder on the CLI machine, which may not be the local machine
98-
lift $ createDirectoryIfMissingCLI @w False (Text.unpack "pcTxFileDir")
98+
lift $ createDirectoryIfMissingCLI @w False (Text.unpack pabConf.pcTxFileDir)
9999

100100
-- Adds required collaterals, only needs to happen once
101101
-- Also adds signatures for fee calculation

src/BotPlutusInterface/TimeSlot.hs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ module BotPlutusInterface.TimeSlot (
1111
posixTimeRangeToContainedSlotRangeIO,
1212
) where
1313

14-
import BotPlutusInterface.QueryNode (NodeInfo (NodeInfo), queryEraHistory, querySystemStart)
15-
import BotPlutusInterface.Types (PABConfig, pcNetwork, pcProtocolParams)
14+
import BotPlutusInterface.QueryNode (
15+
NodeInfo (NodeInfo),
16+
queryEraHistory,
17+
querySystemStart,
18+
)
19+
import BotPlutusInterface.Types (
20+
PABConfig,
21+
pcNetwork,
22+
pcProtocolParams,
23+
)
1624
import Cardano.Api (CardanoMode, EraHistory)
1725
import Cardano.Api qualified as CAPI
1826
import Cardano.Ledger.Alonzo.PParams (_protocolVersion)
@@ -22,13 +30,24 @@ import Cardano.Slotting.EpochInfo (hoistEpochInfo)
2230
import Cardano.Slotting.Time (SystemStart, toRelativeTime)
2331
import Control.Monad.Except (runExcept)
2432
import Control.Monad.IO.Class (liftIO)
25-
import Control.Monad.Trans.Either (EitherT, firstEitherT, hoistEither, newEitherT, runEitherT)
33+
import Control.Monad.Trans.Either (
34+
EitherT,
35+
firstEitherT,
36+
hoistEither,
37+
newEitherT,
38+
runEitherT,
39+
)
2640
import Data.Bifunctor (first)
2741
import Data.Text (Text)
2842
import Data.Text qualified as Text
29-
import Data.Time (secondsToNominalDiffTime)
43+
import Data.Time (UTCTime, secondsToNominalDiffTime)
3044
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
31-
import Ledger (Extended (Finite, NegInf, PosInf), Interval (Interval), LowerBound (LowerBound), UpperBound (UpperBound))
45+
import Ledger (
46+
Extended (Finite, NegInf, PosInf),
47+
Interval (Interval),
48+
LowerBound (LowerBound),
49+
UpperBound (UpperBound),
50+
)
3251
import Ledger qualified
3352
import Ouroboros.Consensus.HardFork.History qualified as Consensus
3453
import Ouroboros.Consensus.HardFork.History.Qry qualified as HF
@@ -86,7 +105,7 @@ posixTimeRangeToContainedSlotRangeIO
86105
-- getting required info from node
87106
nodeInfo <- liftIO $ mkNodeInfo pabConf
88107
sysStart <- newET $ querySystemStart nodeInfo
89-
eraHsitory <- newET (queryEraHistory nodeInfo)
108+
eraHsitory <- newET $ queryEraHistory nodeInfo
90109
let epochInfo = toLedgerEpochInfo eraHsitory
91110
pparams =
92111
CAPI.toLedgerPParams
@@ -101,9 +120,16 @@ posixTimeRangeToContainedSlotRangeIO
101120
startSlotClosure <- getClosure startSlot startIncl
102121
endSlot <- extTimeToExtSlot end
103122
endSlotClosure <- getClosure endSlot endIncl
104-
let lowerB = LowerBound startSlot startSlotClosure
123+
let lowerB :: LowerBound Ledger.Slot
124+
lowerB = LowerBound startSlot startSlotClosure
125+
126+
upperB :: UpperBound Ledger.Slot
105127
upperB = UpperBound endSlot endSlotClosure
106-
pure $ Interval lowerB upperB
128+
129+
range :: Ledger.SlotRange
130+
range = Interval lowerB upperB
131+
132+
pure range
107133
where
108134
convertExtended sysStart eraHist =
109135
firstEitherT toError . hoistEither . \case
@@ -128,13 +154,16 @@ posixTimeToSlot ::
128154
EraHistory CardanoMode ->
129155
Ledger.POSIXTime ->
130156
Either HF.PastHorizonException Ledger.Slot
131-
posixTimeToSlot sysStart eraHist pTime =
157+
posixTimeToSlot sysStart eraHist pTime = do
132158
-- toRelativeTime checks that pTime >= sysStart via `Control.Exception.assert`
133159
let relativeTime = toRelativeTime sysStart (toUtc pTime)
134160
(CAPI.EraHistory _ int) = eraHist
135-
in HF.interpretQuery int (HF.wallclockToSlot relativeTime)
136-
>>= \(s, _, _) -> return (fromSlotNo s)
161+
query = HF.wallclockToSlot relativeTime
162+
163+
(sn, _, _) <- HF.interpretQuery int query
164+
return (fromSlotNo sn)
137165
where
166+
toUtc :: Ledger.POSIXTime -> UTCTime
138167
toUtc (Ledger.POSIXTime milliseconds) =
139168
posixSecondsToUTCTime
140169
. secondsToNominalDiffTime

test/Spec/MockContract.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,10 @@ mockSlotRange ::
670670
forall (w :: Type).
671671
POSIXTimeRange ->
672672
MockContract w (Either TimeSlotConversionError SlotRange)
673-
mockSlotRange = \case
673+
mockSlotRange = pure . Right . \case
674674
Interval (LowerBound NegInf True) (UpperBound PosInf True) ->
675-
pure $ Right $ Interval (LowerBound NegInf True) (UpperBound PosInf True)
675+
Interval (LowerBound NegInf True) (UpperBound PosInf True)
676676
_ ->
677-
pure (Right slotRange)
677+
slotRange
678678
where
679679
slotRange = Interval (lowerBound 47577202) (strictUpperBound 50255602)

0 commit comments

Comments
 (0)