Skip to content

Commit

Permalink
feat(#326): fix doc typos, remove MonadIO instance for some of the …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
sourabhxyz committed Aug 26, 2024
1 parent b1ca12b commit 3658eb7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/GeniusYield/Test/FeeTracker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ module GeniusYield.Test.FeeTracker (
import Control.Monad.Except
import Control.Monad.Random
import Control.Monad.State.Strict
import Data.Foldable (foldMap')
import Data.Foldable (foldMap')
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as M
import Data.Monoid
import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Encoding as LTE
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Encoding as LTE

import qualified Data.Aeson as Aeson
import qualified Data.Aeson as Aeson

import GeniusYield.HTTP.Errors (someBackendError)
import GeniusYield.Imports
Expand All @@ -56,9 +56,9 @@ instance Monoid UserExtraLovelace where
mempty = UserExtraLovelace mempty mempty

-- | Track extra lovelace per user.
-- Note: This does the tracking during tranasaction building.
-- Note: This does the tracking during transaction building.
-- If you do not wish to submit said transaction, you should not have it tracked.
-- Use 'ignoreFeeTracking . buildTxBody' etc in those cases.
-- Use 'withoutFeeTracking' etc in those cases.
newtype FeeTrackerState = FeeTrackerState { feesPerUser :: Map GYPubKeyHash UserExtraLovelace }
deriving stock (Eq, Ord, Show)

Expand Down Expand Up @@ -104,7 +104,7 @@ wrapBodyBuilder f skeletons = do
case res of
GYTxBuildSuccess txBodies -> helpers txBodies
GYTxBuildPartialSuccess _ txBodies -> helpers txBodies
_ -> pure ()
_ -> pure ()
pure res
where
helper ownPkh (skeleton, txBody) = do
Expand Down
14 changes: 7 additions & 7 deletions src/GeniusYield/Test/Privnet/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ conwayGenesis =
, cgInitialDReps = mempty
}

-- | This is defined same as `cardanoTestnetDefault` except we use our own conway genesis parameters.
cardanoTestnet' opts conf = do
Api.AnyCardanoEra cEra <- pure $ cardanoNodeEra cardanoDefaultTestnetOptions
alonzoGenesis <- getDefaultAlonzoGenesis cEra
(startTime, shelleyGenesis') <- getDefaultShelleyGenesis opts
cardanoTestnet opts conf startTime shelleyGenesis' alonzoGenesis conwayGenesis

{- | Spawn a resource managed privnet and do things with it (closing it in the end).
Privnet can be configured using "Cardano.Testnet.CardanoTestnetOptions". Pass 'cardanoDefaultTestnetOptions'
Expand Down Expand Up @@ -342,6 +335,13 @@ withPrivnet testnetOpts setupUser = do

let setup = Setup $ \targetSev putLog kont -> kont $ ctx { ctxLog = simpleLogging targetSev (putLog . Txt.unpack) }
setupUser setup
where
-- | This is defined same as `cardanoTestnetDefault` except we use our own conway genesis parameters.
cardanoTestnet' opts conf = do
Api.AnyCardanoEra cEra <- pure $ cardanoNodeEra cardanoDefaultTestnetOptions
alonzoGenesis <- getDefaultAlonzoGenesis cEra
(startTime, shelleyGenesis') <- getDefaultShelleyGenesis opts
cardanoTestnet opts conf startTime shelleyGenesis' alonzoGenesis conwayGenesis

-------------------------------------------------------------------------------
-- Generating users
Expand Down
2 changes: 1 addition & 1 deletion src/GeniusYield/TxBuilder/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ from its associated 'GYTxMonad' instance (such is the case for 'GYTxGameMonadIO'
make the same data type a 'GYTxMonad' and 'GYTxGameMonad'.
The former would not be possible if 'GYTxGameMonad' was subsumed into 'GYTxMonad', or if the 'TxMonadOf' type family
was not present. Thus, both the seperation and the type family are the result of a conscious design decision.
was not present. Thus, both the separation and the type family are the result of a conscious design decision.
It's important to allow the former case since it avoids making 'asUser' a higher order effect, unconditionally. Higher
order effects can be problematic. If, in the future, we are to use a proper effect system - we'd like to avoid having to
Expand Down
10 changes: 6 additions & 4 deletions src/GeniusYield/TxBuilder/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ module GeniusYield.TxBuilder.IO (
) where


import Control.Monad.Reader (ReaderT(ReaderT), MonadReader, asks)
import qualified Data.List.NonEmpty as NE
import Control.Monad.Reader (MonadReader,
ReaderT (ReaderT), asks)
import qualified Data.List.NonEmpty as NE

import GeniusYield.TxBuilder.Class
import GeniusYield.TxBuilder.Errors
import GeniusYield.TxBuilder.IO.Query
import GeniusYield.TxBuilder.IO.Builder
import GeniusYield.TxBuilder.IO.Query
import GeniusYield.TxBuilder.User
import GeniusYield.Types

Expand Down Expand Up @@ -127,7 +128,8 @@ data GYTxGameIOEnv = GYTxGameIOEnv
, envGameProviders :: !GYProviders
}

-- INTERNAL USAGE ONLY
-- | INTERNAL USAGE ONLY
--
-- Do not expose a 'MonadIO' instance. It allows the user to do arbitrary IO within the tx monad.
ioToTxGameMonad :: IO a -> GYTxGameMonadIO a
ioToTxGameMonad ioAct = GYTxGameMonadIO . const $ ioToQueryMonad ioAct
Expand Down
9 changes: 4 additions & 5 deletions src/GeniusYield/TxBuilder/IO/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ module GeniusYield.TxBuilder.IO.Builder (
) where


import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Reader (MonadReader, ReaderT (ReaderT),
asks)
import Control.Monad.Reader (MonadIO (liftIO), MonadReader,
ReaderT (ReaderT), asks)
import Control.Monad.Trans.Maybe (MaybeT (runMaybeT))
import qualified Data.Set as Set

Expand All @@ -43,7 +42,6 @@ newtype GYTxBuilderMonadIO a = GYTxBuilderMonadIO (GYTxBuilderIOEnv -> GYTxQuery
, MonadError GYTxMonadException
, GYTxQueryMonad
, GYTxSpecialQueryMonad
, MonadIO
)
via ReaderT GYTxBuilderIOEnv GYTxQueryMonadIO
deriving anyclass GYTxBuilderMonad
Expand All @@ -55,7 +53,8 @@ data GYTxBuilderIOEnv = GYTxBuilderIOEnv
, envUsedSomeUTxOs :: !(Set GYTxOutRef)
}

-- INTERNAL USAGE ONLY
-- | INTERNAL USAGE ONLY
--
-- Do not expose a 'MonadIO' instance. It allows the user to do arbitrary IO within the tx monad.
ioToTxBuilderMonad :: IO a -> GYTxBuilderMonadIO a
ioToTxBuilderMonad ioAct = GYTxBuilderMonadIO . const $ ioToQueryMonad ioAct
Expand Down
4 changes: 2 additions & 2 deletions src/GeniusYield/TxBuilder/IO/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ newtype GYTxQueryMonadIO a = GYTxQueryMonadIO { runGYTxQueryMonadIO' :: GYTxQuer
, Monad
, MonadReader GYTxQueryIOEnv
, MonadRandom
, MonadIO
)
via ReaderT GYTxQueryIOEnv IO

data GYTxQueryIOEnv = GYTxQueryIOEnv { envNid :: !GYNetworkId, envProviders :: !GYProviders}

-- INTERNAL USAGE ONLY
-- | INTERNAL USAGE ONLY
--
-- Do not expose a 'MonadIO' instance. It allows the user to do arbitrary IO within the tx monad.
ioToQueryMonad :: IO a -> GYTxQueryMonadIO a
ioToQueryMonad ioAct = GYTxQueryMonadIO $ const ioAct
Expand Down

0 comments on commit 3658eb7

Please sign in to comment.