packages feed

utxorpc-server 0.0.3.0 → 0.0.4.1

raw patch · 8 files changed

+64/−44 lines, 8 filesdep ~utxorpcnew-component:exe:examplePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: utxorpc

API changes (from Hackage documentation)

- Utxorpc.Server: [streamUtxos] :: QueryHandlers m a -> ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a
+ Utxorpc.Server: [readEraSummary] :: QueryHandlers m -> UnaryHandler m ReadEraSummaryRequest ReadEraSummaryResponse
+ Utxorpc.Server: [readGenesis] :: QueryHandlers m -> UnaryHandler m ReadGenesisRequest ReadGenesisResponse
+ Utxorpc.Server: [readTip] :: SyncHandlers m a -> UnaryHandler m ReadTipRequest ReadTipResponse
- Utxorpc.Server: QueryHandlers :: UnaryHandler m ReadParamsRequest ReadParamsResponse -> UnaryHandler m ReadUtxosRequest ReadUtxosResponse -> UnaryHandler m SearchUtxosRequest SearchUtxosResponse -> ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a -> QueryHandlers m a
+ Utxorpc.Server: QueryHandlers :: UnaryHandler m ReadParamsRequest ReadParamsResponse -> UnaryHandler m ReadUtxosRequest ReadUtxosResponse -> UnaryHandler m SearchUtxosRequest SearchUtxosResponse -> UnaryHandler m ReadGenesisRequest ReadGenesisResponse -> UnaryHandler m ReadEraSummaryRequest ReadEraSummaryResponse -> QueryHandlers m
- Utxorpc.Server: ServiceConfig :: TLSSettings -> Settings -> UtxorpcHandlers m a b c d e -> Maybe (UtxorpcServiceLogger m) -> (forall x. m x -> IO x) -> [Compression] -> ServiceConfig m a b c d e
+ Utxorpc.Server: ServiceConfig :: TLSSettings -> Settings -> UtxorpcHandlers m a b c d -> Maybe (UtxorpcServiceLogger m) -> (forall x. m x -> IO x) -> [Compression] -> ServiceConfig m a b c d
- Utxorpc.Server: SyncHandlers :: UnaryHandler m FetchBlockRequest FetchBlockResponse -> UnaryHandler m DumpHistoryRequest DumpHistoryResponse -> ServerStreamHandler m FollowTipRequest FollowTipResponse a -> SyncHandlers m a
+ Utxorpc.Server: SyncHandlers :: UnaryHandler m FetchBlockRequest FetchBlockResponse -> UnaryHandler m DumpHistoryRequest DumpHistoryResponse -> ServerStreamHandler m FollowTipRequest FollowTipResponse a -> UnaryHandler m ReadTipRequest ReadTipResponse -> SyncHandlers m a
- Utxorpc.Server: UtxorpcHandlers :: Maybe (QueryHandlers m a) -> Maybe (SubmitHandlers m b c) -> Maybe (SyncHandlers m d) -> Maybe (WatchHandlers m e) -> UtxorpcHandlers m a b c d e
+ Utxorpc.Server: UtxorpcHandlers :: Maybe (QueryHandlers m) -> Maybe (SubmitHandlers m a b) -> Maybe (SyncHandlers m c) -> Maybe (WatchHandlers m d) -> UtxorpcHandlers m a b c d
- Utxorpc.Server: [compression] :: ServiceConfig m a b c d e -> [Compression]
+ Utxorpc.Server: [compression] :: ServiceConfig m a b c d -> [Compression]
- Utxorpc.Server: [handlers] :: ServiceConfig m a b c d e -> UtxorpcHandlers m a b c d e
+ Utxorpc.Server: [handlers] :: ServiceConfig m a b c d -> UtxorpcHandlers m a b c d
- Utxorpc.Server: [logger] :: ServiceConfig m a b c d e -> Maybe (UtxorpcServiceLogger m)
+ Utxorpc.Server: [logger] :: ServiceConfig m a b c d -> Maybe (UtxorpcServiceLogger m)
- Utxorpc.Server: [queryHandlers] :: UtxorpcHandlers m a b c d e -> Maybe (QueryHandlers m a)
+ Utxorpc.Server: [queryHandlers] :: UtxorpcHandlers m a b c d -> Maybe (QueryHandlers m)
- Utxorpc.Server: [readParams] :: QueryHandlers m a -> UnaryHandler m ReadParamsRequest ReadParamsResponse
+ Utxorpc.Server: [readParams] :: QueryHandlers m -> UnaryHandler m ReadParamsRequest ReadParamsResponse
- Utxorpc.Server: [readUtxos] :: QueryHandlers m a -> UnaryHandler m ReadUtxosRequest ReadUtxosResponse
+ Utxorpc.Server: [readUtxos] :: QueryHandlers m -> UnaryHandler m ReadUtxosRequest ReadUtxosResponse
- Utxorpc.Server: [searchUtxos] :: QueryHandlers m a -> UnaryHandler m SearchUtxosRequest SearchUtxosResponse
+ Utxorpc.Server: [searchUtxos] :: QueryHandlers m -> UnaryHandler m SearchUtxosRequest SearchUtxosResponse
- Utxorpc.Server: [submitHandlers] :: UtxorpcHandlers m a b c d e -> Maybe (SubmitHandlers m b c)
+ Utxorpc.Server: [submitHandlers] :: UtxorpcHandlers m a b c d -> Maybe (SubmitHandlers m a b)
- Utxorpc.Server: [syncHandlers] :: UtxorpcHandlers m a b c d e -> Maybe (SyncHandlers m d)
+ Utxorpc.Server: [syncHandlers] :: UtxorpcHandlers m a b c d -> Maybe (SyncHandlers m c)
- Utxorpc.Server: [tlsSettings] :: ServiceConfig m a b c d e -> TLSSettings
+ Utxorpc.Server: [tlsSettings] :: ServiceConfig m a b c d -> TLSSettings
- Utxorpc.Server: [unlift] :: ServiceConfig m a b c d e -> forall x. m x -> IO x
+ Utxorpc.Server: [unlift] :: ServiceConfig m a b c d -> forall x. m x -> IO x
- Utxorpc.Server: [warpSettings] :: ServiceConfig m a b c d e -> Settings
+ Utxorpc.Server: [warpSettings] :: ServiceConfig m a b c d -> Settings
- Utxorpc.Server: [watchHandlers] :: UtxorpcHandlers m a b c d e -> Maybe (WatchHandlers m e)
+ Utxorpc.Server: [watchHandlers] :: UtxorpcHandlers m a b c d -> Maybe (WatchHandlers m d)
- Utxorpc.Server: data QueryHandlers m a
+ Utxorpc.Server: data QueryHandlers m
- Utxorpc.Server: data ServiceConfig m a b c d e
+ Utxorpc.Server: data ServiceConfig m a b c d
- Utxorpc.Server: data UtxorpcHandlers m a b c d e
+ Utxorpc.Server: data UtxorpcHandlers m a b c d
- Utxorpc.Server: runUtxorpc :: MonadIO m => ServiceConfig m a b c d e -> IO ()
+ Utxorpc.Server: runUtxorpc :: MonadIO m => ServiceConfig m a b c d -> IO ()

Files

example/Main.hs view
@@ -57,7 +57,7 @@       id       [gzip] -handlersImpl :: (MonadIO m) => (String -> m ()) -> UtxorpcHandlers m Int Int Int Int Int+handlersImpl :: (MonadIO m) => (String -> m ()) -> UtxorpcHandlers m Int Int Int Int handlersImpl logF =   UtxorpcHandlers     (Just $ QueryImpl.handlerImpls logF)
example/QueryImpl.hs view
@@ -9,13 +9,14 @@ handlerImpls ::   (MonadIO m) =>   (String -> m ()) ->-  QueryHandlers m Int+  QueryHandlers m handlerImpls logF =   QueryHandlers     (readParamsHandler logF)     (readUtxosHandler logF)     (searchUtxosHandler logF)-    (streamUtxosHandler logF)+    (readGenesisHandler logF)+    (readEraSummaryHandler logF)  readParamsHandler ::   (MonadIO m) =>@@ -35,8 +36,14 @@   UnaryHandler m SearchUtxosRequest SearchUtxosResponse searchUtxosHandler = emptyUnaryHandler -streamUtxosHandler ::+readGenesisHandler ::   (MonadIO m) =>   (String -> m ()) ->-  ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse Int-streamUtxosHandler = emptySStreamHandler+  UnaryHandler m ReadGenesisRequest ReadGenesisResponse+readGenesisHandler = emptyUnaryHandler++readEraSummaryHandler ::+  (MonadIO m) =>+  (String -> m ()) ->+  UnaryHandler m ReadEraSummaryRequest ReadEraSummaryResponse+readEraSummaryHandler = emptyUnaryHandler
example/SyncImpl.hs view
@@ -3,7 +3,7 @@ import Control.Monad.IO.Class (MonadIO) import EmptyHandlers (emptySStreamHandler, emptyUnaryHandler) import Network.GRPC.Server (ServerStreamHandler, UnaryHandler)-import Proto.Utxorpc.V1alpha.Sync.Sync (DumpHistoryRequest, DumpHistoryResponse, FetchBlockRequest, FetchBlockResponse, FollowTipRequest, FollowTipResponse)+import Proto.Utxorpc.V1alpha.Sync.Sync (DumpHistoryRequest, DumpHistoryResponse, FetchBlockRequest, FetchBlockResponse, FollowTipRequest, FollowTipResponse, ReadTipRequest, ReadTipResponse) import Utxorpc.Server (SyncHandlers (..))  handlerImpls ::@@ -15,6 +15,7 @@     (fetchBlockHandler logF)     (dumpHistoryHandler logF)     (followTipHandler logF)+    (readTipHandler logF)  fetchBlockHandler ::   (MonadIO m) =>@@ -33,3 +34,9 @@   (String -> m ()) ->   ServerStreamHandler m FollowTipRequest FollowTipResponse Int followTipHandler = emptySStreamHandler++readTipHandler ::+  (MonadIO m) =>+  (String -> m ()) ->+  UnaryHandler m ReadTipRequest ReadTipResponse+readTipHandler = emptyUnaryHandler
src/Utxorpc/Query.hs view
@@ -10,23 +10,25 @@ import Proto.Utxorpc.V1alpha.Query.Query import Utxorpc.Logged (UtxorpcServiceLogger, loggedSStream, loggedUnary) -data QueryHandlers m a = QueryHandlers+data QueryHandlers m = QueryHandlers   { readParams :: UnaryHandler m ReadParamsRequest ReadParamsResponse,     readUtxos :: UnaryHandler m ReadUtxosRequest ReadUtxosResponse,     searchUtxos :: UnaryHandler m SearchUtxosRequest SearchUtxosResponse,-    streamUtxos :: ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a+    readGenesis :: UnaryHandler m ReadGenesisRequest ReadGenesisResponse,+    readEraSummary :: UnaryHandler m ReadEraSummaryRequest ReadEraSummaryResponse   }  serviceHandlers ::   (MonadIO m) =>   Maybe (UtxorpcServiceLogger m) ->   (forall x. m x -> IO x) ->-  QueryHandlers m b ->+  QueryHandlers m ->   [ServiceHandler]-serviceHandlers logger f QueryHandlers {readParams, readUtxos, searchUtxos, streamUtxos } =-  [readParamsSH, readUtxosSH, searchUtxosSH, streamUtxosSH ]+serviceHandlers logger f QueryHandlers {readParams, readUtxos, searchUtxos, readGenesis, readEraSummary} =+  [readParamsSH, readUtxosSH, searchUtxosSH, readGenesisSH, readEraSummarySH]   where     readParamsSH = loggedUnary f (RPC :: RPC QueryService "readParams") readParams logger     readUtxosSH = loggedUnary f (RPC :: RPC QueryService "readUtxos") readUtxos logger     searchUtxosSH = loggedUnary f (RPC :: RPC QueryService "searchUtxos") searchUtxos logger-    streamUtxosSH = loggedSStream f (RPC :: RPC QueryService "streamUtxos") streamUtxos logger+    readGenesisSH = loggedUnary f (RPC :: RPC QueryService "readGenesis") readGenesis logger+    readEraSummarySH = loggedUnary f (RPC :: RPC QueryService "readEraSummary") readEraSummary logger
src/Utxorpc/Server.hs view
@@ -34,6 +34,7 @@   ) where +import Data.Maybe (catMaybes) import Control.Monad.IO.Class (MonadIO) import Network.GRPC.HTTP2.Encoding (Compression) import Network.GRPC.Server@@ -49,7 +50,7 @@ runUtxorpc ::   (MonadIO m) =>   -- | Configuration info and method handlers.-  ServiceConfig m a b c d e ->+  ServiceConfig m a b c d ->   IO () runUtxorpc   ServiceConfig@@ -72,13 +73,13 @@ -- and @'unlift'@ runs the combined action in IO. This means that changes to the -- monadic state made by the request logger (e.g., adding a namespace) are seen by -- the handlers and other logging functions for that specific call.-data ServiceConfig m a b c d e = ServiceConfig+data ServiceConfig m a b c d = ServiceConfig   { -- | warp-tls settings for using TLS.     tlsSettings :: TLSSettings,     -- | warp settings     warpSettings :: Settings,     -- | A handler for each method in the UTxO RPC specification.-    handlers :: UtxorpcHandlers m a b c d e,+    handlers :: UtxorpcHandlers m a b c d,     -- | Log each RPC event.     logger :: Maybe (UtxorpcServiceLogger m),     -- | An unlift function for the handlers and logger. Allows the handler and logger to be run in any monad, but they must be the same monad.@@ -93,36 +94,37 @@ data   UtxorpcHandlers     m -- Monad of the handler functions-    a -- Stream state of `holdUtxo`-    b -- Stream state of `waitForTx`-    c -- Stream state of `watchMempool`-    d -- Stream state of `followTip`-    e -- Stream state of `watchTx`+    a -- Stream state of `waitForTx`+    b -- Stream state of `watchMempool`+    c -- Stream state of `followTip`+    d -- Stream state of `watchTx`   = UtxorpcHandlers   { -- | Handlers for the Query module.-    queryHandlers :: Maybe (QueryHandlers m a),+    queryHandlers :: Maybe (QueryHandlers m),     -- | Handlers for the Submit module.-    submitHandlers :: Maybe (SubmitHandlers m b c),+    submitHandlers :: Maybe (SubmitHandlers m a b),     -- | Handlers for the Sync module.-    syncHandlers :: Maybe (SyncHandlers m d),+    syncHandlers :: Maybe (SyncHandlers m c),     -- | Handlers for the Watch module.-    watchHandlers :: Maybe (WatchHandlers m e)+    watchHandlers :: Maybe (WatchHandlers m d)   }  serviceHandlers ::   (MonadIO m) =>   Maybe (UtxorpcServiceLogger m) ->   (forall x. m x -> IO x) ->-  UtxorpcHandlers m a b c d e ->+  UtxorpcHandlers m a b c d ->   [ServiceHandler] serviceHandlers   logger   unlift   UtxorpcHandlers {queryHandlers, submitHandlers, syncHandlers, watchHandlers} =-    maybe [] (Query.serviceHandlers logger unlift) queryHandlers-      <> maybe [] (Submit.serviceHandlers logger unlift) submitHandlers-      <> maybe [] (Sync.serviceHandlers logger unlift) syncHandlers-      <> maybe [] (Watch.serviceHandlers logger unlift) watchHandlers+    concat . catMaybes $+      [ Query.serviceHandlers logger unlift <$> queryHandlers+      , Submit.serviceHandlers logger unlift <$> submitHandlers+      , Sync.serviceHandlers logger unlift <$> syncHandlers+      , Watch.serviceHandlers logger unlift <$> watchHandlers+      ]  -- $use -- To run a UTxO RPC service:
src/Utxorpc/Sync.hs view
@@ -13,7 +13,8 @@ data SyncHandlers m a = SyncHandlers   { fetchBlock :: UnaryHandler m FetchBlockRequest FetchBlockResponse,     dumpHistory :: UnaryHandler m DumpHistoryRequest DumpHistoryResponse,-    followTip :: ServerStreamHandler m FollowTipRequest FollowTipResponse a+    followTip :: ServerStreamHandler m FollowTipRequest FollowTipResponse a,+    readTip :: UnaryHandler m ReadTipRequest ReadTipResponse   }  serviceHandlers ::@@ -22,9 +23,10 @@   (forall x. m x -> IO x) ->   SyncHandlers m b ->   [ServiceHandler]-serviceHandlers logger f SyncHandlers {fetchBlock, dumpHistory, followTip} =-  [fetchBlockSH, dumpHistorySH, followTipSH]+serviceHandlers logger f SyncHandlers {fetchBlock, dumpHistory, followTip, readTip} =+  [fetchBlockSH, dumpHistorySH, followTipSH, readTipSH]   where-    fetchBlockSH = loggedUnary f (RPC :: RPC ChainSyncService "fetchBlock") fetchBlock logger-    dumpHistorySH = loggedUnary f (RPC :: RPC ChainSyncService "dumpHistory") dumpHistory logger-    followTipSH = loggedSStream f (RPC :: RPC ChainSyncService "followTip") followTip logger+    fetchBlockSH = loggedUnary f (RPC :: RPC SyncService "fetchBlock") fetchBlock logger+    dumpHistorySH = loggedUnary f (RPC :: RPC SyncService "dumpHistory") dumpHistory logger+    followTipSH = loggedSStream f (RPC :: RPC SyncService "followTip") followTip logger+    readTipSH = loggedUnary f (RPC :: RPC SyncService "readTip") readTip logger
test/logged_test.hs view
@@ -78,7 +78,7 @@ unaryHandlerOut :: String unaryHandlerOut = "UNARY_HANDLER\n" -unaryRpc :: RPC ChainSyncService "fetchBlock"+unaryRpc :: RPC SyncService "fetchBlock" unaryRpc = RPC  unaryReq :: FetchBlockRequest@@ -112,7 +112,7 @@ streamHandlerEndOut :: Int -> String streamHandlerEndOut index = "STREAM_HANDLER_END " ++ show index ++ "\n" -sStreamRpc :: RPC ChainSyncService "followTip"+sStreamRpc :: RPC SyncService "followTip" sStreamRpc = RPC  type SStreamReq = FollowTipRequest
utxorpc-server.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0  name:           utxorpc-server-version:        0.0.3.0+version:        0.0.4.1 synopsis:       An SDK for UTxO RPC services. description:    An SDK to reduce boilerplate, improve ease-of-use, and support logging for `utxorpc`.                 To get started, see the documentation for `Utxorpc.Server` below.@@ -51,7 +51,7 @@     , bytestring < 0.13     , http2-grpc-proto-lens < 0.2     , http2-grpc-types >= 0.5.0.0 && < 0.6-    , utxorpc >= 0.0.5 && < 0.0.6+    , utxorpc >= 0.0.18 && < 0.0.19     , uuid < 1.4     , wai < 3.3     , warp  < 3.5@@ -59,7 +59,7 @@     , warp-tls < 3.5   default-language: Haskell2010 -executable server-example+executable example   main-is:     Main.hs   other-modules:@@ -95,7 +95,7 @@     , time < 1.13     , transformers < 0.7     , unliftio < 0.3-    , utxorpc >= 0.0.4+    , utxorpc >= 0.0.18 && < 0.0.19     , utxorpc-server     , uuid < 1.4     , wai < 3.3@@ -104,7 +104,7 @@     , warp-tls < 3.5   default-language: Haskell2010 -test-suite logged_test_server+test-suite unit   type:     exitcode-stdio-1.0   main-is:@@ -134,7 +134,7 @@     , hspec >= 2.11.7 && < 2.12     , proto-lens < 0.8     , transformers < 0.7-    , utxorpc >= 0.0.4+    , utxorpc >= 0.0.18 && < 0.0.19     , uuid < 1.4     , wai < 3.3     , warp-grpc < 0.5