packages feed

utxorpc-client 0.0.1.1 → 0.0.2.0

raw patch · 4 files changed

+84/−51 lines, 4 filesdep ~utxorpcPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: utxorpc

API changes (from Hackage documentation)

- Utxorpc.Client: BuildClient :: (GetChainTipRequest -> UnaryReply GetChainTipResponse) -> (GetChainParamRequest -> UnaryReply GetChainParamResponse) -> (GetUtxoByAddressRequest -> UnaryReply GetUtxoByAddressResponse) -> (GetUtxoByRefRequest -> UnaryReply GetUtxoByRefResponse) -> ServerStreamCall HoldUtxoRequest HoldUtxoResponse -> BuildClient
- Utxorpc.Client: [buildClient] :: UtxorpcClient -> BuildClient
- Utxorpc.Client: [getChainParam] :: BuildClient -> GetChainParamRequest -> UnaryReply GetChainParamResponse
- Utxorpc.Client: [getChainTip] :: BuildClient -> GetChainTipRequest -> UnaryReply GetChainTipResponse
- Utxorpc.Client: [getUtxoByAddress] :: BuildClient -> GetUtxoByAddressRequest -> UnaryReply GetUtxoByAddressResponse
- Utxorpc.Client: [getUtxoByRef] :: BuildClient -> GetUtxoByRefRequest -> UnaryReply GetUtxoByRefResponse
- Utxorpc.Client: [holdUtxo] :: BuildClient -> ServerStreamCall HoldUtxoRequest HoldUtxoResponse
- Utxorpc.Client: data BuildClient
+ Utxorpc.Client: QueryClient :: (ReadParamsRequest -> UnaryReply ReadParamsResponse) -> (ReadUtxosRequest -> UnaryReply ReadUtxosResponse) -> (SearchUtxosRequest -> UnaryReply SearchUtxosResponse) -> ServerStreamCall ReadUtxosRequest ReadUtxosResponse -> QueryClient
+ Utxorpc.Client: [queryClient] :: UtxorpcClient -> QueryClient
+ Utxorpc.Client: [readParams] :: QueryClient -> ReadParamsRequest -> UnaryReply ReadParamsResponse
+ Utxorpc.Client: [readUtxos] :: QueryClient -> ReadUtxosRequest -> UnaryReply ReadUtxosResponse
+ Utxorpc.Client: [searchUtxos] :: QueryClient -> SearchUtxosRequest -> UnaryReply SearchUtxosResponse
+ Utxorpc.Client: [streamUtxos] :: QueryClient -> ServerStreamCall ReadUtxosRequest ReadUtxosResponse
+ Utxorpc.Client: data QueryClient
- Utxorpc.Client: UtxorpcClient :: BuildClient -> SubmitClient -> SyncClient -> WatchClient -> IO (Either ClientError ()) -> UtxorpcClient
+ Utxorpc.Client: UtxorpcClient :: QueryClient -> SubmitClient -> SyncClient -> WatchClient -> IO (Either ClientError ()) -> UtxorpcClient

Files

example/Main.hs view
@@ -1,23 +1,27 @@+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PackageImports #-}  module Main (main) where +import Control.Lens.Operators ((&), (.~))+import Control.Monad (void) import qualified Data.ByteString.Char8 as BS import Data.ProtoLens (Message (..))+import qualified Data.Text.Encoding as TE import Katip import Katip.Monadic import KatipLogger (katipLogger) import Network.GRPC.Client (CIHeaderList) import Network.HTTP2.Frame (ErrorCode)+import Proto.Utxorpc.V1alpha.Sync.Sync_Fields import Safe (readMay) import SimpleLogger (simpleLogger) import System.Environment (getArgs) import UnliftIO (MonadIO, bracket, stdout, throwString) import Utxorpc.Client-  ( BuildClient (..),+  ( QueryClient (..),     ServerStreamReply,-    SubmitClient (..),     SyncClient (..),     UnaryReply,     UtxorpcClient (..),@@ -70,8 +74,8 @@ runKatipExample :: UtxorpcInfo m -> IO () runKatipExample serviceInfo = do   bracket mkLogEnv closeScribes $ \le -> do-    eService <- utxorpcClient $ serviceInfo {_logger = Just $ mkKatipLogger le}-    case eService of+    let mkEService = utxorpcClient $ serviceInfo {_logger = Just $ mkKatipLogger le}+    bracket mkEService closeService $ \case       Left clientErr -> handleClientErr clientErr       Right service -> runUtxo service   where@@ -88,11 +92,17 @@  runSimpleExample :: UtxorpcInfo m -> IO () runSimpleExample serviceInfo = do-  eService <- utxorpcClient $ serviceInfo {_logger = Just simpleLogger}-  case eService of+  let mkEService = utxorpcClient $ serviceInfo {_logger = Just simpleLogger}+  bracket mkEService closeService $ \case     Left clientErr -> handleClientErr clientErr     Right service -> runUtxo service +closeService :: Either ClientError UtxorpcClient -> IO ()+closeService (Left _) = return ()+closeService (Right service) = do+  putStrLn "Closing connection"+  void $ close service+ -- Make UTxO RPC calls with empty messages -- Errors are handled by throwing IO exceptions and exiting -- `handleStream` is the stream handler function expected by a `ServerStreamCall`.@@ -100,13 +110,36 @@ -- logger. runUtxo :: UtxorpcClient -> IO () runUtxo client = do-  _maybeFetchBlockResponse <- handleUnaryReply $ fetchBlock (syncClient client) defMessage-  _maybeChainTipResponse <- handleUnaryReply $ getChainTip (buildClient client) defMessage+  _maybeChainTipResponse <- handleUnaryReply $ dumpHistory (syncClient client) dumpHistoryRequest+  _maybeReadUtxosResponse <- handleUnaryReply $ readUtxos (queryClient client) defMessage   _maybeStreamState <-     handleStreamReply $-      watchMempool (submitClient client) (0 :: Int) defMessage handleStream+      followTip (syncClient client) (0 :: Int) followTipRequest handleStream   return ()   where+    dumpHistoryRequest =+      defMessage+        & startToken .~ blockRef+        & maxItems .~ 3++    followTipRequest =+      defMessage+        & intersect+          .~ [ blockRef,+               defMessage+                 & index .~ 41562539+                 & hash+                   .~ TE.encodeUtf8+                     "e4599d275375e54257e7fd922d2f486cf47dd90692d1a7e531804a4e90893346"+             ]++    blockRef =+      defMessage+        & index .~ 41561535+        & hash+          .~ TE.encodeUtf8+            "91ec40dfc09449d918ec7b5311d5ddba318e8a7c337eaf23c9916c6463c30fbe"+     handleStream n _headerList _reply = do       putStrLn ("The stream handler is processing message #" ++ show n)       return (n + 1)
src/Utxorpc/Client.hs view
@@ -33,7 +33,7 @@      -- * The @'UtxorpcClient'@     UtxorpcClient (..),-    BuildClient (..),+    QueryClient (..),     SubmitClient (..),     SyncClient (..),     WatchClient (..),@@ -64,7 +64,7 @@     _grpcClientConfigCompression,   ) import Network.GRPC.HTTP2.ProtoLens (RPC (RPC))-import Proto.Utxorpc.V1alpha.Build.Build+import Proto.Utxorpc.V1alpha.Query.Query import Proto.Utxorpc.V1alpha.Submit.Submit import Proto.Utxorpc.V1alpha.Sync.Sync import Proto.Utxorpc.V1alpha.Watch.Watch@@ -109,7 +109,8 @@ utxorpcClient :: UtxorpcInfo m -> IO (Either ClientError UtxorpcClient) utxorpcClient   UtxorpcInfo {_hostName, _portNumber, _tlsEnabled, _useGzip, _logger, _clientHeaders} = do-    eClient <- grpcClient _hostName _portNumber _tlsEnabled _useGzip+    let sanitizedHost = if _hostName == "localhost" then "127.0.0.1" else _hostName+    eClient <- grpcClient sanitizedHost _portNumber _tlsEnabled _useGzip     return $ fromGrpc _logger . withHeaders _clientHeaders <$> eClient     where       withHeaders hdrs client =@@ -144,39 +145,35 @@ fromGrpc :: Maybe (UtxorpcClientLogger m) -> GrpcClient -> UtxorpcClient fromGrpc logger client =   UtxorpcClient-    (mkBuildClient logger client)+    (mkQueryClient logger client)     (mkSubmitClient logger client)     (mkSyncClient logger client)     (mkWatchClient logger client)     (runClientIO $ Network.GRPC.Client.Helpers.close client)  {---------------------------------------  BUILD+  QUERY --------------------------------------} -mkBuildClient :: Maybe (UtxorpcClientLogger m) -> GrpcClient -> BuildClient-mkBuildClient logger client =-  BuildClient-    (loggedUnary logger getChainTipRPC client)-    (loggedUnary logger getChainParamRPC client)-    (loggedUnary logger getUtxoByAddressRPC client)-    (loggedUnary logger getUtxoByRefRPC client)-    (loggedSStream logger holdUtxoRPC client)--getChainTipRPC :: RPC LedgerStateService "getChainTip"-getChainTipRPC = RPC+mkQueryClient :: Maybe (UtxorpcClientLogger m) -> GrpcClient -> QueryClient+mkQueryClient logger client =+  QueryClient+    (loggedUnary logger readParamsRPC client)+    (loggedUnary logger readUtxosRPC client)+    (loggedUnary logger searchUtxosRPC client)+    (loggedSStream logger streamUtxosRPC client) -getChainParamRPC :: RPC LedgerStateService "getChainParam"-getChainParamRPC = RPC+readParamsRPC :: RPC QueryService "readParams"+readParamsRPC = RPC -getUtxoByAddressRPC :: RPC LedgerStateService "getUtxoByAddress"-getUtxoByAddressRPC = RPC+readUtxosRPC :: RPC QueryService "readUtxos"+readUtxosRPC = RPC -getUtxoByRefRPC :: RPC LedgerStateService "getUtxoByRef"-getUtxoByRefRPC = RPC+searchUtxosRPC :: RPC QueryService "searchUtxos"+searchUtxosRPC = RPC -holdUtxoRPC :: RPC LedgerStateService "holdUtxo"-holdUtxoRPC = RPC+streamUtxosRPC :: RPC QueryService "streamUtxos"+streamUtxosRPC = RPC  {--------------------------------------   SUBMIT@@ -294,7 +291,7 @@ -- --     4. Server stream ended. ----- For more information, see @'Utxorpc.Logged'@ and the examples.+-- For more information, see @'UtxorpcClientLogger'@ and the examples.  -- $examples -- There are two examples included in the [project](https://github.com/utxorpc/haskell-sdk).
src/Utxorpc/Types.hs view
@@ -7,7 +7,7 @@ -- The types in this module are required to call methods of a `UtxorpcClient`. module Utxorpc.Types   ( UtxorpcClient (..),-    BuildClient (..),+    QueryClient (..),     SubmitClient (..),     SyncClient (..),     WatchClient (..),@@ -18,7 +18,7 @@ where  import Network.GRPC.Client (HeaderList, RawReply)-import Proto.Utxorpc.V1alpha.Build.Build+import Proto.Utxorpc.V1alpha.Query.Query import Proto.Utxorpc.V1alpha.Submit.Submit import Proto.Utxorpc.V1alpha.Sync.Sync import Proto.Utxorpc.V1alpha.Watch.Watch@@ -53,10 +53,10 @@  -- | Methods for each module in UTxO RPC. ----- >>> fetchBlock (buildClient client) defMessage+-- >>> fetchBlock (queryClient client) defMessage data UtxorpcClient = UtxorpcClient-  { -- | Build module service methods.-    buildClient :: BuildClient,+  { -- | Query module service methods.+    queryClient :: QueryClient,     -- | Submit module service methods.     submitClient :: SubmitClient,     -- | Sync module service methods.@@ -68,16 +68,15 @@   }  {----------------------------------------  Build+  Query ---------------------------------------} --- | Methods of the Build module-data BuildClient = BuildClient-  { getChainTip :: GetChainTipRequest -> UnaryReply GetChainTipResponse,-    getChainParam :: GetChainParamRequest -> UnaryReply GetChainParamResponse,-    getUtxoByAddress :: GetUtxoByAddressRequest -> UnaryReply GetUtxoByAddressResponse,-    getUtxoByRef :: GetUtxoByRefRequest -> UnaryReply GetUtxoByRefResponse,-    holdUtxo :: ServerStreamCall HoldUtxoRequest HoldUtxoResponse+-- | Methods of the Query module+data QueryClient = QueryClient+  { readParams :: ReadParamsRequest -> UnaryReply ReadParamsResponse,+    readUtxos :: ReadUtxosRequest -> UnaryReply ReadUtxosResponse,+    searchUtxos :: SearchUtxosRequest -> UnaryReply SearchUtxosResponse,+    streamUtxos :: ServerStreamCall ReadUtxosRequest ReadUtxosResponse   }  {---------------------------------------
utxorpc-client.cabal view
@@ -1,11 +1,13 @@ cabal-version: 3.0  name:           utxorpc-client-version:        0.0.1.1+version:        0.0.2.0 synopsis:       An SDK for clients of the UTxO RPC specification. description:    An SDK to reduce boilerplate, improve ease-of-use, and support logging for `utxorpc`.                 To get started, see the documentation for `Utxorpc.Client` below.+                                 Consult the README for help with dependency configurations.+                 WARNING: This package is currently pre-release. Any version < 0.1.0.0 is subject to breaking                 changes without change in major version. category:       Network, Blockchain, Cardano@@ -50,7 +52,7 @@     , http2-grpc-proto-lens < 0.2     , http2-grpc-types < 0.6     , proto-lens < 0.8-    , utxorpc >= 0.0.3 && < 0.1+    , utxorpc >= 0.0.5 && < 0.0.6     , uuid < 1.4   default-language: Haskell2010 @@ -86,9 +88,11 @@     , lens < 5.3     , proto-lens < 0.8     , safe < 0.4+    , text < 2.2     , time < 1.13     , transformers < 0.7     , unliftio < 0.3+    , utxorpc >= 0.0.5 && < 0.0.6     , utxorpc-client     , uuid < 1.4   default-language: Haskell2010@@ -115,7 +119,7 @@     , proto-lens < 0.8     , text < 2.2     , unliftio < 0.3-    , utxorpc >= 0.0.3.0 && < 0.1+    , utxorpc >= 0.0.5 && < 0.0.6     , utxorpc-client   default-language: Haskell2010 @@ -150,6 +154,6 @@     , http2-grpc-types >= 0.5.0.0 && < 0.6     , hspec >= 2.11.7 && < 2.12     , proto-lens < 0.8-    , utxorpc >= 0.0.3.0 && < 0.1+    , utxorpc >= 0.0.5 && < 0.0.6     , uuid < 1.4   default-language: Haskell2010