Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking authored Nov 28, 2024
1 parent f346460 commit 76f957e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ newNetworkEnvMock = do
, getTimeInterpreter =
pure $ Time.toTimeTranslationPure Time.mockTimeInterpreter
, slotToUTCTime = pure Time.unsafeUTCTimeOfSlot
-- , utcTimeToSlot = pure . Just . Time.unsafeSlotOfUTCTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,6 @@ import qualified Cardano.Wallet.Network.Implementation as NetworkLayer
NodeToClient 'NetworkEnv'
------------------------------------------------------------------------------}

withNetwork
:: HasCallStack
=> NetworkParameters
-- ^ Initial blockchain parameters
-> CardanoNodeConn
-- ^ Socket for communicating with the node
-> NodeToClientVersionData
-- ^ Codecs for the node's client
-> SyncTolerance
-> (NetworkEnv IO (Read.EraValue Read.Block) -> IO a)
-- ^ Callback function with the network layer
-> IO a
withNetwork np conn vData syncTol act =
NetworkLayer.withNetworkLayer
nullTracer -- Using this for now
tunedForMainnetPipeliningStrategy
np
conn
vData
syncTol
(act . fromNetworkLayer)

-- | Translate the old NetworkLayer to the new NetworkEnv interface
fromNetworkLayer
Expand All @@ -115,7 +94,6 @@ fromNetworkLayer nl = mapBlock Read.fromConsensusBlock $
NetworkLayer.currentPParams nl
, getTimeInterpreter = toTimeTranslation (NetworkLayer.timeInterpreter nl)
, slotToUTCTime = Time.slotToUTCTime <$> snapshot ti
-- , utcTimeToSlot = pure . Just . Time.unsafeSlotOfUTCTime
}

where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,12 @@ data NetworkEnv m block = NetworkEnv
, currentPParams
:: m (Read.EraValue Read.PParams)
-- ^ Current protocol paramters.
, getTimeInterpreter
, getTimeTranslation
:: m Time.TimeTranslation
-- ^ Get the current 'TimeInterpreter' from the Cardano node.
, slotToUTCTime
:: m (Slot -> (Maybe (WithOrigin UTCTime)))

-- -- ^ Try to convert a set of slots to their UTCTimes counterparts
-- , utcTimeToSlot
-- :: UTCTime
-- -> m (Maybe Slot)
}

mapBlock
Expand Down
12 changes: 4 additions & 8 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,16 @@ type LookupTimeFromSlot = Slot -> Maybe (WithOrigin UTCTime)
TimeInterpreter
------------------------------------------------------------------------------}

-- TODO: Is this the start time of the slot?
-- | Look up the UTCTime corresponding to the start of the provided `Slot`.

TODO: Check roundtrip properties once we need to implement the corresponding 'utcTimeToSlot'.
slotToUTCTime :: TimeInterpreter -> LookupTimeFromSlot
slotToUTCTime _ti Origin = Just Origin --either (const Nothing) Just $ interpretQuery ti $ Primitive.slotToUTCTime minBound
slotToUTCTime _ti Origin = Just Origin
slotToUTCTime ti (At s) = either (const Nothing) (Just . At) . interpretQuery ti . Primitive.slotToUTCTime =<< convertSlotNo s
where
convertSlotNo :: SlotNo -> Maybe Primitive.SlotNo
convertSlotNo (SlotNo n) = Primitive.SlotNo <$> intCastMaybe n

--utcTimeToSlot :: TimeInterpreter -> UTCTime -> Maybe Slot
--utcTimeToSlot ti t = either (const Nothing) Just . interpretQuery ti $ do
-- ongoingSlotAt $ toRelativeTime startTime t
-- where
-- convertSlotNo :: Primitive.SlotNo -> SlotNo
-- convertSlotNo (Primitive.SlotNo n) = SlotNo $ intCast n

-- TODO: Rename to mainnetUTCTimeOfSlot
-- TODO: Move to tests?
Expand Down

0 comments on commit 76f957e

Please sign in to comment.