Skip to content

Commit

Permalink
Extract common configuration out of Ogmios.Mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbfs committed Feb 5, 2025
1 parent fb55251 commit ea54320
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 53 deletions.
3 changes: 1 addition & 2 deletions src/Internal/Contract/Monad.purs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Ctl.Internal.Contract.ProviderBackend
)
import Ctl.Internal.Helpers (filterMapWithKeyM, liftM, logWithLevel)
import Ctl.Internal.Logging (Logger, mkLogger, setupLogs)
import Ctl.Internal.QueryM (QueryM)
import Ctl.Internal.QueryM (QueryEnv, QueryM)
import Ctl.Internal.QueryM.Kupo (isTxConfirmedAff)
import Ctl.Internal.QueryM.Ogmios (getProtocolParameters, getSystemStartTime)
import Ctl.Internal.QueryM.Ogmios.JsWebSocket (_wsClose, _wsFinalize)
Expand All @@ -64,7 +64,6 @@ import Ctl.Internal.QueryM.Ogmios.Mempool
, mkOgmiosWebSocketAff
, underlyingWebSocket
)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (QueryEnv)
import Ctl.Internal.QueryM.Ogmios.Types
( OgmiosDecodeError
, pprintOgmiosDecodeError
Expand Down
44 changes: 42 additions & 2 deletions src/Internal/QueryM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
-- | This module defines an Aff interface for backend queries.
module Ctl.Internal.QueryM
( QueryM
, QueryEnv
, QueryConfig
, ClusterSetup
, ParQueryM
, QueryMT(QueryMT)
, handleAffjaxResponse
Expand All @@ -16,6 +19,7 @@ import Cardano.Provider.Error
( ClientError(ClientHttpError, ClientHttpResponseError, ClientDecodeJsonError)
, ServiceError(ServiceOtherError)
)
import Cardano.Wallet.Key (PrivatePaymentKey, PrivateStakeKey)
import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Monad.Error.Class (class MonadError, class MonadThrow)
Expand All @@ -26,16 +30,52 @@ import Control.Monad.Rec.Class (class MonadRec)
import Control.Parallel (class Parallel, parallel, sequential)
import Control.Plus (class Plus)
import Ctl.Internal.Helpers (logWithLevel)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (QueryEnv)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (QueryRuntime)
import Ctl.Internal.ServerConfig (ServerConfig)
import Data.Bifunctor (lmap)
import Data.Either (Either(Left, Right))
import Data.Maybe (fromMaybe)
import Data.Log.Level (LogLevel)
import Data.Log.Message (Message)
import Data.Maybe (Maybe, fromMaybe)
import Data.Newtype (class Newtype, unwrap, wrap)
import Effect.Aff (Aff, ParAff)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect)
import Effect.Exception (Error)

-- | Cluster setup contains everything that is needed to run a `Contract` on
-- | a local cluster: paramters to connect to the services and private keys
-- | that are pre-funded with Ada on that cluster
type ClusterSetup =
{ ogmiosConfig :: ServerConfig
, kupoConfig :: ServerConfig
, keys ::
{ payment :: PrivatePaymentKey
, stake :: Maybe PrivateStakeKey
}
}

-- | `QueryConfig` contains a complete specification on how to initialize a
-- | `QueryM` environment.
-- | It includes:
-- | - server parameters for all the services
-- | - network ID
-- | - logging level
-- | - optional custom logger
type QueryConfig =
{ ogmiosConfig :: ServerConfig
, kupoConfig :: ServerConfig
, logLevel :: LogLevel
, customLogger :: Maybe (LogLevel -> Message -> Aff Unit)
, suppressLogs :: Boolean
}

-- | `QueryEnv` contains everything needed for `QueryM` to run.
type QueryEnv =
{ config :: QueryConfig
, runtime :: QueryRuntime
}

type QueryM = QueryMT Aff

type ParQueryM = QueryMT ParAff
Expand Down
46 changes: 1 addition & 45 deletions src/Internal/QueryM/Ogmios/QueryEnv.purs
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
module Ctl.Internal.QueryM.Ogmios.QueryEnv
( ClusterSetup
, QueryConfig
, QueryEnv
, QueryRuntime
( QueryRuntime
) where

import Prelude

import Cardano.Wallet.Key (PrivatePaymentKey, PrivateStakeKey)
import Ctl.Internal.QueryM.Ogmios.Mempool (OgmiosWebSocket)
import Ctl.Internal.ServerConfig (ServerConfig)
import Data.Log.Level (LogLevel)
import Data.Log.Message (Message)
import Data.Maybe (Maybe)
import Effect.Aff (Aff)

-- | Cluster setup contains everything that is needed to run a `Contract` on
-- | a local cluster: paramters to connect to the services and private keys
-- | that are pre-funded with Ada on that cluster
type ClusterSetup =
{ ogmiosConfig :: ServerConfig
, kupoConfig :: ServerConfig
, keys ::
{ payment :: PrivatePaymentKey
, stake :: Maybe PrivateStakeKey
}
}

-- | `QueryConfig` contains a complete specification on how to initialize a
-- | `QueryM` environment.
-- | It includes:
-- | - server parameters for all the services
-- | - network ID
-- | - logging level
-- | - optional custom logger
type QueryConfig =
{ ogmiosConfig :: ServerConfig
, kupoConfig :: ServerConfig
, logLevel :: LogLevel
, customLogger :: Maybe (LogLevel -> Message -> Aff Unit)
, suppressLogs :: Boolean
}

-- | Reusable part of `QueryRuntime` that can be shared between many `QueryM`
-- | instances running in parallel.
Expand All @@ -51,9 +13,3 @@ type QueryRuntime =
{ ogmiosWs :: OgmiosWebSocket
}

-- | `QueryEnv` contains everything needed for `QueryM` to run.
type QueryEnv =
{ config :: QueryConfig
, runtime :: QueryRuntime
}

2 changes: 1 addition & 1 deletion src/Internal/Test/E2E/Feedback/Browser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Prelude
import Aeson (decodeAeson, encodeAeson, jsonToAeson, stringifyAeson)
import Ctl.Internal.FfiHelpers (MaybeFfiHelper, maybeFfiHelper)
import Ctl.Internal.Helpers (liftedM)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (ClusterSetup)
import Ctl.Internal.QueryM (ClusterSetup)
import Ctl.Internal.Test.E2E.Feedback (BrowserEvent)
import Data.Argonaut (Json)
import Data.Either (hush)
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Test/E2E/Feedback/Node.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Prelude

import Aeson (decodeAeson, encodeAeson, parseJsonStringToAeson, stringifyAeson)
import Ctl.Internal.Helpers (liftEither)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (ClusterSetup)
import Ctl.Internal.QueryM (ClusterSetup)
import Ctl.Internal.Test.E2E.Feedback (BrowserEvent(Failure, Success))
import Data.Array as Array
import Data.Either (Either(Left), hush, note)
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Test/E2E/Route.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Control.Alt ((<|>))
import Control.Monad.Error.Class (liftMaybe)
import Ctl.Internal.Contract.ProviderBackend (mkCtlBackendParams)
import Ctl.Internal.Helpers (liftEither)
import Ctl.Internal.QueryM.Ogmios.QueryEnv (ClusterSetup)
import Ctl.Internal.QueryM (ClusterSetup)
import Ctl.Internal.Test.E2E.Feedback.Browser (getClusterSetupRepeatedly)
import Ctl.Internal.Test.E2E.Feedback.Hooks (addE2EFeedbackHooks)
import Ctl.Internal.Wallet.Spec (WalletSpec(ConnectToGenericCip30))
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Test/E2E/Runner.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Ctl.Internal.Affjax (request) as Affjax
import Ctl.Internal.Contract.Hooks (emptyHooks)
import Ctl.Internal.Contract.ProviderBackend (ProviderBackend(CtlBackend))
import Ctl.Internal.Helpers (liftedM, unsafeFromJust, (<</>>))
import Ctl.Internal.QueryM.Ogmios.QueryEnv (ClusterSetup)
import Ctl.Internal.QueryM (ClusterSetup)
import Ctl.Internal.Test.E2E.Browser (withBrowser)
import Ctl.Internal.Test.E2E.Feedback
( BrowserEvent(ConfirmAccess, Sign, Success, Failure)
Expand Down

0 comments on commit ea54320

Please sign in to comment.