From b0b64b1593518e5e33d285934d375b08c939086a Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Wed, 4 Sep 2019 06:47:16 +0000 Subject: [PATCH] Use `safe` library function `tailSafe` instead of locally-defined `tailOrEmpty`. --- lib/jormungandr/cardano-wallet-jormungandr.cabal | 1 + lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs | 7 +++---- nix/.stack.nix/cardano-wallet-jormungandr.nix | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/jormungandr/cardano-wallet-jormungandr.cabal b/lib/jormungandr/cardano-wallet-jormungandr.cabal index 82df34f6978..5e1595ca8dc 100644 --- a/lib/jormungandr/cardano-wallet-jormungandr.cabal +++ b/lib/jormungandr/cardano-wallet-jormungandr.cabal @@ -49,6 +49,7 @@ library , http-client , http-types , memory + , safe , servant , servant-client , servant-client-core diff --git a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs index 1aa8c5ce567..2ec00758bce 100644 --- a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs +++ b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs @@ -89,6 +89,8 @@ import Network.HTTP.Client ( Manager, defaultManagerSettings, newManager ) import Network.HTTP.Types.Status ( status400 ) +import Safe + ( tailSafe ) import Servant.API ( (:<|>) (..) ) import Servant.Client @@ -141,7 +143,7 @@ mkNetworkLayer j = NetworkLayer -- Get the descendants of the tip's /parent/. -- The first descendant is therefore the current tip itself. We need to -- skip it. Hence the 'tail'. - ids <- tailOrEmpty <$> getDescendantIds j (prevBlockHash tip) count + ids <- tailSafe <$> getDescendantIds j (prevBlockHash tip) count `mappingError` \case ErrGetDescendantsNetworkUnreachable e -> ErrGetBlockNetworkUnreachable e @@ -165,9 +167,6 @@ mkNetworkLayer j = NetworkLayer where mappingError = flip withExceptT - tailOrEmpty [] = [] - tailOrEmpty (_:xs) = xs - {------------------------------------------------------------------------------- Jormungandr Client -------------------------------------------------------------------------------} diff --git a/nix/.stack.nix/cardano-wallet-jormungandr.nix b/nix/.stack.nix/cardano-wallet-jormungandr.nix index 639cf875768..590509b32f1 100644 --- a/nix/.stack.nix/cardano-wallet-jormungandr.nix +++ b/nix/.stack.nix/cardano-wallet-jormungandr.nix @@ -38,6 +38,7 @@ (hsPkgs.http-client) (hsPkgs.http-types) (hsPkgs.memory) + (hsPkgs.safe) (hsPkgs.servant) (hsPkgs.servant-client) (hsPkgs.servant-client-core)