{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE DerivingStrategies    #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns        #-}
{-# LANGUAGE NumericUnderscores    #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RankNTypes            #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE StrictData            #-}
{-# LANGUAGE TypeApplications      #-}
{-# LANGUAGE TypeOperators         #-}

{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}

module Plutus.PAB.App(
    App,
    runApp,
    AppEnv(..),
    StorageBackend(..),
    -- * App actions
    migrate,
    dbConnect,
    handleContractDefinition
    ) where

import Cardano.Api.NetworkId.Extra (NetworkIdWrapper (unNetworkIdWrapper))
import Cardano.BM.Trace (Trace, logDebug)
import Cardano.ChainIndex.Types qualified as ChainIndex
import Cardano.Node.Client (handleNodeClientClient, runChainSyncWithCfg)
import Cardano.Node.Params qualified as Params
import Cardano.Node.Types (ChainSyncHandle, NodeMode (MockNode),
                           PABServerConfig (PABServerConfig, pscBaseUrl, pscNetworkId, pscNodeMode, pscSocketPath))
import Cardano.Protocol.Socket.Mock.Client qualified as MockClient
import Cardano.Wallet.LocalClient qualified as LocalWalletClient
import Cardano.Wallet.Mock.Client qualified as WalletMockClient
import Cardano.Wallet.RemoteClient qualified as RemoteWalletClient
import Cardano.Wallet.Types qualified as Wallet
import Control.Lens (preview, (^?!))
import Control.Monad (void)
import Control.Monad.Freer (Eff, LastMember, Member, interpret, reinterpret, reinterpret2, reinterpretN, type (~>))
import Control.Monad.Freer.Error (Error, handleError, throwError)
import Control.Monad.Freer.Extras.Beam.Effects (handleBeam)
import Control.Monad.Freer.Extras.Beam.Postgres qualified as Postgres (DbConfig (..), runBeam)
import Control.Monad.Freer.Extras.Beam.Sqlite qualified as Sqlite (DbConfig (..), runBeam)
import Control.Monad.Freer.Extras.Log (LogMsg, mapLog)
import Control.Monad.Freer.Reader (Reader, ask, runReader)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Aeson (FromJSON, ToJSON)
import Data.Coerce (coerce)
import Data.Pool (Pool)
import Data.Pool qualified as Pool
import Data.Text (Text, pack, unpack)
import Data.Typeable (Typeable)
import Database.Beam.Migrate.Simple (autoMigrate)
import Database.Beam.Postgres qualified as Postgres
import Database.Beam.Postgres.Migrate qualified as Postgres
import Database.Beam.Sqlite qualified as Sqlite
import Database.Beam.Sqlite.Migrate qualified as Sqlite
import Database.SQLite.Simple qualified as Sqlite
import Network.HTTP.Client (ManagerSettings (managerResponseTimeout), managerModifyRequest, newManager,
                            responseTimeoutMicro, setRequestIgnoreStatus)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Plutus.ChainIndex.Client qualified as ChainIndex
import Plutus.PAB.Core (EffectHandlers (EffectHandlers), PABAction)
import Plutus.PAB.Core qualified as Core
import Plutus.PAB.Core.ContractInstance.BlockchainEnv qualified as BlockchainEnv
import Plutus.PAB.Core.ContractInstance.STM as Instances (InstancesState, emptyInstancesState)
import Plutus.PAB.Db.Beam.ContractStore qualified as BeamEff
import Plutus.PAB.Db.Memory.ContractStore (InMemInstances, initialInMemInstances)
import Plutus.PAB.Db.Memory.ContractStore qualified as InMem
import Plutus.PAB.Db.Schema (checkedPostgresDb, checkedSqliteDb)
import Plutus.PAB.Effects.Contract (ContractDefinition (AddDefinition, GetDefinitions))
import Plutus.PAB.Effects.Contract.Builtin (Builtin, BuiltinHandler (BuiltinHandler, contractHandler),
                                            HasDefinitions (getDefinitions))
import Plutus.PAB.Monitoring.Monitoring (convertLog, handleLogMsgTrace)
import Plutus.PAB.Monitoring.PABLogMsg (PABLogMsg (SMultiAgent), PABMultiAgentMsg (BeamLogItem, UserLog, WalletClient),
                                        WalletClientMsg)
import Plutus.PAB.Timeout (Timeout (Timeout))
import Plutus.PAB.Types (ChainQueryConfig (..), ChainQueryEnv (..), Config (Config), DBConnection (..), DbConfig (..),
                         PABError (BeamEffectError, ChainIndexError, NodeClientError, RemoteWalletWithMockNodeError, WalletClientError, WalletError),
                         WebserverConfig (WebserverConfig), _PostgresPool, _SqlitePool, chainQueryConfig, dbConfig,
                         endpointTimeout, getBlockfrostEnv, getChainIndexEnv, nodeServerConfig, pabWebserverConfig,
                         waitStatusTimeout, walletServerConfig)
import Servant.Client (ClientEnv, ClientError, mkClientEnv)
import Wallet.API (NodeClientEffect)
import Wallet.Effects (WalletEffect)
import Wallet.Emulator.Wallet (Wallet)
import Wallet.Error (WalletAPIError)
import Wallet.Types (ContractInstanceId)

import Database.Beam.Postgres (Postgres)
import Database.Beam.Sqlite (Sqlite)
import Plutus.Blockfrost.Client as BlockfrostClient
import Plutus.Blockfrost.Types qualified as BF (BlockfrostConfig (bfTokenPath), BlockfrostEnv (..))

------------------------------------------------------------

-- | Application environment with a contract type `a`.
data AppEnv a =
    AppEnv
        { AppEnv a -> DBConnection
dbPool                :: DBConnection
        , AppEnv a -> Maybe ClientEnv
walletClientEnv       :: Maybe ClientEnv -- ^ No 'ClientEnv' when in the remote client setting.
        , AppEnv a -> ClientEnv
nodeClientEnv         :: ClientEnv
        , AppEnv a -> ChainQueryEnv
chainQueryEnv         :: ChainQueryEnv
        , AppEnv a -> Maybe TxSendHandle
txSendHandle          :: Maybe MockClient.TxSendHandle -- No 'TxSendHandle' required when connecting to the real node.
        , AppEnv a -> ChainSyncHandle
chainSyncHandle       :: ChainSyncHandle
        , AppEnv a -> Config
appConfig             :: Config
        , AppEnv a -> Trace IO (PABLogMsg (Builtin a))
appTrace              :: Trace IO (PABLogMsg (Builtin a))
        , AppEnv a -> InMemInstances (Builtin a)
appInMemContractStore :: InMemInstances (Builtin a)
        }

appEffectHandlers
  :: forall a.
  ( FromJSON a
  , ToJSON a
  , HasDefinitions a
  , Typeable a
  )
  => StorageBackend
  -> Config
  -> Trace IO (PABLogMsg (Builtin a))
  -> BuiltinHandler a
  -> EffectHandlers (Builtin a) (AppEnv a)
appEffectHandlers :: StorageBackend
-> Config
-> Trace IO (PABLogMsg (Builtin a))
-> BuiltinHandler a
-> EffectHandlers (Builtin a) (AppEnv a)
appEffectHandlers StorageBackend
storageBackend Config
config Trace IO (PABLogMsg (Builtin a))
trace BuiltinHandler{forall (effs :: [* -> *]).
(Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs) =>
ContractEffect (Builtin a) ~> Eff effs
contractHandler :: forall (effs :: [* -> *]).
(Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs) =>
ContractEffect (Builtin a) ~> Eff effs
contractHandler :: forall a.
BuiltinHandler a
-> forall (effs :: [* -> *]).
   (Member (Error PABError) effs,
    Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs) =>
   ContractEffect (Builtin a) ~> Eff effs
contractHandler} =
    EffectHandlers :: forall t env.
(forall (effs :: [* -> *]).
 (Member (Error PABError) effs, LastMember IO effs) =>
 Eff effs (InstancesState, BlockchainEnv, env))
-> (forall (effs :: [* -> *]).
    (Member (Reader (PABEnvironment t env)) effs,
     Member TimeEffect effs, Member (Error PABError) effs,
     LastMember IO effs) =>
    Eff (LogMsg (PABMultiAgentMsg t) : effs) ~> Eff effs)
-> (forall (effs :: [* -> *]).
    (Member (Reader (PABEnvironment t env)) effs,
     Member (Error PABError) effs, Member TimeEffect effs,
     Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) =>
    Eff (ContractStore t : effs) ~> Eff effs)
-> (forall (effs :: [* -> *]).
    (Member (Reader (PABEnvironment t env)) effs,
     Member (Error PABError) effs, Member TimeEffect effs,
     Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) =>
    Eff (ContractEffect t : effs) ~> Eff effs)
-> (forall (effs :: [* -> *]).
    (Member (Reader (PABEnvironment t env)) effs,
     Member (Error PABError) effs, Member TimeEffect effs,
     Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) =>
    Eff (ContractDefinition t : effs) ~> Eff effs)
-> (forall (effs :: [* -> *]).
    (Member (Reader (PABEnvironment t env)) effs,
     Member (Error PABError) effs, Member TimeEffect effs,
     Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) =>
    Wallet
    -> Maybe ContractInstanceId
    -> Eff
         (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs)
       ~> Eff effs)
-> PABAction t env ()
-> PABAction t env ()
-> EffectHandlers t env
EffectHandlers
        { initialiseEnvironment :: forall (effs :: [* -> *]).
(Member (Error PABError) effs, LastMember IO effs) =>
Eff effs (InstancesState, BlockchainEnv, AppEnv a)
initialiseEnvironment = do
            AppEnv a
env <- IO (AppEnv a) -> Eff effs (AppEnv a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (AppEnv a) -> Eff effs (AppEnv a))
-> IO (AppEnv a) -> Eff effs (AppEnv a)
forall a b. (a -> b) -> a -> b
$ Trace IO (PABLogMsg (Builtin a)) -> Config -> IO (AppEnv a)
forall a.
Trace IO (PABLogMsg (Builtin a)) -> Config -> IO (AppEnv a)
mkEnv Trace IO (PABLogMsg (Builtin a))
trace Config
config
            InstancesState
instancesState <- IO InstancesState -> Eff effs InstancesState
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO InstancesState
Instances.emptyInstancesState
            BlockchainEnv
blockchainEnv <- IO BlockchainEnv -> Eff effs BlockchainEnv
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO BlockchainEnv -> Eff effs BlockchainEnv)
-> IO BlockchainEnv -> Eff effs BlockchainEnv
forall a b. (a -> b) -> a -> b
$ Config -> InstancesState -> IO BlockchainEnv
BlockchainEnv.startNodeClient Config
config InstancesState
instancesState
            (InstancesState, BlockchainEnv, AppEnv a)
-> Eff effs (InstancesState, BlockchainEnv, AppEnv a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InstancesState
instancesState, BlockchainEnv
blockchainEnv, AppEnv a
env)

        , handleLogMessages :: forall (effs :: [* -> *]).
(Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs,
 Member TimeEffect effs, Member (Error PABError) effs,
 LastMember IO effs) =>
Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) ~> Eff effs
handleLogMessages =
            (LogMsg (PABLogMsg (Builtin a)) ~> Eff effs)
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (Trace IO (PABLogMsg (Builtin a))
-> LogMsg (PABLogMsg (Builtin a)) ~> Eff effs
forall a (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m) =>
Trace m a -> LogMsg a ~> Eff effs
handleLogMsgTrace Trace IO (PABLogMsg (Builtin a))
trace)
            (Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x -> Eff effs x)
-> (Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
    -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg (PABMultiAgentMsg (Builtin a))
 ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs))
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> LogMsg (PABMultiAgentMsg (Builtin a))
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall a b (effs :: [* -> *]).
Member (LogMsg b) effs =>
(a -> b) -> LogMsg a ~> Eff effs
mapLog PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent)

        , handleContractEffect :: forall (effs :: [* -> *]).
(Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs,
 Member (Error PABError) effs, Member TimeEffect effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs,
 LastMember IO effs) =>
Eff (ContractEffect (Builtin a) : effs) ~> Eff effs
handleContractEffect =
            (LogMsg (PABLogMsg (Builtin a)) ~> Eff effs)
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (Trace IO (PABLogMsg (Builtin a))
-> LogMsg (PABLogMsg (Builtin a)) ~> Eff effs
forall a (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m) =>
Trace m a -> LogMsg a ~> Eff effs
handleLogMsgTrace Trace IO (PABLogMsg (Builtin a))
trace)
            (Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x -> Eff effs x)
-> (Eff (ContractEffect (Builtin a) : effs) x
    -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> Eff (ContractEffect (Builtin a) : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractEffect (Builtin a)
 ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs))
-> Eff (ContractEffect (Builtin a) : effs)
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret forall (effs :: [* -> *]).
(Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs) =>
ContractEffect (Builtin a) ~> Eff effs
ContractEffect (Builtin a)
~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
contractHandler

        , handleContractStoreEffect :: forall (effs :: [* -> *]).
(Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs,
 Member (Error PABError) effs, Member TimeEffect effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs,
 LastMember IO effs) =>
Eff (ContractStore (Builtin a) : effs) ~> Eff effs
handleContractStoreEffect =
          case StorageBackend
storageBackend of
            StorageBackend
InMemoryBackend ->
              (Reader (AppEnv a) ~> Eff effs)
-> Eff (Reader (AppEnv a) : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
              (Eff (Reader (AppEnv a) : effs) x -> Eff effs x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff (Reader (AppEnv a) : effs) x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (InMemInstances (Builtin a))
 ~> Eff (Reader (AppEnv a) : effs))
-> Eff
     (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs)
   ~> Eff (Reader (AppEnv a) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((AppEnv a -> InMemInstances (Builtin a))
-> Reader (InMemInstances (Builtin a))
   ~> Eff (Reader (AppEnv a) : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) AppEnv a -> InMemInstances (Builtin a)
forall a. AppEnv a -> InMemInstances (Builtin a)
appInMemContractStore)
              (Eff
   (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs) x
 -> Eff (Reader (AppEnv a) : effs) x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs) x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff (Reader (AppEnv a) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractStore (Builtin a)
 ~> Eff
      (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs))
-> Eff (ContractStore (Builtin a) : effs)
   ~> Eff
        (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *)
       (effs :: [* -> *]).
(f ~> Eff (g : h : effs)) -> Eff (f : effs) ~> Eff (g : h : effs)
reinterpret2 ContractStore (Builtin a)
~> Eff
     (Reader (InMemInstances (Builtin a)) : Reader (AppEnv a) : effs)
forall t (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (InMemInstances t)) effs,
 Member (Error PABError) effs) =>
ContractStore t ~> Eff effs
InMem.handleContractStore

            StorageBackend
BeamBackend ->
              (LogMsg (PABLogMsg (Builtin a)) ~> Eff effs)
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (Trace IO (PABLogMsg (Builtin a))
-> LogMsg (PABLogMsg (Builtin a)) ~> Eff effs
forall a (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m) =>
Trace m a -> LogMsg a ~> Eff effs
handleLogMsgTrace Trace IO (PABLogMsg (Builtin a))
trace)
              (Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x -> Eff effs x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg (PABMultiAgentMsg (Builtin a))
 ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs))
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> LogMsg (PABMultiAgentMsg (Builtin a))
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall a b (effs :: [* -> *]).
Member (LogMsg b) effs =>
(a -> b) -> LogMsg a ~> Eff effs
mapLog @_ @(PABLogMsg (Builtin a)) PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent)
              (Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff
   (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> (BeamError
     -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
 -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (BeamError
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff
     (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff
  (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
-> (BeamError
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (BeamError -> PABError)
-> BeamError
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamError -> PABError
BeamEffectError)
              (Eff
   (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
              (Eff
   (Reader (AppEnv a)
      : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff
     (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. case Config -> DbConfig
dbConfig Config
config of
                    SqliteDB DbConfig
_ ->
                          (Reader (Pool Connection)
 ~> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((AppEnv a -> Pool Connection)
-> Reader (Pool Connection)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) ((DBConnection
-> Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
-> Pool Connection
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
Prism' DBConnection (Pool Connection)
_SqlitePool) (DBConnection -> Pool Connection)
-> (AppEnv a -> DBConnection) -> AppEnv a -> Pool Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> DBConnection
forall a. AppEnv a -> DBConnection
dbPool))
                        (Eff
   (Reader (Pool Connection)
      : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BeamEffect Sqlite
 ~> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (BeamEffect Sqlite
        : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((Trace IO BeamLog
 -> SqliteM
    ~> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Trace IO BeamLog
-> BeamEffect Sqlite
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> SqliteM
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> SqliteM ~> Eff effs
Sqlite.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
                        (Eff
   (BeamEffect Sqlite
      : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (BeamEffect Sqlite
            : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractStore (Builtin a)
 ~> Eff
      ('[BeamEffect Sqlite, Reader (Pool Connection), Reader (AppEnv a),
         Error BeamError, LogMsg (PABMultiAgentMsg (Builtin a))]
       :++: effs))
-> Eff (ContractStore (Builtin a) : effs)
   ~> Eff
        ('[BeamEffect Sqlite, Reader (Pool Connection), Reader (AppEnv a),
           Error BeamError, LogMsg (PABMultiAgentMsg (Builtin a))]
         :++: effs)
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _, _] (forall a (effs :: [* -> *]).
(FromBackendRow Sqlite Text, FromBackendRow Sqlite Bool,
 FromBackendRow Sqlite SqlNull,
 HasSqlValueSyntax (Synt Sqlite) (Maybe Text),
 HasSqlValueSyntax (Synt Sqlite) Text,
 HasSqlValueSyntax (Synt Sqlite) Bool,
 HasSqlEqualityCheck Sqlite Text, HasSqlEqualityCheck Sqlite Bool,
 HasQBuilder Sqlite, Member (BeamEffect Sqlite) effs,
 Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
forall dbt a (effs :: [* -> *]).
(FromBackendRow dbt Text, FromBackendRow dbt Bool,
 FromBackendRow dbt SqlNull,
 HasSqlValueSyntax (Synt dbt) (Maybe Text),
 HasSqlValueSyntax (Synt dbt) Text,
 HasSqlValueSyntax (Synt dbt) Bool, HasSqlEqualityCheck dbt Text,
 HasSqlEqualityCheck dbt Bool, HasQBuilder dbt,
 Member (BeamEffect dbt) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
BeamEff.handleContractStore @Sqlite)
                    PostgresDB DbConfig
_ ->
                          (Reader (Pool Connection)
 ~> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((AppEnv a -> Pool Connection)
-> Reader (Pool Connection)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) ((DBConnection
-> Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
-> Pool Connection
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
Prism' DBConnection (Pool Connection)
_PostgresPool) (DBConnection -> Pool Connection)
-> (AppEnv a -> DBConnection) -> AppEnv a -> Pool Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> DBConnection
forall a. AppEnv a -> DBConnection
dbPool))
                        (Eff
   (Reader (Pool Connection)
      : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BeamEffect Postgres
 ~> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (BeamEffect Postgres
        : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((Trace IO BeamLog
 -> Pg
    ~> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Trace IO BeamLog
-> BeamEffect Postgres
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> Pg
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> Pg ~> Eff effs
Postgres.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
                        (Eff
   (BeamEffect Postgres
      : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractStore (Builtin a) : effs) x
    -> Eff
         (BeamEffect Postgres
            : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractStore (Builtin a) : effs) x
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractStore (Builtin a)
 ~> Eff
      ('[BeamEffect Postgres, Reader (Pool Connection),
         Reader (AppEnv a), Error BeamError,
         LogMsg (PABMultiAgentMsg (Builtin a))]
       :++: effs))
-> Eff (ContractStore (Builtin a) : effs)
   ~> Eff
        ('[BeamEffect Postgres, Reader (Pool Connection),
           Reader (AppEnv a), Error BeamError,
           LogMsg (PABMultiAgentMsg (Builtin a))]
         :++: effs)
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _, _] (forall a (effs :: [* -> *]).
(FromBackendRow Postgres Text, FromBackendRow Postgres Bool,
 FromBackendRow Postgres SqlNull,
 HasSqlValueSyntax (Synt Postgres) (Maybe Text),
 HasSqlValueSyntax (Synt Postgres) Text,
 HasSqlValueSyntax (Synt Postgres) Bool,
 HasSqlEqualityCheck Postgres Text,
 HasSqlEqualityCheck Postgres Bool, HasQBuilder Postgres,
 Member (BeamEffect Postgres) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
forall dbt a (effs :: [* -> *]).
(FromBackendRow dbt Text, FromBackendRow dbt Bool,
 FromBackendRow dbt SqlNull,
 HasSqlValueSyntax (Synt dbt) (Maybe Text),
 HasSqlValueSyntax (Synt dbt) Text,
 HasSqlValueSyntax (Synt dbt) Bool, HasSqlEqualityCheck dbt Text,
 HasSqlEqualityCheck dbt Bool, HasQBuilder dbt,
 Member (BeamEffect dbt) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
BeamEff.handleContractStore @Postgres)

        , handleContractDefinitionEffect :: forall (effs :: [* -> *]).
(Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs,
 Member (Error PABError) effs, Member TimeEffect effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs,
 LastMember IO effs) =>
Eff (ContractDefinition (Builtin a) : effs) ~> Eff effs
handleContractDefinitionEffect =
            (LogMsg (PABLogMsg (Builtin a)) ~> Eff effs)
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (Trace IO (PABLogMsg (Builtin a))
-> LogMsg (PABLogMsg (Builtin a)) ~> Eff effs
forall a (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m) =>
Trace m a -> LogMsg a ~> Eff effs
handleLogMsgTrace Trace IO (PABLogMsg (Builtin a))
trace)
            (Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x -> Eff effs x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg (PABMultiAgentMsg (Builtin a))
 ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs))
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> LogMsg (PABMultiAgentMsg (Builtin a))
   ~> Eff (LogMsg (PABLogMsg (Builtin a)) : effs)
forall a b (effs :: [* -> *]).
Member (LogMsg b) effs =>
(a -> b) -> LogMsg a ~> Eff effs
mapLog @_ @(PABLogMsg (Builtin a)) PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent)
            (Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff (LogMsg (PABLogMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff
   (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> (BeamError
     -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
 -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (BeamError
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff
     (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff
  (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
-> (BeamError
    -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (BeamError -> PABError)
-> BeamError
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamError -> PABError
BeamEffectError)
            (Eff
   (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
 -> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff (LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. case Config -> DbConfig
dbConfig Config
config of
                  SqliteDB DbConfig
_ -> (Reader (AppEnv a)
 ~> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
                                (Eff
   (Reader (AppEnv a)
      : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (Pool Connection)
 ~> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((AppEnv a -> Pool Connection)
-> Reader (Pool Connection)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) ((DBConnection
-> Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
-> Pool Connection
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
Prism' DBConnection (Pool Connection)
_SqlitePool) (DBConnection -> Pool Connection)
-> (AppEnv a -> DBConnection) -> AppEnv a -> Pool Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> DBConnection
forall a. AppEnv a -> DBConnection
dbPool))
                                (Eff
   (Reader (Pool Connection)
      : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BeamEffect Sqlite
 ~> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (BeamEffect Sqlite
        : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((Trace IO BeamLog
 -> SqliteM
    ~> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Trace IO BeamLog
-> BeamEffect Sqlite
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> SqliteM
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> SqliteM ~> Eff effs
Sqlite.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
                                (Eff
   (BeamEffect Sqlite
      : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (BeamEffect Sqlite
            : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractDefinition (Builtin a)
 ~> Eff
      ('[BeamEffect Sqlite, Reader (Pool Connection), Reader (AppEnv a),
         Error BeamError, LogMsg (PABMultiAgentMsg (Builtin a))]
       :++: effs))
-> Eff (ContractDefinition (Builtin a) : effs)
   ~> Eff
        ('[BeamEffect Sqlite, Reader (Pool Connection), Reader (AppEnv a),
           Error BeamError, LogMsg (PABMultiAgentMsg (Builtin a))]
         :++: effs)
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _, _ ] ContractDefinition (Builtin a)
~> Eff
     ('[BeamEffect Sqlite, Reader (Pool Connection), Reader (AppEnv a),
        Error BeamError, LogMsg (PABMultiAgentMsg (Builtin a))]
      :++: effs)
forall a (effs :: [* -> *]).
HasDefinitions a =>
ContractDefinition (Builtin a) ~> Eff effs
handleContractDefinition
                  PostgresDB DbConfig
_ -> (Reader (AppEnv a)
 ~> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
                                (Eff
   (Reader (AppEnv a)
      : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (Pool Connection)
 ~> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((AppEnv a -> Pool Connection)
-> Reader (Pool Connection)
   ~> Eff
        (Reader (AppEnv a)
           : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) ((DBConnection
-> Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
-> Pool Connection
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!Getting (Endo (Pool Connection)) DBConnection (Pool Connection)
Prism' DBConnection (Pool Connection)
_PostgresPool) (DBConnection -> Pool Connection)
-> (AppEnv a -> DBConnection) -> AppEnv a -> Pool Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> DBConnection
forall a. AppEnv a -> DBConnection
dbPool))
                                (Eff
   (Reader (Pool Connection)
      : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Reader (AppEnv a)
        : Error BeamError : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BeamEffect Postgres
 ~> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Eff
     (BeamEffect Postgres
        : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((Trace IO BeamLog
 -> Pg
    ~> Eff
         (Reader (Pool Connection)
            : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs))
-> Trace IO BeamLog
-> BeamEffect Postgres
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> Pg
   ~> Eff
        (Reader (Pool Connection)
           : Reader (AppEnv a) : Error BeamError
           : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> Pg ~> Eff effs
Postgres.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
                                (Eff
   (BeamEffect Postgres
      : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
      : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
   x
 -> Eff
      (Reader (Pool Connection)
         : Reader (AppEnv a) : Error BeamError
         : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
      x)
-> (Eff (ContractDefinition (Builtin a) : effs) x
    -> Eff
         (BeamEffect Postgres
            : Reader (Pool Connection) : Reader (AppEnv a) : Error BeamError
            : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
         x)
-> Eff (ContractDefinition (Builtin a) : effs) x
-> Eff
     (Reader (Pool Connection)
        : Reader (AppEnv a) : Error BeamError
        : LogMsg (PABMultiAgentMsg (Builtin a)) : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractDefinition (Builtin a)
 ~> Eff
      ('[BeamEffect Postgres, Reader (Pool Connection),
         Reader (AppEnv a), Error BeamError,
         LogMsg (PABMultiAgentMsg (Builtin a))]
       :++: effs))
-> Eff (ContractDefinition (Builtin a) : effs)
   ~> Eff
        ('[BeamEffect Postgres, Reader (Pool Connection),
           Reader (AppEnv a), Error BeamError,
           LogMsg (PABMultiAgentMsg (Builtin a))]
         :++: effs)
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _, _] ContractDefinition (Builtin a)
~> Eff
     ('[BeamEffect Postgres, Reader (Pool Connection),
        Reader (AppEnv a), Error BeamError,
        LogMsg (PABMultiAgentMsg (Builtin a))]
      :++: effs)
forall a (effs :: [* -> *]).
HasDefinitions a =>
ContractDefinition (Builtin a) ~> Eff effs
handleContractDefinition

        , handleServicesEffects :: forall (effs :: [* -> *]).
(Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs,
 Member (Error PABError) effs, Member TimeEffect effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs,
 LastMember IO effs) =>
Wallet
-> Maybe ContractInstanceId
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff effs
handleServicesEffects = \Wallet
wallet Maybe ContractInstanceId
cidM -> do
            -- handle 'NodeClientEffect'
            (Eff (Error ClientError : effs) x
 -> (ClientError -> Eff effs x) -> Eff effs x)
-> (ClientError -> Eff effs x)
-> Eff (Error ClientError : effs) x
-> Eff effs x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff (Error ClientError : effs) x
-> (ClientError -> Eff effs x) -> Eff effs x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff effs x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError -> Eff effs x)
-> (ClientError -> PABError) -> ClientError -> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientError -> PABError
NodeClientError)
            (Eff (Error ClientError : effs) x -> Eff effs x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (Error ClientError : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff effs x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a) ~> Eff (Error ClientError : effs))
-> Eff (Reader (AppEnv a) : Error ClientError : effs)
   ~> Eff (Error ClientError : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff (Reader (AppEnv a) : Error ClientError : effs) x
 -> Eff (Error ClientError : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (Reader (AppEnv a) : Error ClientError : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (Error ClientError : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader ChainSyncHandle
 ~> Eff (Reader (AppEnv a) : Error ClientError : effs))
-> Eff (Reader ChainSyncHandle : Error ClientError : effs)
   ~> Eff (Reader (AppEnv a) : Error ClientError : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> ChainSyncHandle)
-> Reader ChainSyncHandle
   ~> Eff (Reader (AppEnv a) : Error ClientError : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @ChainSyncHandle AppEnv a -> ChainSyncHandle
forall a. AppEnv a -> ChainSyncHandle
chainSyncHandle)
            (Eff (Reader ChainSyncHandle : Error ClientError : effs) x
 -> Eff (Reader (AppEnv a) : Error ClientError : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (Reader ChainSyncHandle : Error ClientError : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (Reader (AppEnv a) : Error ClientError : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff (Reader ChainSyncHandle : Error ClientError : effs))
-> Eff
     (Reader (AppEnv a)
        : Reader ChainSyncHandle : Error ClientError : effs)
   ~> Eff (Reader ChainSyncHandle : Error ClientError : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader (AppEnv a)
      : Reader ChainSyncHandle : Error ClientError : effs)
   x
 -> Eff (Reader ChainSyncHandle : Error ClientError : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Reader ChainSyncHandle : Error ClientError : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (Reader ChainSyncHandle : Error ClientError : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (Maybe TxSendHandle)
 ~> Eff
      (Reader (AppEnv a)
         : Reader ChainSyncHandle : Error ClientError : effs))
-> Eff
     (Reader (Maybe TxSendHandle)
        : Reader ChainSyncHandle : Error ClientError : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Reader ChainSyncHandle : Error ClientError : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> Maybe TxSendHandle)
-> Reader (Maybe TxSendHandle)
   ~> Eff
        (Reader (AppEnv a)
           : Reader ChainSyncHandle : Error ClientError : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @(Maybe MockClient.TxSendHandle) AppEnv a -> Maybe TxSendHandle
forall a. AppEnv a -> Maybe TxSendHandle
txSendHandle)
            (Eff
   (Reader (Maybe TxSendHandle)
      : Reader ChainSyncHandle : Error ClientError : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Reader ChainSyncHandle : Error ClientError : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (Maybe TxSendHandle)
            : Reader ChainSyncHandle : Error ClientError : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a)
        : Reader ChainSyncHandle : Error ClientError : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff
      (Reader (Maybe TxSendHandle)
         : Reader ChainSyncHandle : Error ClientError : effs))
-> Eff
     (Reader (AppEnv a)
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
   ~> Eff
        (Reader (Maybe TxSendHandle)
           : Reader ChainSyncHandle : Error ClientError : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader (AppEnv a)
      : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
      : Error ClientError : effs)
   x
 -> Eff
      (Reader (Maybe TxSendHandle)
         : Reader ChainSyncHandle : Error ClientError : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
            : Error ClientError : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (Maybe TxSendHandle)
        : Reader ChainSyncHandle : Error ClientError : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader ClientEnv
 ~> Eff
      (Reader (AppEnv a)
         : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
         : Error ClientError : effs))
-> Eff
     (Reader ClientEnv
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
           : Error ClientError : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> ClientEnv)
-> Reader ClientEnv
   ~> Eff
        (Reader (AppEnv a)
           : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
           : Error ClientError : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @ClientEnv AppEnv a -> ClientEnv
forall a. AppEnv a -> ClientEnv
nodeClientEnv)
            (Eff
   (Reader ClientEnv
      : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
      : Error ClientError : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
         : Error ClientError : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader ClientEnv
            : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
            : Error ClientError : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a)
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NodeClientEffect
 ~> Eff
      ('[Reader ClientEnv, Reader (Maybe TxSendHandle),
         Reader ChainSyncHandle, Error ClientError]
       :++: effs))
-> Eff (NodeClientEffect : effs)
   ~> Eff
        ('[Reader ClientEnv, Reader (Maybe TxSendHandle),
           Reader ChainSyncHandle, Error ClientError]
         :++: effs)
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _]
              (\NodeClientEffect x
nodeClientEffect -> do
                Params
params <- IO Params
-> Eff
     (Reader ClientEnv
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
     Params
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Params
 -> Eff
      (Reader ClientEnv
         : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
         : Error ClientError : effs)
      Params)
-> IO Params
-> Eff
     (Reader ClientEnv
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
     Params
forall a b. (a -> b) -> a -> b
$ PABServerConfig -> IO Params
Params.fromPABServerConfig (PABServerConfig -> IO Params) -> PABServerConfig -> IO Params
forall a b. (a -> b) -> a -> b
$ Config -> PABServerConfig
nodeServerConfig Config
config
                Params
-> NodeClientEffect x
-> Eff
     (Reader ClientEnv
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
     x
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m, Member (Error PABError) effs,
 Member (Reader (Maybe TxSendHandle)) effs,
 Member (Reader ChainSyncHandle) effs) =>
Params -> NodeClientEffect ~> Eff effs
handleNodeClientClient @IO Params
params NodeClientEffect x
nodeClientEffect)

            -- handle 'ChainIndexEffect'
            (Eff (NodeClientEffect : effs) x
 -> Eff
      (Reader ClientEnv
         : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
         : Error ClientError : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (NodeClientEffect : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader ClientEnv
        : Reader (Maybe TxSendHandle) : Reader ChainSyncHandle
        : Error ClientError : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff (Error ClientError : NodeClientEffect : effs) x
 -> (ClientError -> Eff (NodeClientEffect : effs) x)
 -> Eff (NodeClientEffect : effs) x)
-> (ClientError -> Eff (NodeClientEffect : effs) x)
-> Eff (Error ClientError : NodeClientEffect : effs) x
-> Eff (NodeClientEffect : effs) x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff (Error ClientError : NodeClientEffect : effs) x
-> (ClientError -> Eff (NodeClientEffect : effs) x)
-> Eff (NodeClientEffect : effs) x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff (NodeClientEffect : effs) x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError -> Eff (NodeClientEffect : effs) x)
-> (ClientError -> PABError)
-> ClientError
-> Eff (NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientError -> PABError
ChainIndexError)
            (Eff (Error ClientError : NodeClientEffect : effs) x
 -> Eff (NodeClientEffect : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (Error ClientError : NodeClientEffect : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff (Error ClientError : NodeClientEffect : effs))
-> Eff
     (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
   ~> Eff (Error ClientError : NodeClientEffect : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs) x
 -> Eff (Error ClientError : NodeClientEffect : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (Error ClientError : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (case Config -> ChainQueryConfig
chainQueryConfig Config
config of
                ChainIndexConfig ChainIndexConfig
_ -> (Reader ClientEnv
 ~> Eff
      (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs))
-> Eff
     (Reader ClientEnv : Error ClientError : NodeClientEffect : effs)
   ~> Eff
        (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> ClientEnv)
-> Reader ClientEnv
   ~> Eff
        (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @ClientEnv (ChainQueryEnv -> ClientEnv
getChainIndexEnv (ChainQueryEnv -> ClientEnv)
-> (AppEnv a -> ChainQueryEnv) -> AppEnv a -> ClientEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> ChainQueryEnv
forall a. AppEnv a -> ChainQueryEnv
chainQueryEnv))
                                    (Eff
   (Reader ClientEnv : Error ClientError : NodeClientEffect : effs) x
 -> Eff
      (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
      x)
-> (Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader ClientEnv : Error ClientError : NodeClientEffect : effs) x)
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChainIndexQueryEffect
 ~> Eff
      (Reader ClientEnv : Error ClientError : NodeClientEffect : effs))
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        (Reader ClientEnv : Error ClientError : NodeClientEffect : effs)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *)
       (effs :: [* -> *]).
(f ~> Eff (g : h : effs)) -> Eff (f : effs) ~> Eff (g : h : effs)
reinterpret2 (forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader ClientEnv) effs, MonadIO IO,
 Member (Error ClientError) effs) =>
ChainIndexQueryEffect ~> Eff effs
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, Member (Reader ClientEnv) effs, MonadIO m,
 Member (Error ClientError) effs) =>
ChainIndexQueryEffect ~> Eff effs
ChainIndex.handleChainIndexClient @IO)
                BlockfrostConfig BlockfrostConfig
_ -> (Reader BlockfrostEnv
 ~> Eff
      (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs))
-> Eff
     (Reader BlockfrostEnv
        : Error ClientError : NodeClientEffect : effs)
   ~> Eff
        (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> BlockfrostEnv)
-> Reader BlockfrostEnv
   ~> Eff
        (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @BF.BlockfrostEnv (ChainQueryEnv -> BlockfrostEnv
getBlockfrostEnv (ChainQueryEnv -> BlockfrostEnv)
-> (AppEnv a -> ChainQueryEnv) -> AppEnv a -> BlockfrostEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppEnv a -> ChainQueryEnv
forall a. AppEnv a -> ChainQueryEnv
chainQueryEnv))
                                    (Eff
   (Reader BlockfrostEnv
      : Error ClientError : NodeClientEffect : effs)
   x
 -> Eff
      (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
      x)
-> (Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader BlockfrostEnv
            : Error ClientError : NodeClientEffect : effs)
         x)
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChainIndexQueryEffect
 ~> Eff
      (Reader BlockfrostEnv
         : Error ClientError : NodeClientEffect : effs))
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        (Reader BlockfrostEnv
           : Error ClientError : NodeClientEffect : effs)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *)
       (effs :: [* -> *]).
(f ~> Eff (g : h : effs)) -> Eff (f : effs) ~> Eff (g : h : effs)
reinterpret2 (forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader BlockfrostEnv) effs,
 MonadIO IO) =>
ChainIndexQueryEffect ~> Eff effs
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, Member (Reader BlockfrostEnv) effs,
 MonadIO m) =>
ChainIndexQueryEffect ~> Eff effs
BlockfrostClient.handleBlockfrostClient @IO))

            -- handle 'WalletEffect'
            (Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
 -> Eff
      (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a) : Error ClientError : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff
   (Error ClientError
      : ChainIndexQueryEffect : NodeClientEffect : effs)
   x
 -> (ClientError
     -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
 -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> (ClientError
    -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff
  (Error ClientError
     : ChainIndexQueryEffect : NodeClientEffect : effs)
  x
-> (ClientError
    -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError
 -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> (ClientError -> PABError)
-> ClientError
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientError -> PABError
WalletClientError)
            (Eff
   (Error ClientError
      : ChainIndexQueryEffect : NodeClientEffect : effs)
   x
 -> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff (ChainIndexQueryEffect : NodeClientEffect : effs) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff
   (Error WalletAPIError
      : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
      : effs)
   x
 -> (WalletAPIError
     -> Eff
          (Error ClientError
             : ChainIndexQueryEffect : NodeClientEffect : effs)
          x)
 -> Eff
      (Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs)
      x)
-> (WalletAPIError
    -> Eff
         (Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (Error WalletAPIError
        : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
        : effs)
     x
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff
  (Error WalletAPIError
     : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
     : effs)
  x
-> (WalletAPIError
    -> Eff
         (Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError
 -> Eff
      (Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs)
      x)
-> (WalletAPIError -> PABError)
-> WalletAPIError
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WalletAPIError -> PABError
WalletError)
            (Eff
   (Error WalletAPIError
      : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
      : effs)
   x
 -> Eff
      (Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Error WalletAPIError
            : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
            : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg WalletClientMsg
 ~> Eff
      (Error WalletAPIError
         : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
         : effs))
-> Eff
     (LogMsg WalletClientMsg
        : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
        : NodeClientEffect : effs)
   ~> Eff
        (Error WalletAPIError
           : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
           : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ((WalletClientMsg -> PABMultiAgentMsg (Builtin a))
-> LogMsg WalletClientMsg
   ~> Eff
        (Error WalletAPIError
           : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
           : effs)
forall a b (effs :: [* -> *]).
Member (LogMsg b) effs =>
(a -> b) -> LogMsg a ~> Eff effs
mapLog @_ @(PABMultiAgentMsg (Builtin a)) WalletClientMsg -> PABMultiAgentMsg (Builtin a)
forall t. WalletClientMsg -> PABMultiAgentMsg t
WalletClient)
            (Eff
   (LogMsg WalletClientMsg
      : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
      : NodeClientEffect : effs)
   x
 -> Eff
      (Error WalletAPIError
         : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
         : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (LogMsg WalletClientMsg
            : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
            : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Error WalletAPIError
        : Error ClientError : ChainIndexQueryEffect : NodeClientEffect
        : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff
      (LogMsg WalletClientMsg
         : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
         : NodeClientEffect : effs))
-> Eff
     (Reader (AppEnv a)
        : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        (LogMsg WalletClientMsg
           : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
           : NodeClientEffect : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader (AppEnv a)
      : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
      : ChainIndexQueryEffect : NodeClientEffect : effs)
   x
 -> Eff
      (LogMsg WalletClientMsg
         : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
         : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (AppEnv a)
            : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (LogMsg WalletClientMsg
        : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
        : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (Maybe ClientEnv)
 ~> Eff
      (Reader (AppEnv a)
         : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs))
-> Eff
     (Reader (Maybe ClientEnv)
        : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        (Reader (AppEnv a)
           : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
           : ChainIndexQueryEffect : NodeClientEffect : effs)
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((AppEnv a -> Maybe ClientEnv)
-> Reader (Maybe ClientEnv)
   ~> Eff
        (Reader (AppEnv a)
           : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
           : ChainIndexQueryEffect : NodeClientEffect : effs)
forall f g (effs :: [* -> *]).
Member (Reader f) effs =>
(f -> g) -> Reader g ~> Eff effs
Core.handleMappedReader @(AppEnv a) @(Maybe ClientEnv) AppEnv a -> Maybe ClientEnv
forall a. AppEnv a -> Maybe ClientEnv
walletClientEnv)
            (Eff
   (Reader (Maybe ClientEnv)
      : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
      : ChainIndexQueryEffect : NodeClientEffect : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (Maybe ClientEnv)
            : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a)
        : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader (AppEnv a)
 ~> Eff
      (Reader (Maybe ClientEnv)
         : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs))
-> Eff
     (Reader (AppEnv a)
        : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
        : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
        : NodeClientEffect : effs)
   ~> Eff
        (Reader (Maybe ClientEnv)
           : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
           : ChainIndexQueryEffect : NodeClientEffect : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader (AppEnv a) ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader env ~> Eff effs
Core.handleUserEnvReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader (AppEnv a)
      : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
      : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
      : NodeClientEffect : effs)
   x
 -> Eff
      (Reader (Maybe ClientEnv)
         : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
         : ChainIndexQueryEffect : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader (AppEnv a)
            : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
            : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
            : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (Maybe ClientEnv)
        : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reader InstancesState
 ~> Eff
      (Reader (AppEnv a)
         : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
         : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
         : NodeClientEffect : effs))
-> Eff
     (Reader InstancesState
        : Reader (AppEnv a) : Reader (Maybe ClientEnv)
        : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
        : ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        (Reader (AppEnv a)
           : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
           : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
           : NodeClientEffect : effs)
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (forall (effs :: [* -> *]).
Member (Reader (PABEnvironment (Builtin a) (AppEnv a))) effs =>
Reader InstancesState ~> Eff effs
forall t env (effs :: [* -> *]).
Member (Reader (PABEnvironment t env)) effs =>
Reader InstancesState ~> Eff effs
Core.handleInstancesStateReader @(Builtin a) @(AppEnv a))
            (Eff
   (Reader InstancesState
      : Reader (AppEnv a) : Reader (Maybe ClientEnv)
      : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
      : ChainIndexQueryEffect : NodeClientEffect : effs)
   x
 -> Eff
      (Reader (AppEnv a)
         : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
         : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
         : NodeClientEffect : effs)
      x)
-> (Eff
      (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
    -> Eff
         (Reader InstancesState
            : Reader (AppEnv a) : Reader (Maybe ClientEnv)
            : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
            : ChainIndexQueryEffect : NodeClientEffect : effs)
         x)
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs) x
-> Eff
     (Reader (AppEnv a)
        : Reader (Maybe ClientEnv) : LogMsg WalletClientMsg
        : Error WalletAPIError : Error ClientError : ChainIndexQueryEffect
        : NodeClientEffect : effs)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WalletEffect
 ~> Eff
      ('[Reader InstancesState, Reader (AppEnv a),
         Reader (Maybe ClientEnv), LogMsg WalletClientMsg,
         Error WalletAPIError, Error ClientError]
       :++: (ChainIndexQueryEffect : NodeClientEffect : effs)))
-> Eff
     (WalletEffect : ChainIndexQueryEffect : NodeClientEffect : effs)
   ~> Eff
        ('[Reader InstancesState, Reader (AppEnv a),
           Reader (Maybe ClientEnv), LogMsg WalletClientMsg,
           Error WalletAPIError, Error ClientError]
         :++: (ChainIndexQueryEffect : NodeClientEffect : effs))
forall (gs :: [* -> *]) (f :: * -> *) (effs :: [* -> *]).
Weakens gs =>
(f ~> Eff (gs :++: effs)) -> Eff (f : effs) ~> Eff (gs :++: effs)
reinterpretN @'[_, _, _, _, _, _] (PABServerConfig
-> Maybe ContractInstanceId
-> Wallet
-> WalletEffect
   ~> Eff
        (Reader InstancesState
           : Reader (AppEnv a) : Reader (Maybe ClientEnv)
           : LogMsg WalletClientMsg : Error WalletAPIError : Error ClientError
           : ChainIndexQueryEffect : NodeClientEffect : effs)
forall (effs :: [* -> *]).
(LastMember IO effs, Member NodeClientEffect effs,
 Member (Error ClientError) effs,
 Member (Error WalletAPIError) effs, Member (Error PABError) effs,
 Member (Reader (Maybe ClientEnv)) effs,
 Member (LogMsg WalletClientMsg) effs,
 Member (Reader InstancesState) effs) =>
PABServerConfig
-> Maybe ContractInstanceId -> Wallet -> WalletEffect ~> Eff effs
handleWalletEffect (Config -> PABServerConfig
nodeServerConfig Config
config) Maybe ContractInstanceId
cidM Wallet
wallet)

        , onStartup :: PABAction (Builtin a) (AppEnv a) ()
onStartup = () -> PABAction (Builtin a) (AppEnv a) ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

        , onShutdown :: PABAction (Builtin a) (AppEnv a) ()
onShutdown = () -> PABAction (Builtin a) (AppEnv a) ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        }

handleWalletEffect
  :: forall effs.
  ( LastMember IO effs
  , Member NodeClientEffect effs
  , Member (Error ClientError) effs
  , Member (Error WalletAPIError) effs
  , Member (Error PABError) effs
  , Member (Reader (Maybe ClientEnv)) effs
  , Member (LogMsg WalletClientMsg) effs
  , Member (Reader InstancesState) effs
  )
  => PABServerConfig
  -> Maybe ContractInstanceId
  -> Wallet
  -> WalletEffect
  ~> Eff effs
handleWalletEffect :: PABServerConfig
-> Maybe ContractInstanceId -> Wallet -> WalletEffect ~> Eff effs
handleWalletEffect PABServerConfig { pscNodeMode :: PABServerConfig -> NodeMode
pscNodeMode = NodeMode
MockNode } Maybe ContractInstanceId
_ Wallet
w WalletEffect x
eff = do
    Maybe ClientEnv
clientEnvM <- forall (effs :: [* -> *]).
Member (Reader (Maybe ClientEnv)) effs =>
Eff effs (Maybe ClientEnv)
forall r (effs :: [* -> *]). Member (Reader r) effs => Eff effs r
ask @(Maybe ClientEnv)
    case Maybe ClientEnv
clientEnvM of
        Maybe ClientEnv
Nothing -> PABError -> Eff effs x
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError PABError
RemoteWalletWithMockNodeError
        Just ClientEnv
clientEnv ->
            ClientEnv -> Eff (Reader ClientEnv : effs) x -> Eff effs x
forall r (effs :: [* -> *]) a.
r -> Eff (Reader r : effs) a -> Eff effs a
runReader ClientEnv
clientEnv (Eff (Reader ClientEnv : effs) x -> Eff effs x)
-> Eff (Reader ClientEnv : effs) x -> Eff effs x
forall a b. (a -> b) -> a -> b
$ Wallet -> WalletEffect x -> Eff (Reader ClientEnv : effs) x
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m, Member (Error ClientError) effs,
 Member (Error WalletAPIError) effs,
 Member (Reader ClientEnv) effs) =>
Wallet -> WalletEffect ~> Eff effs
WalletMockClient.handleWalletClient @IO Wallet
w WalletEffect x
eff
handleWalletEffect PABServerConfig
nodeCfg Maybe ContractInstanceId
cidM Wallet
w WalletEffect x
eff = do
    Maybe ClientEnv
clientEnvM <- forall (effs :: [* -> *]).
Member (Reader (Maybe ClientEnv)) effs =>
Eff effs (Maybe ClientEnv)
forall r (effs :: [* -> *]). Member (Reader r) effs => Eff effs r
ask @(Maybe ClientEnv)
    case Maybe ClientEnv
clientEnvM of
        Maybe ClientEnv
Nothing -> Maybe ContractInstanceId -> WalletEffect x -> Eff effs x
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m, Member NodeClientEffect effs,
 Member (Error WalletAPIError) effs,
 Member (Reader InstancesState) effs) =>
Maybe ContractInstanceId -> WalletEffect ~> Eff effs
RemoteWalletClient.handleWalletClient Maybe ContractInstanceId
cidM WalletEffect x
eff
        Just ClientEnv
clientEnv ->
            ClientEnv -> Eff (Reader ClientEnv : effs) x -> Eff effs x
forall r (effs :: [* -> *]) a.
r -> Eff (Reader r : effs) a -> Eff effs a
runReader ClientEnv
clientEnv (Eff (Reader ClientEnv : effs) x -> Eff effs x)
-> Eff (Reader ClientEnv : effs) x -> Eff effs x
forall a b. (a -> b) -> a -> b
$ PABServerConfig
-> Wallet -> WalletEffect x -> Eff (Reader ClientEnv : effs) x
forall (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m, Member NodeClientEffect effs,
 Member (Error ClientError) effs,
 Member (Error WalletAPIError) effs, Member (Reader ClientEnv) effs,
 Member (LogMsg WalletClientMsg) effs) =>
PABServerConfig -> Wallet -> WalletEffect ~> Eff effs
LocalWalletClient.handleWalletClient @IO PABServerConfig
nodeCfg Wallet
w WalletEffect x
eff

runApp ::
    forall a b.
    ( FromJSON a
    , ToJSON a
    , HasDefinitions a
    , Typeable a
    )
    => StorageBackend
    -> Trace IO (PABLogMsg (Builtin a)) -- ^ Top-level tracer
    -> BuiltinHandler a
    -> Config -- ^ Client configuration
    -> App a b -- ^ Action
    -> IO (Either PABError b)
runApp :: StorageBackend
-> Trace IO (PABLogMsg (Builtin a))
-> BuiltinHandler a
-> Config
-> App a b
-> IO (Either PABError b)
runApp
    StorageBackend
storageBackend
    Trace IO (PABLogMsg (Builtin a))
trace
    BuiltinHandler a
contractHandler
    config :: Config
config@Config{pabWebserverConfig :: Config -> WebserverConfig
pabWebserverConfig=WebserverConfig{Maybe Second
endpointTimeout :: Maybe Second
endpointTimeout :: WebserverConfig -> Maybe Second
endpointTimeout, Maybe Second
waitStatusTimeout :: Maybe Second
waitStatusTimeout :: WebserverConfig -> Maybe Second
waitStatusTimeout}} =
    Timeout
-> Timeout
-> EffectHandlers (Builtin a) (AppEnv a)
-> App a b
-> IO (Either PABError b)
forall t env a.
Timeout
-> Timeout
-> EffectHandlers t env
-> PABAction t env a
-> IO (Either PABError a)
Core.runPAB (Maybe Second -> Timeout
Timeout Maybe Second
endpointTimeout) (Maybe Second -> Timeout
Timeout Maybe Second
waitStatusTimeout) (StorageBackend
-> Config
-> Trace IO (PABLogMsg (Builtin a))
-> BuiltinHandler a
-> EffectHandlers (Builtin a) (AppEnv a)
forall a.
(FromJSON a, ToJSON a, HasDefinitions a, Typeable a) =>
StorageBackend
-> Config
-> Trace IO (PABLogMsg (Builtin a))
-> BuiltinHandler a
-> EffectHandlers (Builtin a) (AppEnv a)
appEffectHandlers StorageBackend
storageBackend Config
config Trace IO (PABLogMsg (Builtin a))
trace BuiltinHandler a
contractHandler)

type App a b = PABAction (Builtin a) (AppEnv a) b

data StorageBackend = BeamBackend | InMemoryBackend
  deriving (StorageBackend -> StorageBackend -> Bool
(StorageBackend -> StorageBackend -> Bool)
-> (StorageBackend -> StorageBackend -> Bool) -> Eq StorageBackend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StorageBackend -> StorageBackend -> Bool
$c/= :: StorageBackend -> StorageBackend -> Bool
== :: StorageBackend -> StorageBackend -> Bool
$c== :: StorageBackend -> StorageBackend -> Bool
Eq, Eq StorageBackend
Eq StorageBackend
-> (StorageBackend -> StorageBackend -> Ordering)
-> (StorageBackend -> StorageBackend -> Bool)
-> (StorageBackend -> StorageBackend -> Bool)
-> (StorageBackend -> StorageBackend -> Bool)
-> (StorageBackend -> StorageBackend -> Bool)
-> (StorageBackend -> StorageBackend -> StorageBackend)
-> (StorageBackend -> StorageBackend -> StorageBackend)
-> Ord StorageBackend
StorageBackend -> StorageBackend -> Bool
StorageBackend -> StorageBackend -> Ordering
StorageBackend -> StorageBackend -> StorageBackend
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: StorageBackend -> StorageBackend -> StorageBackend
$cmin :: StorageBackend -> StorageBackend -> StorageBackend
max :: StorageBackend -> StorageBackend -> StorageBackend
$cmax :: StorageBackend -> StorageBackend -> StorageBackend
>= :: StorageBackend -> StorageBackend -> Bool
$c>= :: StorageBackend -> StorageBackend -> Bool
> :: StorageBackend -> StorageBackend -> Bool
$c> :: StorageBackend -> StorageBackend -> Bool
<= :: StorageBackend -> StorageBackend -> Bool
$c<= :: StorageBackend -> StorageBackend -> Bool
< :: StorageBackend -> StorageBackend -> Bool
$c< :: StorageBackend -> StorageBackend -> Bool
compare :: StorageBackend -> StorageBackend -> Ordering
$ccompare :: StorageBackend -> StorageBackend -> Ordering
$cp1Ord :: Eq StorageBackend
Ord, Int -> StorageBackend -> ShowS
[StorageBackend] -> ShowS
StorageBackend -> String
(Int -> StorageBackend -> ShowS)
-> (StorageBackend -> String)
-> ([StorageBackend] -> ShowS)
-> Show StorageBackend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StorageBackend] -> ShowS
$cshowList :: [StorageBackend] -> ShowS
show :: StorageBackend -> String
$cshow :: StorageBackend -> String
showsPrec :: Int -> StorageBackend -> ShowS
$cshowsPrec :: Int -> StorageBackend -> ShowS
Show)

mkEnv :: Trace IO (PABLogMsg (Builtin a)) -> Config -> IO (AppEnv a)
mkEnv :: Trace IO (PABLogMsg (Builtin a)) -> Config -> IO (AppEnv a)
mkEnv Trace IO (PABLogMsg (Builtin a))
appTrace appConfig :: Config
appConfig@Config { DbConfig
dbConfig :: DbConfig
dbConfig :: Config -> DbConfig
dbConfig
             , nodeServerConfig :: Config -> PABServerConfig
nodeServerConfig = PABServerConfig{BaseUrl
pscBaseUrl :: BaseUrl
pscBaseUrl :: PABServerConfig -> BaseUrl
pscBaseUrl, String
pscSocketPath :: String
pscSocketPath :: PABServerConfig -> String
pscSocketPath, NodeMode
pscNodeMode :: NodeMode
pscNodeMode :: PABServerConfig -> NodeMode
pscNodeMode, NetworkIdWrapper
pscNetworkId :: NetworkIdWrapper
pscNetworkId :: PABServerConfig -> NetworkIdWrapper
pscNetworkId}
             , WalletConfig
walletServerConfig :: WalletConfig
walletServerConfig :: Config -> WalletConfig
walletServerConfig
             , ChainQueryConfig
chainQueryConfig :: ChainQueryConfig
chainQueryConfig :: Config -> ChainQueryConfig
chainQueryConfig
             } = do
    Maybe ClientEnv
walletClientEnv <- IO (Maybe ClientEnv)
-> (LocalWalletSettings -> IO (Maybe ClientEnv))
-> Maybe LocalWalletSettings
-> IO (Maybe ClientEnv)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe ClientEnv -> IO (Maybe ClientEnv)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ClientEnv
forall a. Maybe a
Nothing) ((ClientEnv -> Maybe ClientEnv)
-> IO ClientEnv -> IO (Maybe ClientEnv)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ClientEnv -> Maybe ClientEnv
forall a. a -> Maybe a
Just (IO ClientEnv -> IO (Maybe ClientEnv))
-> (LocalWalletSettings -> IO ClientEnv)
-> LocalWalletSettings
-> IO (Maybe ClientEnv)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalWalletSettings -> IO ClientEnv
forall (f :: * -> *) a.
(MonadIO f, Coercible a BaseUrl) =>
a -> f ClientEnv
clientEnv) (Maybe LocalWalletSettings -> IO (Maybe ClientEnv))
-> Maybe LocalWalletSettings -> IO (Maybe ClientEnv)
forall a b. (a -> b) -> a -> b
$ Getting
  (First LocalWalletSettings) WalletConfig LocalWalletSettings
-> WalletConfig -> Maybe LocalWalletSettings
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting
  (First LocalWalletSettings) WalletConfig LocalWalletSettings
Prism' WalletConfig LocalWalletSettings
Wallet._LocalWalletConfig WalletConfig
walletServerConfig
    ClientEnv
nodeClientEnv <- BaseUrl -> IO ClientEnv
forall (f :: * -> *) a.
(MonadIO f, Coercible a BaseUrl) =>
a -> f ClientEnv
clientEnv BaseUrl
pscBaseUrl
    ChainQueryEnv
chainQueryEnv <- IO ChainQueryEnv
mkChainQueryEnv
    DBConnection
dbPool <- DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO DBConnection
forall a.
DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO DBConnection
dbConnect DbConfig
dbConfig Trace IO (PABLogMsg (Builtin a))
appTrace
    Maybe TxSendHandle
txSendHandle <-
      case NodeMode
pscNodeMode of
        NodeMode
MockNode -> IO (Maybe TxSendHandle) -> IO (Maybe TxSendHandle)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe TxSendHandle) -> IO (Maybe TxSendHandle))
-> IO (Maybe TxSendHandle) -> IO (Maybe TxSendHandle)
forall a b. (a -> b) -> a -> b
$ TxSendHandle -> Maybe TxSendHandle
forall a. a -> Maybe a
Just (TxSendHandle -> Maybe TxSendHandle)
-> IO TxSendHandle -> IO (Maybe TxSendHandle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO TxSendHandle
MockClient.runTxSender String
pscSocketPath
        NodeMode
_        -> Maybe TxSendHandle -> IO (Maybe TxSendHandle)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe TxSendHandle
forall a. Maybe a
Nothing
    -- This is for access to the slot number in the interpreter
    ChainSyncHandle
chainSyncHandle <- PABServerConfig -> IO ChainSyncHandle
runChainSyncWithCfg (PABServerConfig -> IO ChainSyncHandle)
-> PABServerConfig -> IO ChainSyncHandle
forall a b. (a -> b) -> a -> b
$ Config -> PABServerConfig
nodeServerConfig Config
appConfig
    InMemInstances (Builtin a)
appInMemContractStore <- IO (InMemInstances (Builtin a)) -> IO (InMemInstances (Builtin a))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (InMemInstances (Builtin a))
forall t. IO (InMemInstances t)
initialInMemInstances
    AppEnv a -> IO (AppEnv a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure AppEnv :: forall a.
DBConnection
-> Maybe ClientEnv
-> ClientEnv
-> ChainQueryEnv
-> Maybe TxSendHandle
-> ChainSyncHandle
-> Config
-> Trace IO (PABLogMsg (Builtin a))
-> InMemInstances (Builtin a)
-> AppEnv a
AppEnv {Maybe ClientEnv
Maybe TxSendHandle
ChainSyncHandle
Trace IO (PABLogMsg (Builtin a))
ClientEnv
Config
ChainQueryEnv
DBConnection
InMemInstances (Builtin a)
appInMemContractStore :: InMemInstances (Builtin a)
chainSyncHandle :: ChainSyncHandle
txSendHandle :: Maybe TxSendHandle
dbPool :: DBConnection
chainQueryEnv :: ChainQueryEnv
nodeClientEnv :: ClientEnv
walletClientEnv :: Maybe ClientEnv
appConfig :: Config
appTrace :: Trace IO (PABLogMsg (Builtin a))
appInMemContractStore :: InMemInstances (Builtin a)
appTrace :: Trace IO (PABLogMsg (Builtin a))
appConfig :: Config
chainSyncHandle :: ChainSyncHandle
txSendHandle :: Maybe TxSendHandle
chainQueryEnv :: ChainQueryEnv
nodeClientEnv :: ClientEnv
walletClientEnv :: Maybe ClientEnv
dbPool :: DBConnection
..}
  where
    clientEnv :: a -> f ClientEnv
clientEnv a
baseUrl = Manager -> BaseUrl -> ClientEnv
mkClientEnv (Manager -> BaseUrl -> ClientEnv)
-> f Manager -> f (BaseUrl -> ClientEnv)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO Manager -> f Manager
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Manager
mkManager f (BaseUrl -> ClientEnv) -> f BaseUrl -> f ClientEnv
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> BaseUrl -> f BaseUrl
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> BaseUrl
coerce a
baseUrl)

    mkManager :: IO Manager
mkManager =
        ManagerSettings -> IO Manager
newManager (ManagerSettings -> IO Manager) -> ManagerSettings -> IO Manager
forall a b. (a -> b) -> a -> b
$
        ManagerSettings
tlsManagerSettings { managerModifyRequest :: Request -> IO Request
managerModifyRequest = Request -> IO Request
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Request -> IO Request)
-> (Request -> Request) -> Request -> IO Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Request
setRequestIgnoreStatus
                           , managerResponseTimeout :: ResponseTimeout
managerResponseTimeout = Int -> ResponseTimeout
responseTimeoutMicro Int
60_000_000 }

    mkChainQueryEnv :: IO ChainQueryEnv
    mkChainQueryEnv :: IO ChainQueryEnv
mkChainQueryEnv = case ChainQueryConfig
chainQueryConfig of
        ChainIndexConfig ChainIndexConfig
config -> ClientEnv -> ChainQueryEnv
ChainIndexEnv (ClientEnv -> ChainQueryEnv) -> IO ClientEnv -> IO ChainQueryEnv
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ChainIndexUrl -> IO ClientEnv
forall (f :: * -> *) a.
(MonadIO f, Coercible a BaseUrl) =>
a -> f ClientEnv
clientEnv (ChainIndexConfig -> ChainIndexUrl
ChainIndex.ciBaseUrl ChainIndexConfig
config)
        BlockfrostConfig BlockfrostConfig
config -> ChainQueryEnv -> IO ChainQueryEnv
forall (m :: * -> *) a. Monad m => a -> m a
return (ChainQueryEnv -> IO ChainQueryEnv)
-> ChainQueryEnv -> IO ChainQueryEnv
forall a b. (a -> b) -> a -> b
$ BlockfrostEnv -> ChainQueryEnv
BlockfrostEnv (BlockfrostEnv -> ChainQueryEnv) -> BlockfrostEnv -> ChainQueryEnv
forall a b. (a -> b) -> a -> b
$
            BlockfrostEnv :: String -> NetworkId -> BlockfrostEnv
BF.BlockfrostEnv { envBfTokenPath :: String
envBfTokenPath = BlockfrostConfig -> String
BF.bfTokenPath BlockfrostConfig
config
                             , envNetworkId :: NetworkId
envNetworkId = NetworkIdWrapper -> NetworkId
unNetworkIdWrapper NetworkIdWrapper
pscNetworkId}

logDebugString :: Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString :: Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg t)
trace = Trace IO (PABLogMsg t) -> PABLogMsg t -> IO ()
forall (m :: * -> *) a. MonadIO m => Trace m a -> a -> m ()
logDebug Trace IO (PABLogMsg t)
trace (PABLogMsg t -> IO ()) -> (Text -> PABLogMsg t) -> Text -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PABMultiAgentMsg t -> PABLogMsg t
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg t -> PABLogMsg t)
-> (Text -> PABMultiAgentMsg t) -> Text -> PABLogMsg t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PABMultiAgentMsg t
forall t. Text -> PABMultiAgentMsg t
UserLog

dbConnect :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO DBConnection
dbConnect :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO DBConnection
dbConnect (PostgresDB DbConfig
db) Trace IO (PABLogMsg (Builtin a))
trace = Pool Connection -> DBConnection
PostgresPool (Pool Connection -> DBConnection)
-> IO (Pool Connection) -> IO DBConnection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
forall a.
DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectPostgres DbConfig
db Trace IO (PABLogMsg (Builtin a))
trace
dbConnect (SqliteDB DbConfig
db) Trace IO (PABLogMsg (Builtin a))
trace   = Pool Connection -> DBConnection
SqlitePool (Pool Connection -> DBConnection)
-> IO (Pool Connection) -> IO DBConnection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
forall a.
DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectSqlite DbConfig
db Trace IO (PABLogMsg (Builtin a))
trace

migrate :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migrate :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migrate (PostgresDB DbConfig
db) = IO () -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> IO ())
-> (Trace IO (PABLogMsg (Builtin a)) -> IO ())
-> Trace IO (PABLogMsg (Builtin a))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
forall a. DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migratePostgres DbConfig
db
migrate (SqliteDB DbConfig
db)   = IO () -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> IO ())
-> (Trace IO (PABLogMsg (Builtin a)) -> IO ())
-> Trace IO (PABLogMsg (Builtin a))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
forall a. DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migrateSqlite DbConfig
db

-- POSTGRES
-- | Initialize/update the database to hold our effects.
migratePostgres :: Postgres.DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migratePostgres :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migratePostgres DbConfig
config Trace IO (PABLogMsg (Builtin a))
trace = do
    Pool Connection
pool <- DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
forall a.
DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectPostgres DbConfig
config Trace IO (PABLogMsg (Builtin a))
trace
    Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace Text
"Running beam migration"
    Pool Connection -> (Connection -> IO ()) -> IO ()
forall a r. Pool a -> (a -> IO r) -> IO r
Pool.withResource Pool Connection
pool (Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
forall a. Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
runBeamMigrationPostgres Trace IO (PABLogMsg (Builtin a))
trace)

runBeamMigrationPostgres
  :: Trace IO (PABLogMsg (Builtin a))
  -> Postgres.Connection
  -> IO ()
runBeamMigrationPostgres :: Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
runBeamMigrationPostgres Trace IO (PABLogMsg (Builtin a))
trace Connection
conn = (String -> IO ()) -> Connection -> Pg () -> IO ()
forall a. (String -> IO ()) -> Connection -> Pg a -> IO a
Postgres.runBeamPostgresDebug (Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace (Text -> IO ()) -> (String -> Text) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack) Connection
conn (Pg () -> IO ()) -> Pg () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
  BeamMigrationBackend Postgres Pg
-> CheckedDatabaseSettings Postgres Db -> Pg ()
forall be (db :: (* -> *) -> *) (m :: * -> *).
(Database be db, MonadFail m) =>
BeamMigrationBackend be m -> CheckedDatabaseSettings be db -> m ()
autoMigrate BeamMigrationBackend Postgres Pg
Postgres.migrationBackend CheckedDatabaseSettings Postgres Db
checkedPostgresDb

-- | Connect to the database.
dbConnectPostgres :: Postgres.DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Postgres.Connection)
dbConnectPostgres :: DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectPostgres Postgres.DbConfig{Int
Word16
Text
dbConfigUser :: DbConfig -> Text
dbConfigPass :: DbConfig -> Text
dbConfigHost :: DbConfig -> Text
dbConfigPort :: DbConfig -> Word16
dbConfigDatabase :: DbConfig -> Text
dbConfigPoolSize :: DbConfig -> Int
dbConfigMarconiFile :: DbConfig -> Text
dbConfigMarconiFile :: Text
dbConfigPoolSize :: Int
dbConfigDatabase :: Text
dbConfigPort :: Word16
dbConfigHost :: Text
dbConfigPass :: Text
dbConfigUser :: Text
..} Trace IO (PABLogMsg (Builtin a))
trace = do
  Pool Connection
pool <- PoolConfig Connection -> IO (Pool Connection)
forall a. PoolConfig a -> IO (Pool a)
Pool.newPool PoolConfig :: forall a. IO a -> (a -> IO ()) -> Double -> Int -> PoolConfig a
Pool.PoolConfig
    { createResource :: IO Connection
Pool.createResource = ConnectInfo -> IO Connection
Postgres.connect ConnectInfo :: String -> Word16 -> String -> String -> String -> ConnectInfo
Postgres.ConnectInfo
      { connectHost :: String
Postgres.connectHost = Text -> String
unpack Text
dbConfigHost
      , connectPort :: Word16
Postgres.connectPort = Word16
dbConfigPort
      , connectUser :: String
Postgres.connectUser = Text -> String
unpack Text
dbConfigUser
      , connectPassword :: String
Postgres.connectPassword = Text -> String
unpack Text
dbConfigPass
      , connectDatabase :: String
Postgres.connectDatabase = Text -> String
unpack Text
dbConfigDatabase
      }
    , freeResource :: Connection -> IO ()
Pool.freeResource = Connection -> IO ()
Postgres.close
    , poolCacheTTL :: Double
Pool.poolCacheTTL = Double
5_000_000
    , poolMaxResources :: Int
Pool.poolMaxResources = Int
dbConfigPoolSize Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
5
    }
  Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ Text
"Connecting to DB: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
databaseStr
  Pool Connection -> IO (Pool Connection)
forall (m :: * -> *) a. Monad m => a -> m a
return Pool Connection
pool
  where
    databaseStr :: Text
    databaseStr :: Text
databaseStr = Text
dbConfigHost Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (String -> Text
pack (String -> Text) -> (Word16 -> String) -> Word16 -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> String
forall a. Show a => a -> String
show) Word16
dbConfigPort

-- SQLITE
migrateSqlite :: Sqlite.DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migrateSqlite :: DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO ()
migrateSqlite DbConfig
config Trace IO (PABLogMsg (Builtin a))
trace = do
    Pool Connection
pool <- DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
forall a.
DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectSqlite DbConfig
config Trace IO (PABLogMsg (Builtin a))
trace
    Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace Text
"Running beam migration"
    Pool Connection -> (Connection -> IO ()) -> IO ()
forall a r. Pool a -> (a -> IO r) -> IO r
Pool.withResource Pool Connection
pool (Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
forall a. Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
runBeamMigrationSqlite Trace IO (PABLogMsg (Builtin a))
trace)

runBeamMigrationSqlite
  :: Trace IO (PABLogMsg (Builtin a))
  -> Sqlite.Connection
  -> IO ()
runBeamMigrationSqlite :: Trace IO (PABLogMsg (Builtin a)) -> Connection -> IO ()
runBeamMigrationSqlite Trace IO (PABLogMsg (Builtin a))
trace Connection
conn = (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
Sqlite.runBeamSqliteDebug (Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace (Text -> IO ()) -> (String -> Text) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack) Connection
conn (SqliteM () -> IO ()) -> SqliteM () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
  BeamMigrationBackend Sqlite SqliteM
-> CheckedDatabaseSettings Sqlite Db -> SqliteM ()
forall be (db :: (* -> *) -> *) (m :: * -> *).
(Database be db, MonadFail m) =>
BeamMigrationBackend be m -> CheckedDatabaseSettings be db -> m ()
autoMigrate BeamMigrationBackend Sqlite SqliteM
Sqlite.migrationBackend CheckedDatabaseSettings Sqlite Db
checkedSqliteDb

dbConnectSqlite :: Sqlite.DbConfig -> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Sqlite.Connection)
dbConnectSqlite :: DbConfig
-> Trace IO (PABLogMsg (Builtin a)) -> IO (Pool Connection)
dbConnectSqlite Sqlite.DbConfig {Text
dbConfigFile :: DbConfig -> Text
dbConfigFile :: Text
dbConfigFile, Int
dbConfigPoolSize :: DbConfig -> Int
dbConfigPoolSize :: Int
dbConfigPoolSize} Trace IO (PABLogMsg (Builtin a))
trace = do
  Pool Connection
pool <- PoolConfig Connection -> IO (Pool Connection)
forall a. PoolConfig a -> IO (Pool a)
Pool.newPool PoolConfig :: forall a. IO a -> (a -> IO ()) -> Double -> Int -> PoolConfig a
Pool.PoolConfig
    { createResource :: IO Connection
Pool.createResource = String -> IO Connection
Sqlite.open (String -> IO Connection) -> String -> IO Connection
forall a b. (a -> b) -> a -> b
$ Text -> String
unpack Text
dbConfigFile
    , freeResource :: Connection -> IO ()
Pool.freeResource = Connection -> IO ()
Sqlite.close
    , poolCacheTTL :: Double
Pool.poolCacheTTL = Double
5_000_000
    , poolMaxResources :: Int
Pool.poolMaxResources = Int
dbConfigPoolSize Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
5
    }
  Trace IO (PABLogMsg (Builtin a)) -> Text -> IO ()
forall t. Trace IO (PABLogMsg t) -> Text -> IO ()
logDebugString Trace IO (PABLogMsg (Builtin a))
trace (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ Text
"Connecting to DB: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
dbConfigFile
  Pool Connection -> IO (Pool Connection)
forall (m :: * -> *) a. Monad m => a -> m a
return Pool Connection
pool

handleContractDefinition ::
  forall a effs. HasDefinitions a
  => ContractDefinition (Builtin a)
  ~> Eff effs
handleContractDefinition :: ContractDefinition (Builtin a) ~> Eff effs
handleContractDefinition = \case
  AddDefinition ContractDef (Builtin a)
_ -> () -> Eff effs ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
  ContractDefinition (Builtin a) x
GetDefinitions  -> [a] -> Eff effs [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [a]
forall a. HasDefinitions a => [a]
getDefinitions