{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}

module Utxorpc.Submit (SubmitHandlers (..), serviceHandlers) where

import Control.Monad.IO.Class (MonadIO)
import Network.GRPC.HTTP2.ProtoLens (RPC (RPC))
import Network.GRPC.Server (ServerStreamHandler, ServiceHandler, UnaryHandler)
import Proto.Utxorpc.V1alpha.Submit.Submit
import Utxorpc.Logged (UtxorpcServiceLogger, loggedSStream, loggedUnary)

data SubmitHandlers m a b = SubmitHandlers
  { forall (m :: * -> *) a b.
SubmitHandlers m a b
-> UnaryHandler m SubmitTxRequest SubmitTxResponse
submitTx :: UnaryHandler m SubmitTxRequest SubmitTxResponse,
    forall (m :: * -> *) a b.
SubmitHandlers m a b
-> UnaryHandler m ReadMempoolRequest ReadMempoolResponse
readMempool :: UnaryHandler m ReadMempoolRequest ReadMempoolResponse,
    forall (m :: * -> *) a b.
SubmitHandlers m a b
-> ServerStreamHandler m WaitForTxRequest WaitForTxResponse a
waitForTx :: ServerStreamHandler m WaitForTxRequest WaitForTxResponse a,
    forall (m :: * -> *) a b.
SubmitHandlers m a b
-> ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse b
watchMempool :: ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse b
  }

serviceHandlers ::
  (MonadIO m) =>
  Maybe (UtxorpcServiceLogger m) ->
  (forall x. m x -> IO x) ->
  SubmitHandlers m b c ->
  [ServiceHandler]
serviceHandlers :: forall (m :: * -> *) b c.
MonadIO m =>
Maybe (UtxorpcServiceLogger m)
-> (forall x. m x -> IO x)
-> SubmitHandlers m b c
-> [ServiceHandler]
serviceHandlers Maybe (UtxorpcServiceLogger m)
logger forall x. m x -> IO x
f SubmitHandlers {UnaryHandler m SubmitTxRequest SubmitTxResponse
submitTx :: forall (m :: * -> *) a b.
SubmitHandlers m a b
-> UnaryHandler m SubmitTxRequest SubmitTxResponse
submitTx :: UnaryHandler m SubmitTxRequest SubmitTxResponse
submitTx, UnaryHandler m ReadMempoolRequest ReadMempoolResponse
readMempool :: forall (m :: * -> *) a b.
SubmitHandlers m a b
-> UnaryHandler m ReadMempoolRequest ReadMempoolResponse
readMempool :: UnaryHandler m ReadMempoolRequest ReadMempoolResponse
readMempool, ServerStreamHandler m WaitForTxRequest WaitForTxResponse b
waitForTx :: forall (m :: * -> *) a b.
SubmitHandlers m a b
-> ServerStreamHandler m WaitForTxRequest WaitForTxResponse a
waitForTx :: ServerStreamHandler m WaitForTxRequest WaitForTxResponse b
waitForTx, ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse c
watchMempool :: forall (m :: * -> *) a b.
SubmitHandlers m a b
-> ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse b
watchMempool :: ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse c
watchMempool} =
  [ServiceHandler
submitTxSH, ServiceHandler
readMempoolSH, ServiceHandler
waitForTxSH, ServiceHandler
watchMempoolSH]
  where
    submitTxSH :: ServiceHandler
submitTxSH = (forall x. m x -> IO x)
-> RPC SubmitService "submitTx"
-> UnaryHandler m SubmitTxRequest SubmitTxResponse
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> UnaryHandler m i o
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedUnary m x -> IO x
forall x. m x -> IO x
f (RPC SubmitService "submitTx"
forall s (m :: Symbol). RPC s m
RPC :: RPC SubmitService "submitTx") UnaryHandler m SubmitTxRequest SubmitTxResponse
submitTx Maybe (UtxorpcServiceLogger m)
logger
    readMempoolSH :: ServiceHandler
readMempoolSH = (forall x. m x -> IO x)
-> RPC SubmitService "readMempool"
-> UnaryHandler m ReadMempoolRequest ReadMempoolResponse
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> UnaryHandler m i o
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedUnary m x -> IO x
forall x. m x -> IO x
f (RPC SubmitService "readMempool"
forall s (m :: Symbol). RPC s m
RPC :: RPC SubmitService "readMempool") UnaryHandler m ReadMempoolRequest ReadMempoolResponse
readMempool Maybe (UtxorpcServiceLogger m)
logger
    waitForTxSH :: ServiceHandler
waitForTxSH = (forall x. m x -> IO x)
-> RPC SubmitService "waitForTx"
-> ServerStreamHandler m WaitForTxRequest WaitForTxResponse b
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o a.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> ServerStreamHandler m i o a
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedSStream m x -> IO x
forall x. m x -> IO x
f (RPC SubmitService "waitForTx"
forall s (m :: Symbol). RPC s m
RPC :: RPC SubmitService "waitForTx") ServerStreamHandler m WaitForTxRequest WaitForTxResponse b
waitForTx Maybe (UtxorpcServiceLogger m)
logger
    watchMempoolSH :: ServiceHandler
watchMempoolSH = (forall x. m x -> IO x)
-> RPC SubmitService "watchMempool"
-> ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse c
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o a.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> ServerStreamHandler m i o a
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedSStream m x -> IO x
forall x. m x -> IO x
f (RPC SubmitService "watchMempool"
forall s (m :: Symbol). RPC s m
RPC :: RPC SubmitService "watchMempool") ServerStreamHandler m WatchMempoolRequest WatchMempoolResponse c
watchMempool Maybe (UtxorpcServiceLogger m)
logger