{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-- The Shelley ledger uses promoted data kinds which we have to use, but we do
-- not export any from this API. We also use them unticked as nature intended.
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}

-- | Node IPC protocols
module Cardano.Api.IPC
  ( -- * Node interaction

    -- | Operations that involve talking to a local Cardano node.
    connectToLocalNode
  , connectToLocalNodeWithVersion
  , LocalNodeConnectInfo (..)
  , LocalNodeClientParams (..)
  , mkLocalNodeClientParams
  , LocalNodeClientProtocols (..)
  , LocalChainSyncClient (..)
  , LocalNodeClientProtocolsInMode

    -- ** Modes

    -- | TODO move to Cardano.Api
  , ConsensusModeParams (..)
  , EpochSlots (..)
  --  connectToRemoteNode,

    -- *** Chain sync protocol
  , ChainSyncClient (..)
  , ChainSyncClientPipelined (..)
  , BlockInMode (..)

    -- *** Local tx submission
  , LocalTxSubmissionClient (..)
  , TxInMode (..)
  , TxValidationErrorInCardanoMode
  , TxValidationError
  , submitTxToNodeLocal
  , SubmitResult (..)

    -- *** Local state query
  , LocalStateQueryClient (..)
  , AcquiringFailure (..)
  , QueryInMode (..)
  , QueryInEra (..)
  , QueryInShelleyBasedEra (..)
  , queryNodeLocalState

    -- *** Local tx monitoring
  , LocalTxMonitorClient (..)
  , LocalTxMonitoringQuery (..)
  , LocalTxMonitoringResult (..)
  , Consensus.MempoolSizeAndCapacity (..)
  , queryTxMonitoringLocal
  , EraHistory (..)
  , getProgress

    -- *** Common queries
  , getLocalChainTip

    -- *** Helpers

  -- TODO: These should be exported via Cardano.Api.Mode
  , toAcquiringFailure
  , NodeToClientVersion (..)
  , UnsupportedNtcVersionError (..)
  )
where

import           Cardano.Api.Block
import           Cardano.Api.HasTypeProxy
import           Cardano.Api.InMode
import           Cardano.Api.IO
import           Cardano.Api.IPC.Version
import           Cardano.Api.Modes
import           Cardano.Api.Monad.Error (ExceptT (..))
import           Cardano.Api.NetworkId
import           Cardano.Api.Protocol
import           Cardano.Api.Query
import           Cardano.Api.Tx.Body
import           Cardano.Api.Tx.Sign

import qualified Cardano.Ledger.Api as L
import qualified Ouroboros.Consensus.Block as Consensus
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import           Ouroboros.Consensus.Cardano.CanHardFork
import qualified Ouroboros.Consensus.Ledger.Query as Consensus
import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Consensus
import qualified Ouroboros.Consensus.Ledger.SupportsProtocol as Consensus
import qualified Ouroboros.Consensus.Network.NodeToClient as Consensus
import qualified Ouroboros.Consensus.Node.NetworkProtocolVersion as Consensus
import qualified Ouroboros.Consensus.Node.ProtocolInfo as Consensus
import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus
import           Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
import qualified Ouroboros.Network.Block as Net
import qualified Ouroboros.Network.Mux as Net
import           Ouroboros.Network.NodeToClient (NodeToClientProtocols (..),
                   NodeToClientVersionData (..))
import qualified Ouroboros.Network.NodeToClient as Net
import           Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..))
import           Ouroboros.Network.Protocol.ChainSync.Client as Net.Sync
import           Ouroboros.Network.Protocol.ChainSync.ClientPipelined as Net.SyncP
import           Ouroboros.Network.Protocol.LocalStateQuery.Client (LocalStateQueryClient (..))
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as Net.Query
import           Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure (..))
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Net.Query
import           Ouroboros.Network.Protocol.LocalTxMonitor.Client (LocalTxMonitorClient (..),
                   localTxMonitorClientPeer)
import qualified Ouroboros.Network.Protocol.LocalTxMonitor.Client as CTxMon
import qualified Ouroboros.Network.Protocol.LocalTxMonitor.Type as Consensus
import           Ouroboros.Network.Protocol.LocalTxSubmission.Client (LocalTxSubmissionClient (..),
                   SubmitResult (..))
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx

import           Control.Concurrent.STM (TMVar, atomically, newEmptyTMVarIO, putTMVar, takeTMVar,
                   tryPutTMVar)
import           Control.Monad (void)
import           Control.Monad.IO.Class
import           Control.Tracer (nullTracer)
import           Data.Aeson (ToJSON, object, toJSON, (.=))
import qualified Data.ByteString.Lazy as LBS
import           Data.Void (Void)
import           GHC.Exts (IsList (..))

-- ----------------------------------------------------------------------------
-- The types for the client side of the node-to-client IPC protocols
--

-- | The protocols we can use with a local node. Use in conjunction with
-- 'connectToLocalNode'.
--
-- These protocols use the types from the rest of this API. The conversion
-- to\/from the types used by the underlying wire formats is handled by
-- 'connectToLocalNode'.
data LocalNodeClientProtocols block point tip slot tx txid txerr query m
  = LocalNodeClientProtocols
  { forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> LocalChainSyncClient block point tip m
localChainSyncClient :: LocalChainSyncClient block point tip m
  , forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalTxSubmissionClient tx txerr m ())
localTxSubmissionClient :: Maybe (LocalTxSubmissionClient tx txerr m ())
  , forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalStateQueryClient block point query m ())
localStateQueryClient :: Maybe (LocalStateQueryClient block point query m ())
  , forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalTxMonitorClient txid tx slot m ())
localTxMonitoringClient :: Maybe (LocalTxMonitorClient txid tx slot m ())
  }

data LocalChainSyncClient block point tip m
  = NoLocalChainSyncClient
  | LocalChainSyncClientPipelined (ChainSyncClientPipelined block point tip m ())
  | LocalChainSyncClient (ChainSyncClient block point tip m ())

-- public, exported
type LocalNodeClientProtocolsInMode =
  LocalNodeClientProtocols
    BlockInMode
    ChainPoint
    ChainTip
    SlotNo
    TxInMode
    TxIdInMode
    TxValidationErrorInCardanoMode
    QueryInMode
    IO

data LocalNodeConnectInfo
  = LocalNodeConnectInfo
  { LocalNodeConnectInfo -> ConsensusModeParams
localConsensusModeParams :: ConsensusModeParams
  , LocalNodeConnectInfo -> NetworkId
localNodeNetworkId :: NetworkId
  , LocalNodeConnectInfo -> SocketPath
localNodeSocketPath :: SocketPath
  }

-- ----------------------------------------------------------------------------
-- Actually connect to the node
--

-- | Establish a connection to a local node and execute the given set of
-- protocol handlers.
connectToLocalNode
  :: MonadIO m
  => LocalNodeConnectInfo
  -> LocalNodeClientProtocolsInMode
  -> m ()
connectToLocalNode :: forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
connectToLocalNode LocalNodeConnectInfo
localNodeConnectInfo LocalNodeClientProtocolsInMode
handlers =
  LocalNodeConnectInfo
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode) -> m ()
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode) -> m ()
connectToLocalNodeWithVersion LocalNodeConnectInfo
localNodeConnectInfo (LocalNodeClientProtocolsInMode
-> NodeToClientVersion -> LocalNodeClientProtocolsInMode
forall a b. a -> b -> a
const LocalNodeClientProtocolsInMode
handlers)

-- | Establish a connection to a local node and execute the given set of
-- protocol handlers parameterized on the negotiated node-to-client protocol
-- version.
connectToLocalNodeWithVersion
  :: MonadIO m
  => LocalNodeConnectInfo
  -> (NodeToClientVersion -> LocalNodeClientProtocolsInMode)
  -> m ()
connectToLocalNodeWithVersion :: forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode) -> m ()
connectToLocalNodeWithVersion
  LocalNodeConnectInfo
    { SocketPath
localNodeSocketPath :: LocalNodeConnectInfo -> SocketPath
localNodeSocketPath :: SocketPath
localNodeSocketPath
    , NetworkId
localNodeNetworkId :: LocalNodeConnectInfo -> NetworkId
localNodeNetworkId :: NetworkId
localNodeNetworkId
    , ConsensusModeParams
localConsensusModeParams :: LocalNodeConnectInfo -> ConsensusModeParams
localConsensusModeParams :: ConsensusModeParams
localConsensusModeParams
    }
  NodeToClientVersion -> LocalNodeClientProtocolsInMode
clients =
    IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ (IOManager -> IO ()) -> IO ()
WithIOManager
Net.withIOManager ((IOManager -> IO ()) -> IO ()) -> (IOManager -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \IOManager
iomgr ->
      LocalSnocket
-> NetworkConnectTracers LocalAddress NodeToClientVersion
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
-> FilePath
-> IO ()
forall a b.
LocalSnocket
-> NetworkConnectTracers LocalAddress NodeToClientVersion
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO a b)
-> FilePath
-> IO ()
Net.connectTo
        (IOManager -> LocalSnocket
Net.localSnocket IOManager
iomgr)
        Net.NetworkConnectTracers
          { nctMuxTracer :: Tracer IO (WithMuxBearer (ConnectionId LocalAddress) MuxTrace)
Net.nctMuxTracer = Tracer IO (WithMuxBearer (ConnectionId LocalAddress) MuxTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
          , nctHandshakeTracer :: Tracer
  IO
  (WithMuxBearer
     (ConnectionId LocalAddress)
     (TraceSendRecv (Handshake NodeToClientVersion Term)))
Net.nctHandshakeTracer = Tracer
  IO
  (WithMuxBearer
     (ConnectionId LocalAddress)
     (TraceSendRecv (Handshake NodeToClientVersion Term)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
          }
        Versions
  NodeToClientVersion
  NodeToClientVersionData
  (OuroborosApplicationWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void)
versionedProtocls
        (SocketPath -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile SocketPath
localNodeSocketPath)
   where
    versionedProtocls :: Versions
  NodeToClientVersion
  NodeToClientVersionData
  (OuroborosApplicationWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void)
versionedProtocls =
      -- First convert from the mode-parametrised view of things to the
      -- block-parametrised view and then do the final setup for the versioned
      -- bundles of mini-protocols.
      case ConsensusModeParams
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode)
-> LocalNodeClientParams
mkLocalNodeClientParams ConsensusModeParams
localConsensusModeParams NodeToClientVersion -> LocalNodeClientProtocolsInMode
clients of
        LocalNodeClientParamsSingleBlock ProtocolClientInfoArgs block
ptcl NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
clients' ->
          NetworkId
-> ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
forall block.
(ShowQuery (Query block), ProtocolClient block) =>
NetworkId
-> ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
mkVersionedProtocols NetworkId
localNodeNetworkId ProtocolClientInfoArgs block
ptcl NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
clients'
        LocalNodeClientParamsCardano ProtocolClientInfoArgs block
ptcl NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
clients' ->
          NetworkId
-> ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
forall block.
(ShowQuery (Query block), ProtocolClient block) =>
NetworkId
-> ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
mkVersionedProtocols NetworkId
localNodeNetworkId ProtocolClientInfoArgs block
ptcl NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
clients'

mkVersionedProtocols
  :: forall block
   . ( Consensus.ShowQuery (Consensus.Query block)
     , ProtocolClient block
     )
  => NetworkId
  -> ProtocolClientInfoArgs block
  -> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
  -> Net.Versions
      Net.NodeToClientVersion
      Net.NodeToClientVersionData
      ( Net.OuroborosApplicationWithMinimalCtx
          Net.InitiatorMode
          Net.LocalAddress
          LBS.ByteString
          IO
          ()
          Void
      )
mkVersionedProtocols :: forall block.
(ShowQuery (Query block), ProtocolClient block) =>
NetworkId
-> ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
mkVersionedProtocols NetworkId
networkid ProtocolClientInfoArgs block
ptcl NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
unversionedClients =
  -- TODO: really we should construct specific combinations of
  -- protocols for the versions we know about, with different protocol
  -- versions taking different sets of typed client protocols.
  ((NodeToClientVersion, BlockNodeToClientVersion block)
 -> Versions
      NodeToClientVersion
      NodeToClientVersionData
      (OuroborosApplicationWithMinimalCtx
         'InitiatorMode LocalAddress ByteString IO () Void))
-> [(NodeToClientVersion, BlockNodeToClientVersion block)]
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
forall vNum (f :: * -> *) x extra r.
(Ord vNum, Foldable f, HasCallStack) =>
(x -> Versions vNum extra r) -> f x -> Versions vNum extra r
Net.foldMapVersions
    ( \(NodeToClientVersion
ptclVersion, BlockNodeToClientVersion block
ptclBlockVersion) ->
        NodeToClientVersion
-> NodeToClientVersionData
-> NodeToClientProtocols
     'InitiatorMode LocalAddress ByteString IO () Void
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO () Void)
forall (appType :: MuxMode) bytes (m :: * -> *) a b.
NodeToClientVersion
-> NodeToClientVersionData
-> NodeToClientProtocols appType LocalAddress bytes m a b
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        appType LocalAddress bytes m a b)
Net.versionedNodeToClientProtocols
          NodeToClientVersion
ptclVersion
          NodeToClientVersionData
            { networkMagic :: NetworkMagic
networkMagic = NetworkId -> NetworkMagic
toNetworkMagic NetworkId
networkid
            , query :: Bool
query = Bool
False
            }
          (LocalNodeClientProtocolsForBlock block
-> BlockNodeToClientVersion block
-> NodeToClientVersion
-> NodeToClientProtocols
     'InitiatorMode LocalAddress ByteString IO () Void
protocols (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block
unversionedClients NodeToClientVersion
ptclVersion) BlockNodeToClientVersion block
ptclBlockVersion NodeToClientVersion
ptclVersion)
    )
    (Map NodeToClientVersion (BlockNodeToClientVersion block)
-> [Item
      (Map NodeToClientVersion (BlockNodeToClientVersion block))]
forall l. IsList l => l -> [Item l]
toList (Proxy block
-> Map NodeToClientVersion (BlockNodeToClientVersion block)
forall blk.
SupportedNetworkProtocolVersion blk =>
Proxy blk -> Map NodeToClientVersion (BlockNodeToClientVersion blk)
Consensus.supportedNodeToClientVersions Proxy block
proxy))
 where
  proxy :: Proxy block
  proxy :: Proxy block
proxy = Proxy block
forall {k} (t :: k). Proxy t
Proxy

  protocols
    :: LocalNodeClientProtocolsForBlock block
    -> Consensus.BlockNodeToClientVersion block
    -> NodeToClientVersion
    -> NodeToClientProtocols Net.InitiatorMode Net.LocalAddress LBS.ByteString IO () Void
  protocols :: LocalNodeClientProtocolsForBlock block
-> BlockNodeToClientVersion block
-> NodeToClientVersion
-> NodeToClientProtocols
     'InitiatorMode LocalAddress ByteString IO () Void
protocols
    LocalNodeClientProtocolsForBlock
      { LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock :: LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock :: forall block.
LocalNodeClientProtocolsForBlock block
-> LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock
      , Maybe
  (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock :: Maybe
  (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock :: forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock
      , Maybe
  (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock :: Maybe
  (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock :: forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock
      , Maybe
  (LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock :: Maybe
  (LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock :: forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalTxMonitorClient
        (TxId (GenTx block)) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock
      }
    BlockNodeToClientVersion block
ptclBlockVersion
    NodeToClientVersion
ptclVersion =
      NodeToClientProtocols
        { localChainSyncProtocol :: RunMiniProtocolWithMinimalCtx
  'InitiatorMode LocalAddress ByteString IO () Void
localChainSyncProtocol =
            MiniProtocolCb
  (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall initiatorCtx bytes (m :: * -> *) a responderCtx.
MiniProtocolCb initiatorCtx bytes m a
-> RunMiniProtocol
     'InitiatorMode initiatorCtx responderCtx bytes m a Void
Net.InitiatorProtocolOnly (MiniProtocolCb
   (MinimalInitiatorContext LocalAddress) ByteString IO ()
 -> RunMiniProtocolWithMinimalCtx
      'InitiatorMode LocalAddress ByteString IO () Void)
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall a b. (a -> b) -> a -> b
$ case LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock of
              LocalChainSyncClient block (Point block) (Tip block) IO
NoLocalChainSyncClient ->
                (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
     Codec
       (ChainSync block (Point block) (Tip block))
       DeserialiseFailure
       IO
       ByteString,
     Peer
       (ChainSync block (Point block) (Tip block))
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure bytes ctx
       (m :: * -> *) a.
(MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     Peer ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeer ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
      Codec
        (ChainSync block (Point block) (Tip block))
        DeserialiseFailure
        IO
        ByteString,
      Peer
        (ChainSync block (Point block) (Tip block))
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
        Codec
          (ChainSync block (Point block) (Tip block))
          DeserialiseFailure
          IO
          ByteString,
        Peer
          (ChainSync block (Point block) (Tip block))
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                  (Tracer
   IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
 Codec
   (ChainSync block (Point block) (Tip block))
   DeserialiseFailure
   IO
   ByteString,
 Peer
   (ChainSync block (Point block) (Tip block))
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
    Codec
      (ChainSync block (Point block) (Tip block))
      DeserialiseFailure
      IO
      ByteString,
    Peer
      (ChainSync block (Point block) (Tip block))
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                    (Tracer
  IO (TraceSendRecv (ChainSync block (Point block) (Tip block)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer, Codec
  (ChainSync block (Point block) (Tip block))
  DeserialiseFailure
  IO
  ByteString
cChainSyncCodec, Peer
  (ChainSync block (Point block) (Tip block)) 'AsClient 'StIdle IO ()
forall header point tip (m :: * -> *) a.
MonadDelay m =>
Peer (ChainSync header point tip) 'AsClient 'StIdle m a
Net.chainSyncPeerNull)
              LocalChainSyncClient ChainSyncClient block (Point block) (Tip block) IO ()
client ->
                (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
     Codec
       (ChainSync block (Point block) (Tip block))
       DeserialiseFailure
       IO
       ByteString,
     Peer
       (ChainSync block (Point block) (Tip block))
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure bytes ctx
       (m :: * -> *) a.
(MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     Peer ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeer ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
      Codec
        (ChainSync block (Point block) (Tip block))
        DeserialiseFailure
        IO
        ByteString,
      Peer
        (ChainSync block (Point block) (Tip block))
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
        Codec
          (ChainSync block (Point block) (Tip block))
          DeserialiseFailure
          IO
          ByteString,
        Peer
          (ChainSync block (Point block) (Tip block))
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                  (Tracer
   IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
 Codec
   (ChainSync block (Point block) (Tip block))
   DeserialiseFailure
   IO
   ByteString,
 Peer
   (ChainSync block (Point block) (Tip block))
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
    Codec
      (ChainSync block (Point block) (Tip block))
      DeserialiseFailure
      IO
      ByteString,
    Peer
      (ChainSync block (Point block) (Tip block))
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                    (Tracer
  IO (TraceSendRecv (ChainSync block (Point block) (Tip block)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer, Codec
  (ChainSync block (Point block) (Tip block))
  DeserialiseFailure
  IO
  ByteString
cChainSyncCodec, ChainSyncClient block (Point block) (Tip block) IO ()
-> Peer
     (ChainSync block (Point block) (Tip block)) 'AsClient 'StIdle IO ()
forall header point tip (m :: * -> *) a.
Monad m =>
ChainSyncClient header point tip m a
-> Peer (ChainSync header point tip) 'AsClient 'StIdle m a
Net.Sync.chainSyncClientPeer ChainSyncClient block (Point block) (Tip block) IO ()
client)
              LocalChainSyncClientPipelined ChainSyncClientPipelined block (Point block) (Tip block) IO ()
clientPipelined ->
                (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
     Codec
       (ChainSync block (Point block) (Tip block))
       DeserialiseFailure
       IO
       ByteString,
     PeerPipelined
       (ChainSync block (Point block) (Tip block))
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure ctx bytes
       (m :: * -> *) a.
(MonadAsync m, MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     PeerPipelined ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeerPipelined ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
      Codec
        (ChainSync block (Point block) (Tip block))
        DeserialiseFailure
        IO
        ByteString,
      PeerPipelined
        (ChainSync block (Point block) (Tip block))
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
        Codec
          (ChainSync block (Point block) (Tip block))
          DeserialiseFailure
          IO
          ByteString,
        PeerPipelined
          (ChainSync block (Point block) (Tip block))
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                  (Tracer
   IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
 Codec
   (ChainSync block (Point block) (Tip block))
   DeserialiseFailure
   IO
   ByteString,
 PeerPipelined
   (ChainSync block (Point block) (Tip block))
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO (TraceSendRecv (ChainSync block (Point block) (Tip block))),
    Codec
      (ChainSync block (Point block) (Tip block))
      DeserialiseFailure
      IO
      ByteString,
    PeerPipelined
      (ChainSync block (Point block) (Tip block))
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                    (Tracer
  IO (TraceSendRecv (ChainSync block (Point block) (Tip block)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer, Codec
  (ChainSync block (Point block) (Tip block))
  DeserialiseFailure
  IO
  ByteString
cChainSyncCodec, ChainSyncClientPipelined block (Point block) (Tip block) IO ()
-> PeerPipelined
     (ChainSync block (Point block) (Tip block)) 'AsClient 'StIdle IO ()
forall header point tip (m :: * -> *) a.
Monad m =>
ChainSyncClientPipelined header point tip m a
-> PeerPipelined (ChainSync header point tip) 'AsClient 'StIdle m a
Net.SyncP.chainSyncClientPeerPipelined ChainSyncClientPipelined block (Point block) (Tip block) IO ()
clientPipelined)
        , localTxSubmissionProtocol :: RunMiniProtocolWithMinimalCtx
  'InitiatorMode LocalAddress ByteString IO () Void
localTxSubmissionProtocol =
            MiniProtocolCb
  (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall initiatorCtx bytes (m :: * -> *) a responderCtx.
MiniProtocolCb initiatorCtx bytes m a
-> RunMiniProtocol
     'InitiatorMode initiatorCtx responderCtx bytes m a Void
Net.InitiatorProtocolOnly (MiniProtocolCb
   (MinimalInitiatorContext LocalAddress) ByteString IO ()
 -> RunMiniProtocolWithMinimalCtx
      'InitiatorMode LocalAddress ByteString IO () Void)
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall a b. (a -> b) -> a -> b
$
              (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO
       (TraceSendRecv
          (LocalTxSubmission (GenTx block) (ApplyTxErr block))),
     Codec
       (LocalTxSubmission (GenTx block) (ApplyTxErr block))
       DeserialiseFailure
       IO
       ByteString,
     Peer
       (LocalTxSubmission (GenTx block) (ApplyTxErr block))
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure bytes ctx
       (m :: * -> *) a.
(MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     Peer ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeer ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO
        (TraceSendRecv
           (LocalTxSubmission (GenTx block) (ApplyTxErr block))),
      Codec
        (LocalTxSubmission (GenTx block) (ApplyTxErr block))
        DeserialiseFailure
        IO
        ByteString,
      Peer
        (LocalTxSubmission (GenTx block) (ApplyTxErr block))
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO
          (TraceSendRecv
             (LocalTxSubmission (GenTx block) (ApplyTxErr block))),
        Codec
          (LocalTxSubmission (GenTx block) (ApplyTxErr block))
          DeserialiseFailure
          IO
          ByteString,
        Peer
          (LocalTxSubmission (GenTx block) (ApplyTxErr block))
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                (Tracer
   IO
   (TraceSendRecv
      (LocalTxSubmission (GenTx block) (ApplyTxErr block))),
 Codec
   (LocalTxSubmission (GenTx block) (ApplyTxErr block))
   DeserialiseFailure
   IO
   ByteString,
 Peer
   (LocalTxSubmission (GenTx block) (ApplyTxErr block))
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO
      (TraceSendRecv
         (LocalTxSubmission (GenTx block) (ApplyTxErr block))),
    Codec
      (LocalTxSubmission (GenTx block) (ApplyTxErr block))
      DeserialiseFailure
      IO
      ByteString,
    Peer
      (LocalTxSubmission (GenTx block) (ApplyTxErr block))
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                  ( Tracer
  IO
  (TraceSendRecv
     (LocalTxSubmission (GenTx block) (ApplyTxErr block)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
                  , Codec
  (LocalTxSubmission (GenTx block) (ApplyTxErr block))
  DeserialiseFailure
  IO
  ByteString
cTxSubmissionCodec
                  , Peer
  (LocalTxSubmission (GenTx block) (ApplyTxErr block))
  'AsClient
  'StIdle
  IO
  ()
-> (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ()
    -> Peer
         (LocalTxSubmission (GenTx block) (ApplyTxErr block))
         'AsClient
         'StIdle
         IO
         ())
-> Maybe
     (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
-> Peer
     (LocalTxSubmission (GenTx block) (ApplyTxErr block))
     'AsClient
     'StIdle
     IO
     ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                      Peer
  (LocalTxSubmission (GenTx block) (ApplyTxErr block))
  'AsClient
  'StIdle
  IO
  ()
forall tx reject (m :: * -> *) a.
MonadDelay m =>
Peer (LocalTxSubmission tx reject) 'AsClient 'StIdle m a
Net.localTxSubmissionPeerNull
                      LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ()
-> Peer
     (LocalTxSubmission (GenTx block) (ApplyTxErr block))
     'AsClient
     'StIdle
     IO
     ()
forall tx reject (m :: * -> *) a.
Monad m =>
LocalTxSubmissionClient tx reject m a
-> Peer (LocalTxSubmission tx reject) 'AsClient 'StIdle m a
Net.Tx.localTxSubmissionClientPeer
                      Maybe
  (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock
                  )
        , localStateQueryProtocol :: RunMiniProtocolWithMinimalCtx
  'InitiatorMode LocalAddress ByteString IO () Void
localStateQueryProtocol =
            MiniProtocolCb
  (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall initiatorCtx bytes (m :: * -> *) a responderCtx.
MiniProtocolCb initiatorCtx bytes m a
-> RunMiniProtocol
     'InitiatorMode initiatorCtx responderCtx bytes m a Void
Net.InitiatorProtocolOnly (MiniProtocolCb
   (MinimalInitiatorContext LocalAddress) ByteString IO ()
 -> RunMiniProtocolWithMinimalCtx
      'InitiatorMode LocalAddress ByteString IO () Void)
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall a b. (a -> b) -> a -> b
$
              (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO
       (TraceSendRecv
          (LocalStateQuery block (Point block) (Query block))),
     Codec
       (LocalStateQuery block (Point block) (Query block))
       DeserialiseFailure
       IO
       ByteString,
     Peer
       (LocalStateQuery block (Point block) (Query block))
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure bytes ctx
       (m :: * -> *) a.
(MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     Peer ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeer ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO
        (TraceSendRecv
           (LocalStateQuery block (Point block) (Query block))),
      Codec
        (LocalStateQuery block (Point block) (Query block))
        DeserialiseFailure
        IO
        ByteString,
      Peer
        (LocalStateQuery block (Point block) (Query block))
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO
          (TraceSendRecv
             (LocalStateQuery block (Point block) (Query block))),
        Codec
          (LocalStateQuery block (Point block) (Query block))
          DeserialiseFailure
          IO
          ByteString,
        Peer
          (LocalStateQuery block (Point block) (Query block))
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                (Tracer
   IO
   (TraceSendRecv
      (LocalStateQuery block (Point block) (Query block))),
 Codec
   (LocalStateQuery block (Point block) (Query block))
   DeserialiseFailure
   IO
   ByteString,
 Peer
   (LocalStateQuery block (Point block) (Query block))
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO
      (TraceSendRecv
         (LocalStateQuery block (Point block) (Query block))),
    Codec
      (LocalStateQuery block (Point block) (Query block))
      DeserialiseFailure
      IO
      ByteString,
    Peer
      (LocalStateQuery block (Point block) (Query block))
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                  ( Tracer
  IO
  (TraceSendRecv (LocalStateQuery block (Point block) (Query block)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
                  , Codec
  (LocalStateQuery block (Point block) (Query block))
  DeserialiseFailure
  IO
  ByteString
cStateQueryCodec
                  , Peer
  (LocalStateQuery block (Point block) (Query block))
  'AsClient
  'StIdle
  IO
  ()
-> (LocalStateQueryClient block (Point block) (Query block) IO ()
    -> Peer
         (LocalStateQuery block (Point block) (Query block))
         'AsClient
         'StIdle
         IO
         ())
-> Maybe
     (LocalStateQueryClient block (Point block) (Query block) IO ())
-> Peer
     (LocalStateQuery block (Point block) (Query block))
     'AsClient
     'StIdle
     IO
     ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                      Peer
  (LocalStateQuery block (Point block) (Query block))
  'AsClient
  'StIdle
  IO
  ()
forall block point (query :: * -> *) (m :: * -> *) a.
MonadDelay m =>
Peer (LocalStateQuery block point query) 'AsClient 'StIdle m a
Net.localStateQueryPeerNull
                      LocalStateQueryClient block (Point block) (Query block) IO ()
-> Peer
     (LocalStateQuery block (Point block) (Query block))
     'AsClient
     'StIdle
     IO
     ()
forall block point (query :: * -> *) (m :: * -> *) a.
Monad m =>
LocalStateQueryClient block point query m a
-> Peer (LocalStateQuery block point query) 'AsClient 'StIdle m a
Net.Query.localStateQueryClientPeer
                      Maybe
  (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock
                  )
        , localTxMonitorProtocol :: RunMiniProtocolWithMinimalCtx
  'InitiatorMode LocalAddress ByteString IO () Void
localTxMonitorProtocol =
            MiniProtocolCb
  (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall initiatorCtx bytes (m :: * -> *) a responderCtx.
MiniProtocolCb initiatorCtx bytes m a
-> RunMiniProtocol
     'InitiatorMode initiatorCtx responderCtx bytes m a Void
Net.InitiatorProtocolOnly (MiniProtocolCb
   (MinimalInitiatorContext LocalAddress) ByteString IO ()
 -> RunMiniProtocolWithMinimalCtx
      'InitiatorMode LocalAddress ByteString IO () Void)
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
-> RunMiniProtocolWithMinimalCtx
     'InitiatorMode LocalAddress ByteString IO () Void
forall a b. (a -> b) -> a -> b
$
              (MinimalInitiatorContext LocalAddress
 -> (Tracer
       IO
       (TraceSendRecv
          (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)),
     Codec
       (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
       DeserialiseFailure
       IO
       ByteString,
     Peer
       (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
       'AsClient
       'StIdle
       IO
       ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall (pr :: PeerRole) ps (st :: ps) failure bytes ctx
       (m :: * -> *) a.
(MonadThrow m, Show failure,
 forall (st' :: ps). Show (ClientHasAgency st'),
 forall (st' :: ps). Show (ServerHasAgency st'), ShowProxy ps) =>
(ctx
 -> (Tracer m (TraceSendRecv ps), Codec ps failure m bytes,
     Peer ps pr st m a))
-> MiniProtocolCb ctx bytes m a
Net.mkMiniProtocolCbFromPeer ((MinimalInitiatorContext LocalAddress
  -> (Tracer
        IO
        (TraceSendRecv
           (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)),
      Codec
        (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
        DeserialiseFailure
        IO
        ByteString,
      Peer
        (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
        'AsClient
        'StIdle
        IO
        ()))
 -> MiniProtocolCb
      (MinimalInitiatorContext LocalAddress) ByteString IO ())
-> (MinimalInitiatorContext LocalAddress
    -> (Tracer
          IO
          (TraceSendRecv
             (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)),
        Codec
          (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
          DeserialiseFailure
          IO
          ByteString,
        Peer
          (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
          'AsClient
          'StIdle
          IO
          ()))
-> MiniProtocolCb
     (MinimalInitiatorContext LocalAddress) ByteString IO ()
forall a b. (a -> b) -> a -> b
$
                (Tracer
   IO
   (TraceSendRecv
      (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)),
 Codec
   (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
   DeserialiseFailure
   IO
   ByteString,
 Peer
   (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
   'AsClient
   'StIdle
   IO
   ())
-> MinimalInitiatorContext LocalAddress
-> (Tracer
      IO
      (TraceSendRecv
         (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)),
    Codec
      (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
      DeserialiseFailure
      IO
      ByteString,
    Peer
      (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
      'AsClient
      'StIdle
      IO
      ())
forall a b. a -> b -> a
const
                  ( Tracer
  IO
  (TraceSendRecv
     (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
                  , Codec
  (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
  DeserialiseFailure
  IO
  ByteString
cTxMonitorCodec
                  , Peer
  (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
  'AsClient
  'StIdle
  IO
  ()
-> (LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ()
    -> Peer
         (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
         'AsClient
         'StIdle
         IO
         ())
-> Maybe
     (LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ())
-> Peer
     (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
     'AsClient
     'StIdle
     IO
     ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                      Peer
  (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
  'AsClient
  'StIdle
  IO
  ()
forall txid tx slot (m :: * -> *) a.
MonadDelay m =>
Peer (LocalTxMonitor txid tx slot) 'AsClient 'StIdle m a
Net.localTxMonitorPeerNull
                      LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ()
-> Peer
     (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
     'AsClient
     'StIdle
     IO
     ()
forall txid tx slot (m :: * -> *) a.
Monad m =>
LocalTxMonitorClient txid tx slot m a
-> Peer (LocalTxMonitor txid tx slot) 'AsClient 'StIdle m a
localTxMonitorClientPeer
                      Maybe
  (LocalTxMonitorClient (GenTxId block) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock
                  )
        }
     where
      Consensus.Codecs
        { Codec
  (ChainSync block (Point block) (Tip block))
  DeserialiseFailure
  IO
  ByteString
cChainSyncCodec :: Codec
  (ChainSync block (Point block) (Tip block))
  DeserialiseFailure
  IO
  ByteString
cChainSyncCodec :: forall blk serialisedBlk e (m :: * -> *) bCS bTX bSQ bTM.
Codecs' blk serialisedBlk e m bCS bTX bSQ bTM
-> Codec (ChainSync serialisedBlk (Point blk) (Tip blk)) e m bCS
Consensus.cChainSyncCodec
        , Codec
  (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
  DeserialiseFailure
  IO
  ByteString
cTxMonitorCodec :: Codec
  (LocalTxMonitor (GenTxId block) (GenTx block) SlotNo)
  DeserialiseFailure
  IO
  ByteString
cTxMonitorCodec :: forall blk serialisedBlk e (m :: * -> *) bCS bTX bSQ bTM.
Codecs' blk serialisedBlk e m bCS bTX bSQ bTM
-> Codec (LocalTxMonitor (GenTxId blk) (GenTx blk) SlotNo) e m bTM
Consensus.cTxMonitorCodec
        , Codec
  (LocalTxSubmission (GenTx block) (ApplyTxErr block))
  DeserialiseFailure
  IO
  ByteString
cTxSubmissionCodec :: Codec
  (LocalTxSubmission (GenTx block) (ApplyTxErr block))
  DeserialiseFailure
  IO
  ByteString
cTxSubmissionCodec :: forall blk serialisedBlk e (m :: * -> *) bCS bTX bSQ bTM.
Codecs' blk serialisedBlk e m bCS bTX bSQ bTM
-> Codec (LocalTxSubmission (GenTx blk) (ApplyTxErr blk)) e m bTX
Consensus.cTxSubmissionCodec
        , Codec
  (LocalStateQuery block (Point block) (Query block))
  DeserialiseFailure
  IO
  ByteString
cStateQueryCodec :: Codec
  (LocalStateQuery block (Point block) (Query block))
  DeserialiseFailure
  IO
  ByteString
cStateQueryCodec :: forall blk serialisedBlk e (m :: * -> *) bCS bTX bSQ bTM.
Codecs' blk serialisedBlk e m bCS bTX bSQ bTM
-> Codec (LocalStateQuery blk (Point blk) (Query blk)) e m bSQ
Consensus.cStateQueryCodec
        } = CodecConfig block
-> BlockNodeToClientVersion block
-> NodeToClientVersion
-> Codecs'
     block
     block
     DeserialiseFailure
     IO
     ByteString
     ByteString
     ByteString
     ByteString
forall (m :: * -> *) blk.
(MonadST m, SerialiseNodeToClientConstraints blk,
 ShowQuery (BlockQuery blk), StandardHash blk,
 Serialise (HeaderHash blk)) =>
CodecConfig blk
-> BlockNodeToClientVersion blk
-> NodeToClientVersion
-> ClientCodecs blk m
Consensus.clientCodecs CodecConfig block
codecConfig BlockNodeToClientVersion block
ptclBlockVersion NodeToClientVersion
ptclVersion

  codecConfig :: Consensus.CodecConfig block
  codecConfig :: CodecConfig block
codecConfig =
    ProtocolClientInfo block -> CodecConfig block
forall b. ProtocolClientInfo b -> CodecConfig b
Consensus.pClientInfoCodecConfig
      (ProtocolClientInfoArgs block -> ProtocolClientInfo block
forall blk.
ProtocolClient blk =>
ProtocolClientInfoArgs blk -> ProtocolClientInfo blk
protocolClientInfo ProtocolClientInfoArgs block
ptcl)

-- | This type defines the boundary between the mode-parametrised style used in
-- this API and the block-parametrised style used by the underlying network
-- and consensus libraries.
--
-- This interface itself is in the block-parametrised style, with the block
-- type itself being an hidden\/existential type.
--
-- It bundles together all the necessary class instances, the consensus
-- protocol client identifier, and the set of client side mini-protocol
-- handlers for the node-to-client protocol.
data LocalNodeClientParams where
  LocalNodeClientParamsSingleBlock
    :: ( ProtocolClient block
       , Consensus.LedgerSupportsProtocol
          ( Consensus.ShelleyBlock
              (Consensus.TPraos Consensus.StandardCrypto)
              (Consensus.ShelleyEra Consensus.StandardCrypto)
          )
       )
    => ProtocolClientInfoArgs block
    -> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
    -> LocalNodeClientParams
  LocalNodeClientParamsCardano
    :: (ProtocolClient block, CardanoHardForkConstraints (ConsensusCryptoForBlock block))
    => ProtocolClientInfoArgs block
    -> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
    -> LocalNodeClientParams

data LocalNodeClientProtocolsForBlock block
  = LocalNodeClientProtocolsForBlock
  { forall block.
LocalNodeClientProtocolsForBlock block
-> LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock
      :: LocalChainSyncClient
          block
          (Consensus.Point block)
          (Net.Tip block)
          IO
  , forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock
      :: Maybe
          ( LocalStateQueryClient
              block
              (Consensus.Point block)
              (Consensus.Query block)
              IO
              ()
          )
  , forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock
      :: Maybe
          ( LocalTxSubmissionClient
              (Consensus.GenTx block)
              (Consensus.ApplyTxErr block)
              IO
              ()
          )
  , forall block.
LocalNodeClientProtocolsForBlock block
-> Maybe
     (LocalTxMonitorClient
        (TxId (GenTx block)) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock
      :: Maybe
          ( LocalTxMonitorClient
              (Consensus.TxId (Consensus.GenTx block))
              (Consensus.GenTx block)
              SlotNo
              IO
              ()
          )
  }

-- | Convert from the mode-parametrised style to the block-parametrised style.
mkLocalNodeClientParams
  :: ConsensusModeParams
  -> (NodeToClientVersion -> LocalNodeClientProtocolsInMode)
  -> LocalNodeClientParams
mkLocalNodeClientParams :: ConsensusModeParams
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode)
-> LocalNodeClientParams
mkLocalNodeClientParams ConsensusModeParams
modeparams NodeToClientVersion -> LocalNodeClientProtocolsInMode
clients =
  -- For each of the possible consensus modes we pick the concrete block type
  -- (by picking the appropriate 'ProtocolClient' value).
  --
  -- Though it is not immediately visible, this point where we use
  -- 'LocalNodeClientParams' is also where we pick up the necessary class
  -- instances. This works because in each case we have a monomorphic block
  -- type and the instances are all in scope. This is why the use of
  -- LocalNodeClientParams is repeated within each branch of the case:
  -- because it is only within each branch that the GADT match makes the
  -- block type monomorphic.
  --
  case ConsensusModeParams
modeparams of
    CardanoModeParams EpochSlots
epochSlots ->
      ProtocolClientInfoArgs (CardanoBlock StandardCrypto)
-> (NodeToClientVersion
    -> LocalNodeClientProtocolsForBlock (CardanoBlock StandardCrypto))
-> LocalNodeClientParams
forall block.
(ProtocolClient block,
 CardanoHardForkConstraints (ConsensusCryptoForBlock block)) =>
ProtocolClientInfoArgs block
-> (NodeToClientVersion -> LocalNodeClientProtocolsForBlock block)
-> LocalNodeClientParams
LocalNodeClientParamsCardano
        (EpochSlots -> ProtocolClientInfoArgs (CardanoBlock StandardCrypto)
ProtocolClientInfoArgsCardano EpochSlots
epochSlots)
        (LocalNodeClientProtocolsInMode
-> LocalNodeClientProtocolsForBlock (CardanoBlock StandardCrypto)
forall block.
(CardanoBlock StandardCrypto ~ block) =>
LocalNodeClientProtocolsInMode
-> LocalNodeClientProtocolsForBlock block
convLocalNodeClientProtocols (LocalNodeClientProtocolsInMode
 -> LocalNodeClientProtocolsForBlock (CardanoBlock StandardCrypto))
-> (NodeToClientVersion -> LocalNodeClientProtocolsInMode)
-> NodeToClientVersion
-> LocalNodeClientProtocolsForBlock (CardanoBlock StandardCrypto)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeToClientVersion -> LocalNodeClientProtocolsInMode
clients)

convLocalNodeClientProtocols
  :: ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => LocalNodeClientProtocolsInMode
  -> LocalNodeClientProtocolsForBlock block
convLocalNodeClientProtocols :: forall block.
(CardanoBlock StandardCrypto ~ block) =>
LocalNodeClientProtocolsInMode
-> LocalNodeClientProtocolsForBlock block
convLocalNodeClientProtocols
  LocalNodeClientProtocols
    { LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient :: forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> LocalChainSyncClient block point tip m
localChainSyncClient :: LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient
    , Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient :: forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalTxSubmissionClient tx txerr m ())
localTxSubmissionClient :: Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient
    , Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient :: forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalStateQueryClient block point query m ())
localStateQueryClient :: Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient
    , Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient :: forall block point tip slot tx txid txerr (query :: * -> *)
       (m :: * -> *).
LocalNodeClientProtocols block point tip slot tx txid txerr query m
-> Maybe (LocalTxMonitorClient txid tx slot m ())
localTxMonitoringClient :: Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient
    } =
    LocalNodeClientProtocolsForBlock
      { localChainSyncClientForBlock :: LocalChainSyncClient block (Point block) (Tip block) IO
localChainSyncClientForBlock = case LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient of
          LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
NoLocalChainSyncClient -> LocalChainSyncClient block (Point block) (Tip block) IO
forall block point tip (m :: * -> *).
LocalChainSyncClient block point tip m
NoLocalChainSyncClient
          LocalChainSyncClientPipelined ChainSyncClientPipelined BlockInMode ChainPoint ChainTip IO ()
clientPipelined -> ChainSyncClientPipelined block (Point block) (Tip block) IO ()
-> LocalChainSyncClient block (Point block) (Tip block) IO
forall block point tip (m :: * -> *).
ChainSyncClientPipelined block point tip m ()
-> LocalChainSyncClient block point tip m
LocalChainSyncClientPipelined (ChainSyncClientPipelined block (Point block) (Tip block) IO ()
 -> LocalChainSyncClient block (Point block) (Tip block) IO)
-> ChainSyncClientPipelined block (Point block) (Tip block) IO ()
-> LocalChainSyncClient block (Point block) (Tip block) IO
forall a b. (a -> b) -> a -> b
$ ChainSyncClientPipelined BlockInMode ChainPoint ChainTip IO ()
-> ChainSyncClientPipelined block (Point block) (Tip block) IO ()
forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
-> ChainSyncClientPipelined block (Point block) (Tip block) m a
convLocalChainSyncClientPipelined ChainSyncClientPipelined BlockInMode ChainPoint ChainTip IO ()
clientPipelined
          LocalChainSyncClient ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
client -> ChainSyncClient block (Point block) (Tip block) IO ()
-> LocalChainSyncClient block (Point block) (Tip block) IO
forall block point tip (m :: * -> *).
ChainSyncClient block point tip m ()
-> LocalChainSyncClient block point tip m
LocalChainSyncClient (ChainSyncClient block (Point block) (Tip block) IO ()
 -> LocalChainSyncClient block (Point block) (Tip block) IO)
-> ChainSyncClient block (Point block) (Tip block) IO ()
-> LocalChainSyncClient block (Point block) (Tip block) IO
forall a b. (a -> b) -> a -> b
$ ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
-> ChainSyncClient block (Point block) (Tip block) IO ()
forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
ChainSyncClient BlockInMode ChainPoint ChainTip m a
-> ChainSyncClient block (Point block) (Tip block) m a
convLocalChainSyncClient ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
client
      , localTxSubmissionClientForBlock :: Maybe
  (LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) IO ())
localTxSubmissionClientForBlock = LocalTxSubmissionClient
  TxInMode TxValidationErrorInCardanoMode IO ()
-> LocalTxSubmissionClient
     (GenTx (CardanoBlock StandardCrypto))
     (ApplyTxErr (CardanoBlock StandardCrypto))
     IO
     ()
LocalTxSubmissionClient
  TxInMode TxValidationErrorInCardanoMode IO ()
-> LocalTxSubmissionClient
     (GenTx (CardanoBlock StandardCrypto))
     (HardForkApplyTxErr
        (ByronBlock : CardanoShelleyEras StandardCrypto))
     IO
     ()
forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalTxSubmissionClient TxInMode TxValidationErrorInCardanoMode m a
-> LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) m a
convLocalTxSubmissionClient (LocalTxSubmissionClient
   TxInMode TxValidationErrorInCardanoMode IO ()
 -> LocalTxSubmissionClient
      (GenTx (CardanoBlock StandardCrypto))
      (HardForkApplyTxErr
         (ByronBlock : CardanoShelleyEras StandardCrypto))
      IO
      ())
-> Maybe
     (LocalTxSubmissionClient
        TxInMode TxValidationErrorInCardanoMode IO ())
-> Maybe
     (LocalTxSubmissionClient
        (GenTx (CardanoBlock StandardCrypto))
        (HardForkApplyTxErr
           (ByronBlock : CardanoShelleyEras StandardCrypto))
        IO
        ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient
      , localStateQueryClientForBlock :: Maybe
  (LocalStateQueryClient block (Point block) (Query block) IO ())
localStateQueryClientForBlock = LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
-> LocalStateQueryClient block (Point block) (Query block) IO ()
forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalStateQueryClient BlockInMode ChainPoint QueryInMode m a
-> LocalStateQueryClient block (Point block) (Query block) m a
convLocalStateQueryClient (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
 -> LocalStateQueryClient block (Point block) (Query block) IO ())
-> Maybe
     (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
-> Maybe
     (LocalStateQueryClient block (Point block) (Query block) IO ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient
      , localTxMonitoringClientForBlock :: Maybe
  (LocalTxMonitorClient
     (TxId (GenTx block)) (GenTx block) SlotNo IO ())
localTxMonitoringClientForBlock = LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
-> LocalTxMonitorClient
     (TxId (GenTx block)) (GenTx block) SlotNo IO ()
forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalTxMonitorClient TxIdInMode TxInMode SlotNo m a
-> LocalTxMonitorClient
     (TxId (GenTx block)) (GenTx block) SlotNo m a
convLocalTxMonitoringClient (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
 -> LocalTxMonitorClient
      (TxId (GenTx block)) (GenTx block) SlotNo IO ())
-> Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
-> Maybe
     (LocalTxMonitorClient
        (TxId (GenTx block)) (GenTx block) SlotNo IO ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient
      }

convLocalTxMonitoringClient
  :: forall block m a
   . ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => Functor m
  => LocalTxMonitorClient TxIdInMode TxInMode SlotNo m a
  -> LocalTxMonitorClient (Consensus.TxId (Consensus.GenTx block)) (Consensus.GenTx block) SlotNo m a
convLocalTxMonitoringClient :: forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalTxMonitorClient TxIdInMode TxInMode SlotNo m a
-> LocalTxMonitorClient
     (TxId (GenTx block)) (GenTx block) SlotNo m a
convLocalTxMonitoringClient =
  (TxIdInMode -> TxId (GenTx block))
-> (GenTx block -> TxInMode)
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo m a
-> LocalTxMonitorClient
     (TxId (GenTx block)) (GenTx block) SlotNo m a
forall txid txid' tx tx' (m :: * -> *) a.
Functor m =>
(txid -> txid')
-> (tx' -> tx)
-> LocalTxMonitorClient txid tx SlotNo m a
-> LocalTxMonitorClient txid' tx' SlotNo m a
mapLocalTxMonitoringClient
    TxIdInMode -> TxId (GenTx block)
forall block.
(CardanoBlock StandardCrypto ~ block) =>
TxIdInMode -> TxId (GenTx block)
toConsensusTxId
    GenTx block -> TxInMode
forall block.
(CardanoBlock StandardCrypto ~ block) =>
GenTx block -> TxInMode
fromConsensusGenTx

convLocalChainSyncClient
  :: forall block m a
   . ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => Functor m
  => ChainSyncClient BlockInMode ChainPoint ChainTip m a
  -> ChainSyncClient block (Net.Point block) (Net.Tip block) m a
convLocalChainSyncClient :: forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
ChainSyncClient BlockInMode ChainPoint ChainTip m a
-> ChainSyncClient block (Point block) (Tip block) m a
convLocalChainSyncClient =
  (ChainPoint -> Point block)
-> (Point block -> ChainPoint)
-> (block -> BlockInMode)
-> (Tip block -> ChainTip)
-> ChainSyncClient BlockInMode ChainPoint ChainTip m a
-> ChainSyncClient block (Point block) (Tip block) m a
forall header header' point point' tip tip' (m :: * -> *) a.
Functor m =>
(point -> point')
-> (point' -> point)
-> (header' -> header)
-> (tip' -> tip)
-> ChainSyncClient header point tip m a
-> ChainSyncClient header' point' tip' m a
Net.Sync.mapChainSyncClient
    ChainPoint -> Point block
forall block (xs :: [*]).
(HeaderHash block ~ OneEraHash xs) =>
ChainPoint -> Point block
toConsensusPointHF
    Point block -> ChainPoint
forall block (xs :: [*]).
(HeaderHash block ~ OneEraHash xs) =>
Point block -> ChainPoint
fromConsensusPointHF
    block -> BlockInMode
forall block.
(CardanoBlock StandardCrypto ~ block) =>
block -> BlockInMode
fromConsensusBlock
    Tip block -> ChainTip
forall block.
(CardanoBlock StandardCrypto ~ block) =>
Tip block -> ChainTip
fromConsensusTip

convLocalChainSyncClientPipelined
  :: forall block m a
   . ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => Functor m
  => ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
  -> ChainSyncClientPipelined block (Net.Point block) (Net.Tip block) m a
convLocalChainSyncClientPipelined :: forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
-> ChainSyncClientPipelined block (Point block) (Tip block) m a
convLocalChainSyncClientPipelined =
  (ChainPoint -> Point block)
-> (Point block -> ChainPoint)
-> (block -> BlockInMode)
-> (Tip block -> ChainTip)
-> ChainSyncClientPipelined BlockInMode ChainPoint ChainTip m a
-> ChainSyncClientPipelined block (Point block) (Tip block) m a
forall header header' point point' tip tip' (m :: * -> *) a.
Functor m =>
(point -> point')
-> (point' -> point)
-> (header' -> header)
-> (tip' -> tip)
-> ChainSyncClientPipelined header point tip m a
-> ChainSyncClientPipelined header' point' tip' m a
mapChainSyncClientPipelined
    ChainPoint -> Point block
forall block (xs :: [*]).
(HeaderHash block ~ OneEraHash xs) =>
ChainPoint -> Point block
toConsensusPointHF
    Point block -> ChainPoint
forall block (xs :: [*]).
(HeaderHash block ~ OneEraHash xs) =>
Point block -> ChainPoint
fromConsensusPointHF
    block -> BlockInMode
forall block.
(CardanoBlock StandardCrypto ~ block) =>
block -> BlockInMode
fromConsensusBlock
    Tip block -> ChainTip
forall block.
(CardanoBlock StandardCrypto ~ block) =>
Tip block -> ChainTip
fromConsensusTip

convLocalTxSubmissionClient
  :: forall block m a
   . ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => Functor m
  => LocalTxSubmissionClient TxInMode TxValidationErrorInCardanoMode m a
  -> LocalTxSubmissionClient (Consensus.GenTx block) (Consensus.ApplyTxErr block) m a
convLocalTxSubmissionClient :: forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalTxSubmissionClient TxInMode TxValidationErrorInCardanoMode m a
-> LocalTxSubmissionClient (GenTx block) (ApplyTxErr block) m a
convLocalTxSubmissionClient =
  (TxInMode -> GenTx block)
-> (HardForkApplyTxErr
      (ByronBlock : CardanoShelleyEras StandardCrypto)
    -> TxValidationErrorInCardanoMode)
-> LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode m a
-> LocalTxSubmissionClient
     (GenTx block)
     (HardForkApplyTxErr
        (ByronBlock : CardanoShelleyEras StandardCrypto))
     m
     a
forall tx tx' reject reject' (m :: * -> *) a.
Functor m =>
(tx -> tx')
-> (reject' -> reject)
-> LocalTxSubmissionClient tx reject m a
-> LocalTxSubmissionClient tx' reject' m a
Net.Tx.mapLocalTxSubmissionClient TxInMode -> GenTx block
forall block.
(CardanoBlock StandardCrypto ~ block) =>
TxInMode -> GenTx block
toConsensusGenTx ApplyTxErr (CardanoBlock StandardCrypto)
-> TxValidationErrorInCardanoMode
HardForkApplyTxErr (ByronBlock : CardanoShelleyEras StandardCrypto)
-> TxValidationErrorInCardanoMode
forall block.
(CardanoBlock StandardCrypto ~ block) =>
ApplyTxErr block -> TxValidationErrorInCardanoMode
fromConsensusApplyTxErr

convLocalStateQueryClient
  :: forall block m a
   . ()
  => Consensus.CardanoBlock L.StandardCrypto ~ block
  => Functor m
  => LocalStateQueryClient BlockInMode ChainPoint QueryInMode m a
  -> LocalStateQueryClient block (Consensus.Point block) (Consensus.Query block) m a
convLocalStateQueryClient :: forall block (m :: * -> *) a.
(CardanoBlock StandardCrypto ~ block, Functor m) =>
LocalStateQueryClient BlockInMode ChainPoint QueryInMode m a
-> LocalStateQueryClient block (Point block) (Query block) m a
convLocalStateQueryClient =
  (ChainPoint -> Point block)
-> (forall result. QueryInMode result -> Some (Query block))
-> (forall result result'.
    QueryInMode result -> Query block result' -> result' -> result)
-> LocalStateQueryClient BlockInMode ChainPoint QueryInMode m a
-> LocalStateQueryClient block (Point block) (Query block) m a
forall block block' point point' (query :: * -> *)
       (query' :: * -> *) (m :: * -> *) a.
Functor m =>
(point -> point')
-> (forall result. query result -> Some query')
-> (forall result result'.
    query result -> query' result' -> result' -> result)
-> LocalStateQueryClient block point query m a
-> LocalStateQueryClient block' point' query' m a
Net.Query.mapLocalStateQueryClient
    ChainPoint -> Point block
forall block (xs :: [*]).
(HeaderHash block ~ OneEraHash xs) =>
ChainPoint -> Point block
toConsensusPointHF
    QueryInMode result -> Some (Query block)
forall result. QueryInMode result -> Some (Query block)
forall block result.
(CardanoBlock StandardCrypto ~ block) =>
QueryInMode result -> Some (Query block)
toConsensusQuery
    QueryInMode result -> Query block result' -> result' -> result
forall result result'.
QueryInMode result -> Query block result' -> result' -> result
forall block result result'.
(HasCallStack, CardanoBlock StandardCrypto ~ block) =>
QueryInMode result -> Query block result' -> result' -> result
fromConsensusQueryResult

-- TODO: Move to consensus
mapLocalTxMonitoringClient
  :: forall txid txid' tx tx' m a
   . ()
  => Functor m
  => (txid -> txid')
  -> (tx' -> tx)
  -> LocalTxMonitorClient txid tx SlotNo m a
  -> LocalTxMonitorClient txid' tx' SlotNo m a
mapLocalTxMonitoringClient :: forall txid txid' tx tx' (m :: * -> *) a.
Functor m =>
(txid -> txid')
-> (tx' -> tx)
-> LocalTxMonitorClient txid tx SlotNo m a
-> LocalTxMonitorClient txid' tx' SlotNo m a
mapLocalTxMonitoringClient txid -> txid'
convTxid tx' -> tx
convTx LocalTxMonitorClient txid tx SlotNo m a
ltxmc =
  let LocalTxMonitorClient m (ClientStIdle txid tx SlotNo m a)
idleEff = LocalTxMonitorClient txid tx SlotNo m a
ltxmc
   in m (ClientStIdle txid' tx' SlotNo m a)
-> LocalTxMonitorClient txid' tx' SlotNo m a
forall txid tx slot (m :: * -> *) a.
m (ClientStIdle txid tx slot m a)
-> LocalTxMonitorClient txid tx slot m a
LocalTxMonitorClient ((ClientStIdle txid tx SlotNo m a
 -> ClientStIdle txid' tx' SlotNo m a)
-> m (ClientStIdle txid tx SlotNo m a)
-> m (ClientStIdle txid' tx' SlotNo m a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ClientStIdle txid tx SlotNo m a
-> ClientStIdle txid' tx' SlotNo m a
convClientStateIdle m (ClientStIdle txid tx SlotNo m a)
idleEff)
 where
  convClientStateIdle
    :: CTxMon.ClientStIdle txid tx SlotNo m a
    -> CTxMon.ClientStIdle txid' tx' SlotNo m a
  convClientStateIdle :: ClientStIdle txid tx SlotNo m a
-> ClientStIdle txid' tx' SlotNo m a
convClientStateIdle (CTxMon.SendMsgAcquire SlotNo -> m (ClientStAcquired txid tx SlotNo m a)
f) =
    (SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStIdle txid' tx' SlotNo m a
forall slot (m :: * -> *) txid tx a.
(slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStIdle txid tx slot m a
CTxMon.SendMsgAcquire ((SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> ClientStIdle txid' tx' SlotNo m a)
-> (SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStIdle txid' tx' SlotNo m a
forall a b. (a -> b) -> a -> b
$ ((m (ClientStAcquired txid tx SlotNo m a)
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
-> SlotNo
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> (SlotNo -> a) -> SlotNo -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((m (ClientStAcquired txid tx SlotNo m a)
  -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
 -> SlotNo
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ((ClientStAcquired txid tx SlotNo m a
     -> ClientStAcquired txid' tx' SlotNo m a)
    -> m (ClientStAcquired txid tx SlotNo m a)
    -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (ClientStAcquired txid tx SlotNo m a
    -> ClientStAcquired txid' tx' SlotNo m a)
-> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
-> SlotNo
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClientStAcquired txid tx SlotNo m a
 -> ClientStAcquired txid' tx' SlotNo m a)
-> m (ClientStAcquired txid tx SlotNo m a)
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired SlotNo -> m (ClientStAcquired txid tx SlotNo m a)
f
  convClientStateIdle (CTxMon.SendMsgDone a
a) = a -> ClientStIdle txid' tx' SlotNo m a
forall a txid tx slot (m :: * -> *).
a -> ClientStIdle txid tx slot m a
CTxMon.SendMsgDone a
a

  convClientStateAcquired
    :: CTxMon.ClientStAcquired txid tx SlotNo m a
    -> CTxMon.ClientStAcquired txid' tx' SlotNo m a
  convClientStateAcquired :: ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired (CTxMon.SendMsgNextTx Maybe tx -> m (ClientStAcquired txid tx SlotNo m a)
f) =
    (Maybe tx' -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall tx (m :: * -> *) txid slot a.
(Maybe tx -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgNextTx (\Maybe tx'
mTx -> ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired (ClientStAcquired txid tx SlotNo m a
 -> ClientStAcquired txid' tx' SlotNo m a)
-> m (ClientStAcquired txid tx SlotNo m a)
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe tx -> m (ClientStAcquired txid tx SlotNo m a)
f (tx' -> tx
convTx (tx' -> tx) -> Maybe tx' -> Maybe tx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe tx'
mTx))
  convClientStateAcquired (CTxMon.SendMsgHasTx txid
txid Bool -> m (ClientStAcquired txid tx SlotNo m a)
f) =
    txid'
-> (Bool -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall txid (m :: * -> *) tx slot a.
txid
-> (Bool -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgHasTx (txid -> txid'
convTxid txid
txid) (((m (ClientStAcquired txid tx SlotNo m a)
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (Bool -> m (ClientStAcquired txid tx SlotNo m a))
-> Bool
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> (Bool -> a) -> Bool -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((m (ClientStAcquired txid tx SlotNo m a)
  -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> (Bool -> m (ClientStAcquired txid tx SlotNo m a))
 -> Bool
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ((ClientStAcquired txid tx SlotNo m a
     -> ClientStAcquired txid' tx' SlotNo m a)
    -> m (ClientStAcquired txid tx SlotNo m a)
    -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (ClientStAcquired txid tx SlotNo m a
    -> ClientStAcquired txid' tx' SlotNo m a)
-> (Bool -> m (ClientStAcquired txid tx SlotNo m a))
-> Bool
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClientStAcquired txid tx SlotNo m a
 -> ClientStAcquired txid' tx' SlotNo m a)
-> m (ClientStAcquired txid tx SlotNo m a)
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired Bool -> m (ClientStAcquired txid tx SlotNo m a)
f)
  convClientStateAcquired (CTxMon.SendMsgGetSizes MempoolSizeAndCapacity -> m (ClientStAcquired txid tx SlotNo m a)
f) =
    (MempoolSizeAndCapacity
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall (m :: * -> *) txid tx slot a.
(MempoolSizeAndCapacity -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgGetSizes ((MempoolSizeAndCapacity
  -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> ClientStAcquired txid' tx' SlotNo m a)
-> (MempoolSizeAndCapacity
    -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall a b. (a -> b) -> a -> b
$ ((m (ClientStAcquired txid tx SlotNo m a)
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (MempoolSizeAndCapacity
    -> m (ClientStAcquired txid tx SlotNo m a))
-> MempoolSizeAndCapacity
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b.
(a -> b)
-> (MempoolSizeAndCapacity -> a) -> MempoolSizeAndCapacity -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((m (ClientStAcquired txid tx SlotNo m a)
  -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> (MempoolSizeAndCapacity
     -> m (ClientStAcquired txid tx SlotNo m a))
 -> MempoolSizeAndCapacity
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ((ClientStAcquired txid tx SlotNo m a
     -> ClientStAcquired txid' tx' SlotNo m a)
    -> m (ClientStAcquired txid tx SlotNo m a)
    -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (ClientStAcquired txid tx SlotNo m a
    -> ClientStAcquired txid' tx' SlotNo m a)
-> (MempoolSizeAndCapacity
    -> m (ClientStAcquired txid tx SlotNo m a))
-> MempoolSizeAndCapacity
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClientStAcquired txid tx SlotNo m a
 -> ClientStAcquired txid' tx' SlotNo m a)
-> m (ClientStAcquired txid tx SlotNo m a)
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired MempoolSizeAndCapacity -> m (ClientStAcquired txid tx SlotNo m a)
f
  convClientStateAcquired (CTxMon.SendMsgAwaitAcquire SlotNo -> m (ClientStAcquired txid tx SlotNo m a)
f) =
    (SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall slot (m :: * -> *) txid tx a.
(slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgAwaitAcquire ((SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> ClientStAcquired txid' tx' SlotNo m a)
-> (SlotNo -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ClientStAcquired txid' tx' SlotNo m a
forall a b. (a -> b) -> a -> b
$ ((m (ClientStAcquired txid tx SlotNo m a)
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
-> SlotNo
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> (SlotNo -> a) -> SlotNo -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((m (ClientStAcquired txid tx SlotNo m a)
  -> m (ClientStAcquired txid' tx' SlotNo m a))
 -> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
 -> SlotNo
 -> m (ClientStAcquired txid' tx' SlotNo m a))
-> ((ClientStAcquired txid tx SlotNo m a
     -> ClientStAcquired txid' tx' SlotNo m a)
    -> m (ClientStAcquired txid tx SlotNo m a)
    -> m (ClientStAcquired txid' tx' SlotNo m a))
-> (ClientStAcquired txid tx SlotNo m a
    -> ClientStAcquired txid' tx' SlotNo m a)
-> (SlotNo -> m (ClientStAcquired txid tx SlotNo m a))
-> SlotNo
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClientStAcquired txid tx SlotNo m a
 -> ClientStAcquired txid' tx' SlotNo m a)
-> m (ClientStAcquired txid tx SlotNo m a)
-> m (ClientStAcquired txid' tx' SlotNo m a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) ClientStAcquired txid tx SlotNo m a
-> ClientStAcquired txid' tx' SlotNo m a
convClientStateAcquired SlotNo -> m (ClientStAcquired txid tx SlotNo m a)
f
  convClientStateAcquired (CTxMon.SendMsgRelease m (ClientStIdle txid tx SlotNo m a)
eff) =
    m (ClientStIdle txid' tx' SlotNo m a)
-> ClientStAcquired txid' tx' SlotNo m a
forall (m :: * -> *) txid tx slot a.
m (ClientStIdle txid tx slot m a)
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgRelease (ClientStIdle txid tx SlotNo m a
-> ClientStIdle txid' tx' SlotNo m a
convClientStateIdle (ClientStIdle txid tx SlotNo m a
 -> ClientStIdle txid' tx' SlotNo m a)
-> m (ClientStIdle txid tx SlotNo m a)
-> m (ClientStIdle txid' tx' SlotNo m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (ClientStIdle txid tx SlotNo m a)
eff)

-- ----------------------------------------------------------------------------
-- Wrappers for specific protocol use-cases
--

-- TODO: change this query to be just a protocol client handler to be used with
-- connectToLocalNode. This would involve changing connectToLocalNode to be
-- able to return protocol handler results properly.

-- | Establish a connection to a node and execute a single query using the
-- local state query protocol.
data AcquiringFailure
  = AFPointTooOld
  | AFPointNotOnChain
  deriving (AcquiringFailure -> AcquiringFailure -> Bool
(AcquiringFailure -> AcquiringFailure -> Bool)
-> (AcquiringFailure -> AcquiringFailure -> Bool)
-> Eq AcquiringFailure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AcquiringFailure -> AcquiringFailure -> Bool
== :: AcquiringFailure -> AcquiringFailure -> Bool
$c/= :: AcquiringFailure -> AcquiringFailure -> Bool
/= :: AcquiringFailure -> AcquiringFailure -> Bool
Eq, Int -> AcquiringFailure -> ShowS
[AcquiringFailure] -> ShowS
AcquiringFailure -> FilePath
(Int -> AcquiringFailure -> ShowS)
-> (AcquiringFailure -> FilePath)
-> ([AcquiringFailure] -> ShowS)
-> Show AcquiringFailure
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AcquiringFailure -> ShowS
showsPrec :: Int -> AcquiringFailure -> ShowS
$cshow :: AcquiringFailure -> FilePath
show :: AcquiringFailure -> FilePath
$cshowList :: [AcquiringFailure] -> ShowS
showList :: [AcquiringFailure] -> ShowS
Show)

toAcquiringFailure :: Net.Query.AcquireFailure -> AcquiringFailure
toAcquiringFailure :: AcquireFailure -> AcquiringFailure
toAcquiringFailure AcquireFailure
AcquireFailurePointTooOld = AcquiringFailure
AFPointTooOld
toAcquiringFailure AcquireFailure
AcquireFailurePointNotOnChain = AcquiringFailure
AFPointNotOnChain

queryNodeLocalState
  :: forall result
   . ()
  => LocalNodeConnectInfo
  -> Net.Query.Target ChainPoint
  -> QueryInMode result
  -> ExceptT AcquiringFailure IO result
queryNodeLocalState :: forall result.
LocalNodeConnectInfo
-> Target ChainPoint
-> QueryInMode result
-> ExceptT AcquiringFailure IO result
queryNodeLocalState LocalNodeConnectInfo
connctInfo Target ChainPoint
mpoint QueryInMode result
query = do
  TMVar (Either AcquiringFailure result)
resultVar <- IO (TMVar (Either AcquiringFailure result))
-> ExceptT
     AcquiringFailure IO (TMVar (Either AcquiringFailure result))
forall a. IO a -> ExceptT AcquiringFailure IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (TMVar (Either AcquiringFailure result))
forall a. IO (TMVar a)
newEmptyTMVarIO
  LocalNodeConnectInfo
-> LocalNodeClientProtocolsInMode -> ExceptT AcquiringFailure IO ()
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
connectToLocalNode
    LocalNodeConnectInfo
connctInfo
    LocalNodeClientProtocols
      { localChainSyncClient :: LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient = LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
forall block point tip (m :: * -> *).
LocalChainSyncClient block point tip m
NoLocalChainSyncClient
      , localStateQueryClient :: Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient = LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
-> Maybe
     (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> Maybe a
Just (Target ChainPoint
-> TMVar (Either AcquiringFailure result)
-> LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
singleQuery Target ChainPoint
mpoint TMVar (Either AcquiringFailure result)
resultVar)
      , localTxSubmissionClient :: Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient = Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
forall a. Maybe a
Nothing
      , localTxMonitoringClient :: Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient = Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
forall a. Maybe a
Nothing
      }
  IO (Either AcquiringFailure result)
-> ExceptT AcquiringFailure IO result
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (IO (Either AcquiringFailure result)
 -> ExceptT AcquiringFailure IO result)
-> IO (Either AcquiringFailure result)
-> ExceptT AcquiringFailure IO result
forall a b. (a -> b) -> a -> b
$ STM (Either AcquiringFailure result)
-> IO (Either AcquiringFailure result)
forall a. STM a -> IO a
atomically (TMVar (Either AcquiringFailure result)
-> STM (Either AcquiringFailure result)
forall a. TMVar a -> STM a
takeTMVar TMVar (Either AcquiringFailure result)
resultVar)
 where
  singleQuery
    :: Net.Query.Target ChainPoint
    -> TMVar (Either AcquiringFailure result)
    -> Net.Query.LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
  singleQuery :: Target ChainPoint
-> TMVar (Either AcquiringFailure result)
-> LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
singleQuery Target ChainPoint
mPointVar' TMVar (Either AcquiringFailure result)
resultVar' =
    IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
-> LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
forall block point (query :: * -> *) (m :: * -> *) a.
m (ClientStIdle block point query m a)
-> LocalStateQueryClient block point query m a
LocalStateQueryClient (IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
 -> LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
-> LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ()
forall a b. (a -> b) -> a -> b
$ do
      ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
 -> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()))
-> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a b. (a -> b) -> a -> b
$
        Target ChainPoint
-> ClientStAcquiring BlockInMode ChainPoint QueryInMode IO ()
-> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
forall point block (query :: * -> *) (m :: * -> *) a.
Target point
-> ClientStAcquiring block point query m a
-> ClientStIdle block point query m a
Net.Query.SendMsgAcquire Target ChainPoint
mPointVar' (ClientStAcquiring BlockInMode ChainPoint QueryInMode IO ()
 -> ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
-> ClientStAcquiring BlockInMode ChainPoint QueryInMode IO ()
-> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
forall a b. (a -> b) -> a -> b
$
          Net.Query.ClientStAcquiring
            { recvMsgAcquired :: IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
Net.Query.recvMsgAcquired =
                ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
 -> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()))
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
forall a b. (a -> b) -> a -> b
$
                  QueryInMode result
-> ClientStQuerying BlockInMode ChainPoint QueryInMode IO () result
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
forall (query :: * -> *) result block point (m :: * -> *) a.
query result
-> ClientStQuerying block point query m a result
-> ClientStAcquired block point query m a
Net.Query.SendMsgQuery QueryInMode result
query (ClientStQuerying BlockInMode ChainPoint QueryInMode IO () result
 -> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
-> ClientStQuerying BlockInMode ChainPoint QueryInMode IO () result
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
forall a b. (a -> b) -> a -> b
$
                    Net.Query.ClientStQuerying
                      { recvMsgResult :: result
-> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
Net.Query.recvMsgResult = \result
result -> do
                          STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TMVar (Either AcquiringFailure result)
-> Either AcquiringFailure result -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar (Either AcquiringFailure result)
resultVar' (result -> Either AcquiringFailure result
forall a b. b -> Either a b
Right result
result)

                          ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
 -> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()))
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
forall a b. (a -> b) -> a -> b
$
                            IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
forall (m :: * -> *) block point (query :: * -> *) a.
m (ClientStIdle block point query m a)
-> ClientStAcquired block point query m a
Net.Query.SendMsgRelease (IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
 -> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ())
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
-> ClientStAcquired BlockInMode ChainPoint QueryInMode IO ()
forall a b. (a -> b) -> a -> b
$
                              ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
 -> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()))
-> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a b. (a -> b) -> a -> b
$
                                () -> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
forall a block point (query :: * -> *) (m :: * -> *).
a -> ClientStIdle block point query m a
Net.Query.SendMsgDone ()
                      }
            , recvMsgFailure :: AcquireFailure
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
Net.Query.recvMsgFailure = \AcquireFailure
failure -> do
                STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TMVar (Either AcquiringFailure result)
-> Either AcquiringFailure result -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar (Either AcquiringFailure result)
resultVar' (AcquiringFailure -> Either AcquiringFailure result
forall a b. a -> Either a b
Left (AcquireFailure -> AcquiringFailure
toAcquiringFailure AcquireFailure
failure))
                ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
 -> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ()))
-> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
-> IO (ClientStIdle BlockInMode ChainPoint QueryInMode IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle BlockInMode ChainPoint QueryInMode IO ()
forall a block point (query :: * -> *) (m :: * -> *).
a -> ClientStIdle block point query m a
Net.Query.SendMsgDone ()
            }

submitTxToNodeLocal
  :: MonadIO m
  => LocalNodeConnectInfo
  -> TxInMode
  -> m (Net.Tx.SubmitResult TxValidationErrorInCardanoMode)
submitTxToNodeLocal :: forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo
-> TxInMode -> m (SubmitResult TxValidationErrorInCardanoMode)
submitTxToNodeLocal LocalNodeConnectInfo
connctInfo TxInMode
tx = do
  TMVar (SubmitResult TxValidationErrorInCardanoMode)
resultVar <- IO (TMVar (SubmitResult TxValidationErrorInCardanoMode))
-> m (TMVar (SubmitResult TxValidationErrorInCardanoMode))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (TMVar (SubmitResult TxValidationErrorInCardanoMode))
forall a. IO (TMVar a)
newEmptyTMVarIO
  LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
connectToLocalNode
    LocalNodeConnectInfo
connctInfo
    LocalNodeClientProtocols
      { localChainSyncClient :: LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient = LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
forall block point tip (m :: * -> *).
LocalChainSyncClient block point tip m
NoLocalChainSyncClient
      , localTxSubmissionClient :: Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient = LocalTxSubmissionClient
  TxInMode TxValidationErrorInCardanoMode IO ()
-> Maybe
     (LocalTxSubmissionClient
        TxInMode TxValidationErrorInCardanoMode IO ())
forall a. a -> Maybe a
Just (TMVar (SubmitResult TxValidationErrorInCardanoMode)
-> LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ()
localTxSubmissionClientSingle TMVar (SubmitResult TxValidationErrorInCardanoMode)
resultVar)
      , localStateQueryClient :: Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient = Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
forall a. Maybe a
Nothing
      , localTxMonitoringClient :: Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient = Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
forall a. Maybe a
Nothing
      }
  IO (SubmitResult TxValidationErrorInCardanoMode)
-> m (SubmitResult TxValidationErrorInCardanoMode)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (SubmitResult TxValidationErrorInCardanoMode)
 -> m (SubmitResult TxValidationErrorInCardanoMode))
-> IO (SubmitResult TxValidationErrorInCardanoMode)
-> m (SubmitResult TxValidationErrorInCardanoMode)
forall a b. (a -> b) -> a -> b
$ STM (SubmitResult TxValidationErrorInCardanoMode)
-> IO (SubmitResult TxValidationErrorInCardanoMode)
forall a. STM a -> IO a
atomically (TMVar (SubmitResult TxValidationErrorInCardanoMode)
-> STM (SubmitResult TxValidationErrorInCardanoMode)
forall a. TMVar a -> STM a
takeTMVar TMVar (SubmitResult TxValidationErrorInCardanoMode)
resultVar)
 where
  localTxSubmissionClientSingle
    :: ()
    => TMVar (Net.Tx.SubmitResult TxValidationErrorInCardanoMode)
    -> Net.Tx.LocalTxSubmissionClient TxInMode TxValidationErrorInCardanoMode IO ()
  localTxSubmissionClientSingle :: TMVar (SubmitResult TxValidationErrorInCardanoMode)
-> LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ()
localTxSubmissionClientSingle TMVar (SubmitResult TxValidationErrorInCardanoMode)
resultVar =
    IO
  (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
-> LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ()
forall tx reject (m :: * -> *) a.
m (LocalTxClientStIdle tx reject m a)
-> LocalTxSubmissionClient tx reject m a
LocalTxSubmissionClient (IO
   (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
 -> LocalTxSubmissionClient
      TxInMode TxValidationErrorInCardanoMode IO ())
-> IO
     (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
-> LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ()
forall a b. (a -> b) -> a -> b
$
      LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ()
-> IO
     (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ()
 -> IO
      (LocalTxClientStIdle
         TxInMode TxValidationErrorInCardanoMode IO ()))
-> LocalTxClientStIdle
     TxInMode TxValidationErrorInCardanoMode IO ()
-> IO
     (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
forall a b. (a -> b) -> a -> b
$
        TxInMode
-> (SubmitResult TxValidationErrorInCardanoMode
    -> IO
         (LocalTxClientStIdle
            TxInMode TxValidationErrorInCardanoMode IO ()))
-> LocalTxClientStIdle
     TxInMode TxValidationErrorInCardanoMode IO ()
forall tx reject (m :: * -> *) a.
tx
-> (SubmitResult reject -> m (LocalTxClientStIdle tx reject m a))
-> LocalTxClientStIdle tx reject m a
Net.Tx.SendMsgSubmitTx TxInMode
tx ((SubmitResult TxValidationErrorInCardanoMode
  -> IO
       (LocalTxClientStIdle
          TxInMode TxValidationErrorInCardanoMode IO ()))
 -> LocalTxClientStIdle
      TxInMode TxValidationErrorInCardanoMode IO ())
-> (SubmitResult TxValidationErrorInCardanoMode
    -> IO
         (LocalTxClientStIdle
            TxInMode TxValidationErrorInCardanoMode IO ()))
-> LocalTxClientStIdle
     TxInMode TxValidationErrorInCardanoMode IO ()
forall a b. (a -> b) -> a -> b
$ \SubmitResult TxValidationErrorInCardanoMode
result -> do
          STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TMVar (SubmitResult TxValidationErrorInCardanoMode)
-> SubmitResult TxValidationErrorInCardanoMode -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar (SubmitResult TxValidationErrorInCardanoMode)
resultVar SubmitResult TxValidationErrorInCardanoMode
result
          LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ()
-> IO
     (LocalTxClientStIdle TxInMode TxValidationErrorInCardanoMode IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (()
-> LocalTxClientStIdle
     TxInMode TxValidationErrorInCardanoMode IO ()
forall a tx reject (m :: * -> *).
a -> LocalTxClientStIdle tx reject m a
Net.Tx.SendMsgDone ())

data LocalTxMonitoringResult
  = -- | Slot number at which the mempool snapshot was taken
    LocalTxMonitoringTxExists
      TxId
      SlotNo
  | -- | Slot number at which the mempool snapshot was taken
    LocalTxMonitoringTxDoesNotExist
      TxId
      SlotNo
  | -- | Slot number at which the mempool snapshot was taken
    LocalTxMonitoringNextTx
      (Maybe TxInMode)
      SlotNo
  | -- | Slot number at which the mempool snapshot was taken
    LocalTxMonitoringMempoolSizeAndCapacity
      Consensus.MempoolSizeAndCapacity
      SlotNo

instance ToJSON LocalTxMonitoringResult where
  toJSON :: LocalTxMonitoringResult -> Value
toJSON LocalTxMonitoringResult
result =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ case LocalTxMonitoringResult
result of
      LocalTxMonitoringTxExists TxId
tx SlotNo
slot ->
        [ Key
"exists" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
True
        , Key
"txId" Key -> TxId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxId
tx
        , Key
"slot" Key -> SlotNo -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SlotNo
slot
        ]
      LocalTxMonitoringTxDoesNotExist TxId
tx SlotNo
slot ->
        [ Key
"exists" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
False
        , Key
"txId" Key -> TxId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxId
tx
        , Key
"slot" Key -> SlotNo -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SlotNo
slot
        ]
      LocalTxMonitoringNextTx Maybe TxInMode
txInMode SlotNo
slot ->
        [ Key
"nextTx" Key -> Maybe TxId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe TxId
txId
        , Key
"slot" Key -> SlotNo -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SlotNo
slot
        ]
       where
        txId :: Maybe TxId
txId = case Maybe TxInMode
txInMode of
          Just (TxInMode ShelleyBasedEra era
_ Tx era
tx) -> TxId -> Maybe TxId
forall a. a -> Maybe a
Just (TxId -> Maybe TxId) -> TxId -> Maybe TxId
forall a b. (a -> b) -> a -> b
$ TxBody era -> TxId
forall era. TxBody era -> TxId
getTxId (TxBody era -> TxId) -> TxBody era -> TxId
forall a b. (a -> b) -> a -> b
$ Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
tx
          -- TODO: support fetching the ID of a Byron Era transaction
          Maybe TxInMode
_ -> Maybe TxId
forall a. Maybe a
Nothing
      LocalTxMonitoringMempoolSizeAndCapacity MempoolSizeAndCapacity
mempool SlotNo
slot ->
        [ Key
"capacityInBytes" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= MempoolSizeAndCapacity -> Word32
Consensus.capacityInBytes MempoolSizeAndCapacity
mempool
        , Key
"sizeInBytes" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= MempoolSizeAndCapacity -> Word32
Consensus.sizeInBytes MempoolSizeAndCapacity
mempool
        , Key
"numberOfTxs" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= MempoolSizeAndCapacity -> Word32
Consensus.numberOfTxs MempoolSizeAndCapacity
mempool
        , Key
"slot" Key -> SlotNo -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SlotNo
slot
        ]

data LocalTxMonitoringQuery
  = -- | Query if a particular tx exists in the mempool. Note that, the absence
    -- of a transaction does not imply anything about how the transaction was
    -- processed: it may have been dropped, or inserted in a block.
    LocalTxMonitoringQueryTx TxIdInMode
  | -- | The mempool is modeled as an ordered list of transactions and thus, can
    -- be traversed linearly. 'LocalTxMonitoringSendNextTx' requests the next transaction from the
    -- current list. This must be a transaction that was not previously sent to
    -- the client for this particular snapshot.
    LocalTxMonitoringSendNextTx
  | -- | Ask the server about the current mempool's capacity and sizes. This is
    -- fixed in a given snapshot.
    LocalTxMonitoringMempoolInformation

queryTxMonitoringLocal
  :: MonadIO m
  => LocalNodeConnectInfo
  -> LocalTxMonitoringQuery
  -> m LocalTxMonitoringResult
queryTxMonitoringLocal :: forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo
-> LocalTxMonitoringQuery -> m LocalTxMonitoringResult
queryTxMonitoringLocal LocalNodeConnectInfo
connectInfo LocalTxMonitoringQuery
localTxMonitoringQuery = do
  TMVar LocalTxMonitoringResult
resultVar <- IO (TMVar LocalTxMonitoringResult)
-> m (TMVar LocalTxMonitoringResult)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (TMVar LocalTxMonitoringResult)
forall a. IO (TMVar a)
newEmptyTMVarIO

  let client :: LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
client = case LocalTxMonitoringQuery
localTxMonitoringQuery of
        LocalTxMonitoringQueryTx TxIdInMode
txidInMode ->
          TxIdInMode
-> TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorClientTxExists TxIdInMode
txidInMode TMVar LocalTxMonitoringResult
resultVar
        LocalTxMonitoringQuery
LocalTxMonitoringSendNextTx ->
          TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorNextTx TMVar LocalTxMonitoringResult
resultVar
        LocalTxMonitoringQuery
LocalTxMonitoringMempoolInformation ->
          TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorMempoolInfo TMVar LocalTxMonitoringResult
resultVar

  LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
connectToLocalNode
    LocalNodeConnectInfo
connectInfo
    LocalNodeClientProtocols
      { localChainSyncClient :: LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient = LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
forall block point tip (m :: * -> *).
LocalChainSyncClient block point tip m
NoLocalChainSyncClient
      , localTxSubmissionClient :: Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient = Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
forall a. Maybe a
Nothing
      , localStateQueryClient :: Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient = Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
forall a. Maybe a
Nothing
      , localTxMonitoringClient :: Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient = LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
-> Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
forall a. a -> Maybe a
Just LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
client
      }
  IO LocalTxMonitoringResult -> m LocalTxMonitoringResult
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO LocalTxMonitoringResult -> m LocalTxMonitoringResult)
-> IO LocalTxMonitoringResult -> m LocalTxMonitoringResult
forall a b. (a -> b) -> a -> b
$ STM LocalTxMonitoringResult -> IO LocalTxMonitoringResult
forall a. STM a -> IO a
atomically (TMVar LocalTxMonitoringResult -> STM LocalTxMonitoringResult
forall a. TMVar a -> STM a
takeTMVar TMVar LocalTxMonitoringResult
resultVar)
 where
  localTxMonitorClientTxExists
    :: ()
    => TxIdInMode
    -> TMVar LocalTxMonitoringResult
    -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
  localTxMonitorClientTxExists :: TxIdInMode
-> TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorClientTxExists tIdInMode :: TxIdInMode
tIdInMode@(TxIdInMode CardanoEra era
_ TxId
txid) TMVar LocalTxMonitoringResult
resultVar = do
    IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall txid tx slot (m :: * -> *) a.
m (ClientStIdle txid tx slot m a)
-> LocalTxMonitorClient txid tx slot m a
LocalTxMonitorClient (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$
      ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$
        (SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall slot (m :: * -> *) txid tx a.
(slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStIdle txid tx slot m a
CTxMon.SendMsgAcquire ((SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> (SlotNo
    -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \SlotNo
slt -> do
          ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ TxIdInMode
-> (Bool -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall txid (m :: * -> *) tx slot a.
txid
-> (Bool -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgHasTx TxIdInMode
tIdInMode ((Bool -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> (Bool -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \Bool
txPresentBool -> do
            if Bool
txPresentBool
              then STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ())
-> (LocalTxMonitoringResult -> STM ())
-> LocalTxMonitoringResult
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TMVar LocalTxMonitoringResult -> LocalTxMonitoringResult -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar LocalTxMonitoringResult
resultVar (LocalTxMonitoringResult -> IO ())
-> LocalTxMonitoringResult -> IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> SlotNo -> LocalTxMonitoringResult
LocalTxMonitoringTxExists TxId
txid SlotNo
slt
              else STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ())
-> (LocalTxMonitoringResult -> STM ())
-> LocalTxMonitoringResult
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TMVar LocalTxMonitoringResult -> LocalTxMonitoringResult -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar LocalTxMonitoringResult
resultVar (LocalTxMonitoringResult -> IO ())
-> LocalTxMonitoringResult -> IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> SlotNo -> LocalTxMonitoringResult
LocalTxMonitoringTxDoesNotExist TxId
txid SlotNo
slt
            ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall (m :: * -> *) txid tx slot a.
m (ClientStIdle txid tx slot m a)
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgRelease (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a txid tx slot (m :: * -> *).
a -> ClientStIdle txid tx slot m a
CTxMon.SendMsgDone ()

  localTxMonitorNextTx
    :: ()
    => TMVar LocalTxMonitoringResult
    -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
  localTxMonitorNextTx :: TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorNextTx TMVar LocalTxMonitoringResult
resultVar =
    IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall txid tx slot (m :: * -> *) a.
m (ClientStIdle txid tx slot m a)
-> LocalTxMonitorClient txid tx slot m a
LocalTxMonitorClient (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ do
      (SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall slot (m :: * -> *) txid tx a.
(slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStIdle txid tx slot m a
CTxMon.SendMsgAcquire ((SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> (SlotNo
    -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \SlotNo
slt -> do
        ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ (Maybe TxInMode
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall tx (m :: * -> *) txid slot a.
(Maybe tx -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgNextTx ((Maybe TxInMode
  -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> (Maybe TxInMode
    -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \Maybe TxInMode
mTx -> do
          STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TMVar LocalTxMonitoringResult -> LocalTxMonitoringResult -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar LocalTxMonitoringResult
resultVar (LocalTxMonitoringResult -> STM ())
-> LocalTxMonitoringResult -> STM ()
forall a b. (a -> b) -> a -> b
$ Maybe TxInMode -> SlotNo -> LocalTxMonitoringResult
LocalTxMonitoringNextTx Maybe TxInMode
mTx SlotNo
slt
          ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall (m :: * -> *) txid tx slot a.
m (ClientStIdle txid tx slot m a)
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgRelease (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a txid tx slot (m :: * -> *).
a -> ClientStIdle txid tx slot m a
CTxMon.SendMsgDone ()

  localTxMonitorMempoolInfo
    :: ()
    => TMVar LocalTxMonitoringResult
    -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
  localTxMonitorMempoolInfo :: TMVar LocalTxMonitoringResult
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
localTxMonitorMempoolInfo TMVar LocalTxMonitoringResult
resultVar =
    IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall txid tx slot (m :: * -> *) a.
m (ClientStIdle txid tx slot m a)
-> LocalTxMonitorClient txid tx slot m a
LocalTxMonitorClient (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ do
      (SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall slot (m :: * -> *) txid tx a.
(slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStIdle txid tx slot m a
CTxMon.SendMsgAcquire ((SlotNo -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> (SlotNo
    -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \SlotNo
slt -> do
        ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ (MempoolSizeAndCapacity
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall (m :: * -> *) txid tx slot a.
(MempoolSizeAndCapacity -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgGetSizes ((MempoolSizeAndCapacity
  -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> (MempoolSizeAndCapacity
    -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ \MempoolSizeAndCapacity
mempoolCapacity -> do
          STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TMVar LocalTxMonitoringResult -> LocalTxMonitoringResult -> STM ()
forall a. TMVar a -> a -> STM ()
putTMVar TMVar LocalTxMonitoringResult
resultVar (LocalTxMonitoringResult -> STM ())
-> LocalTxMonitoringResult -> STM ()
forall a b. (a -> b) -> a -> b
$ MempoolSizeAndCapacity -> SlotNo -> LocalTxMonitoringResult
LocalTxMonitoringMempoolSizeAndCapacity MempoolSizeAndCapacity
mempoolCapacity SlotNo
slt
          ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ()))
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall (m :: * -> *) txid tx slot a.
m (ClientStIdle txid tx slot m a)
-> ClientStAcquired txid tx slot m a
CTxMon.SendMsgRelease (IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
 -> ClientStAcquired TxIdInMode TxInMode SlotNo IO ())
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
-> ClientStAcquired TxIdInMode TxInMode SlotNo IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ClientStIdle TxIdInMode TxInMode SlotNo IO ()
 -> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ()))
-> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
-> IO (ClientStIdle TxIdInMode TxInMode SlotNo IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle TxIdInMode TxInMode SlotNo IO ()
forall a txid tx slot (m :: * -> *).
a -> ClientStIdle txid tx slot m a
CTxMon.SendMsgDone ()

-- ----------------------------------------------------------------------------
-- Get tip as 'ChainPoint'
--

getLocalChainTip
  :: MonadIO m
  => LocalNodeConnectInfo
  -> m ChainTip
getLocalChainTip :: forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> m ChainTip
getLocalChainTip LocalNodeConnectInfo
localNodeConInfo = do
  TMVar ChainTip
resultVar <- IO (TMVar ChainTip) -> m (TMVar ChainTip)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (TMVar ChainTip)
forall a. IO (TMVar a)
newEmptyTMVarIO
  LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo -> LocalNodeClientProtocolsInMode -> m ()
connectToLocalNode
    LocalNodeConnectInfo
localNodeConInfo
    LocalNodeClientProtocols
      { localChainSyncClient :: LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
localChainSyncClient = ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
-> LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
forall block point tip (m :: * -> *).
ChainSyncClient block point tip m ()
-> LocalChainSyncClient block point tip m
LocalChainSyncClient (ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
 -> LocalChainSyncClient BlockInMode ChainPoint ChainTip IO)
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
-> LocalChainSyncClient BlockInMode ChainPoint ChainTip IO
forall a b. (a -> b) -> a -> b
$ TMVar ChainTip
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
chainSyncGetCurrentTip TMVar ChainTip
resultVar
      , localTxSubmissionClient :: Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
localTxSubmissionClient = Maybe
  (LocalTxSubmissionClient
     TxInMode TxValidationErrorInCardanoMode IO ())
forall a. Maybe a
Nothing
      , localStateQueryClient :: Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
localStateQueryClient = Maybe
  (LocalStateQueryClient BlockInMode ChainPoint QueryInMode IO ())
forall a. Maybe a
Nothing
      , localTxMonitoringClient :: Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
localTxMonitoringClient = Maybe (LocalTxMonitorClient TxIdInMode TxInMode SlotNo IO ())
forall a. Maybe a
Nothing
      }
  IO ChainTip -> m ChainTip
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ChainTip -> m ChainTip)
-> (STM ChainTip -> IO ChainTip) -> STM ChainTip -> m ChainTip
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STM ChainTip -> IO ChainTip
forall a. STM a -> IO a
atomically (STM ChainTip -> m ChainTip) -> STM ChainTip -> m ChainTip
forall a b. (a -> b) -> a -> b
$ TMVar ChainTip -> STM ChainTip
forall a. TMVar a -> STM a
takeTMVar TMVar ChainTip
resultVar

chainSyncGetCurrentTip
  :: ()
  => TMVar ChainTip
  -> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
chainSyncGetCurrentTip :: TMVar ChainTip
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
chainSyncGetCurrentTip TMVar ChainTip
tipVar =
  IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall header point tip (m :: * -> *) a.
m (ClientStIdle header point tip m a)
-> ChainSyncClient header point tip m a
ChainSyncClient (IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
 -> ChainSyncClient BlockInMode ChainPoint ChainTip IO ())
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall a b. (a -> b) -> a -> b
$ ClientStIdle BlockInMode ChainPoint ChainTip IO ()
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ClientStIdle BlockInMode ChainPoint ChainTip IO ()
clientStIdle
 where
  clientStIdle :: Net.Sync.ClientStIdle BlockInMode ChainPoint ChainTip IO ()
  clientStIdle :: ClientStIdle BlockInMode ChainPoint ChainTip IO ()
clientStIdle =
    IO ()
-> ClientStNext BlockInMode ChainPoint ChainTip IO ()
-> ClientStIdle BlockInMode ChainPoint ChainTip IO ()
forall (m :: * -> *) header point tip a.
m ()
-> ClientStNext header point tip m a
-> ClientStIdle header point tip m a
Net.Sync.SendMsgRequestNext (() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) ClientStNext BlockInMode ChainPoint ChainTip IO ()
clientStNext

  clientStNext :: Net.Sync.ClientStNext BlockInMode ChainPoint ChainTip IO ()
  clientStNext :: ClientStNext BlockInMode ChainPoint ChainTip IO ()
clientStNext =
    Net.Sync.ClientStNext
      { recvMsgRollForward :: BlockInMode
-> ChainTip
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
Net.Sync.recvMsgRollForward = \BlockInMode
_block ChainTip
tip -> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall header point tip (m :: * -> *) a.
m (ClientStIdle header point tip m a)
-> ChainSyncClient header point tip m a
ChainSyncClient (IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
 -> ChainSyncClient BlockInMode ChainPoint ChainTip IO ())
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall a b. (a -> b) -> a -> b
$ do
          IO Bool -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ STM Bool -> IO Bool
forall a. STM a -> IO a
atomically (STM Bool -> IO Bool) -> STM Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ TMVar ChainTip -> ChainTip -> STM Bool
forall a. TMVar a -> a -> STM Bool
tryPutTMVar TMVar ChainTip
tipVar ChainTip
tip
          ClientStIdle BlockInMode ChainPoint ChainTip IO ()
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStIdle BlockInMode ChainPoint ChainTip IO ()
 -> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ()))
-> ClientStIdle BlockInMode ChainPoint ChainTip IO ()
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle BlockInMode ChainPoint ChainTip IO ()
forall a header point tip (m :: * -> *).
a -> ClientStIdle header point tip m a
Net.Sync.SendMsgDone ()
      , recvMsgRollBackward :: ChainPoint
-> ChainTip
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
Net.Sync.recvMsgRollBackward = \ChainPoint
_point ChainTip
tip -> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall header point tip (m :: * -> *) a.
m (ClientStIdle header point tip m a)
-> ChainSyncClient header point tip m a
ChainSyncClient (IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
 -> ChainSyncClient BlockInMode ChainPoint ChainTip IO ())
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
-> ChainSyncClient BlockInMode ChainPoint ChainTip IO ()
forall a b. (a -> b) -> a -> b
$ do
          IO Bool -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ STM Bool -> IO Bool
forall a. STM a -> IO a
atomically (STM Bool -> IO Bool) -> STM Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ TMVar ChainTip -> ChainTip -> STM Bool
forall a. TMVar a -> a -> STM Bool
tryPutTMVar TMVar ChainTip
tipVar ChainTip
tip
          ClientStIdle BlockInMode ChainPoint ChainTip IO ()
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientStIdle BlockInMode ChainPoint ChainTip IO ()
 -> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ()))
-> ClientStIdle BlockInMode ChainPoint ChainTip IO ()
-> IO (ClientStIdle BlockInMode ChainPoint ChainTip IO ())
forall a b. (a -> b) -> a -> b
$ () -> ClientStIdle BlockInMode ChainPoint ChainTip IO ()
forall a header point tip (m :: * -> *).
a -> ClientStIdle header point tip m a
Net.Sync.SendMsgDone ()
      }