Skip to content

Commit cf55ecc

Browse files
authored
Merge pull request #3989 from IntersectMBO/chore/haskell-linting-and-formatting
chore: fix haskell lint and formatting
2 parents 172cb93 + d896ece commit cf55ecc

File tree

12 files changed

+332
-287
lines changed

12 files changed

+332
-287
lines changed

.github/workflows/code_check_backend.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
- name: Use Haskell
1414
uses: haskell-actions/setup@v2
1515
with:
16-
ghc-version: '9.2.7'
17-
cabal-version: '3.6.0.0'
16+
ghc-version: '9.2.8'
17+
cabal-version: '3.8.1.0'
18+
cabal-update: false
1819

1920
- name: Use Python
2021
uses: actions/setup-python@v2
@@ -26,6 +27,13 @@ jobs:
2627

2728
- name: Install HLint
2829
run: |
30+
rm -rf ~/.cabal ~/.ghcup
31+
mkdir -p ~/.cabal
32+
cat <<EOF > ~/.cabal/config
33+
repository hackage.haskell.org
34+
url: http://hackage.haskell.org/
35+
secure: False
36+
EOF
2937
cabal update
3038
cabal install hlint
3139
@@ -41,8 +49,9 @@ jobs:
4149
- name: Use Haskell
4250
uses: haskell-actions/setup@v2
4351
with:
44-
ghc-version: '9.2.7'
45-
cabal-version: '3.6.0.0'
52+
ghc-version: '9.2.8'
53+
cabal-version: '3.8.1.0'
54+
cabal-update: false
4655

4756
- name: Use Python
4857
uses: actions/setup-python@v2
@@ -54,6 +63,13 @@ jobs:
5463

5564
- name: Install HLint
5665
run: |
66+
rm -rf ~/.cabal ~/.ghcup
67+
mkdir -p ~/.cabal
68+
cat <<EOF > ~/.cabal/config
69+
repository hackage.haskell.org
70+
url: http://hackage.haskell.org/
71+
secure: False
72+
EOF
5773
cabal update
5874
cabal install stylish-haskell
5975

govtool/backend/src/VVA/API.hs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE NamedFieldPuns #-}
34
{-# LANGUAGE OverloadedStrings #-}
45
{-# LANGUAGE RecordWildCards #-}
56
{-# LANGUAGE TypeOperators #-}
67
{-# LANGUAGE ViewPatterns #-}
7-
{-# LANGUAGE DataKinds #-}
88

99
module VVA.API where
1010

@@ -13,48 +13,47 @@ import Control.Exception (throw, throwIO)
1313
import Control.Monad.Except (runExceptT, throwError)
1414
import Control.Monad.Reader
1515

16-
import Data.Aeson (Value(..), Array, decode, ToJSON, toJSON)
16+
import Data.Aeson (Array, ToJSON, Value (..), decode, toJSON)
1717
import Data.Bool (Bool)
18-
import Data.List (sortOn, sort)
18+
import Data.ByteString.Lazy (ByteString)
19+
import qualified Data.ByteString.Lazy as BSL
20+
import Data.List (sort, sortOn)
1921
import qualified Data.Map as Map
2022
import Data.Maybe (Maybe (Nothing), catMaybes, fromMaybe, mapMaybe)
2123
import Data.Ord (Down (..))
2224
import Data.Text hiding (any, drop, elem, filter, length, map, null, take)
2325
import qualified Data.Text as Text
2426
import qualified Data.Text.Lazy as TL
2527
import qualified Data.Text.Lazy.Encoding as TL
26-
import qualified Data.Vector as V
28+
import Data.Time (TimeZone, localTimeToUTC)
2729
import Data.Time.LocalTime (TimeZone, getCurrentTimeZone)
28-
30+
import qualified Data.Vector as V
2931

3032
import Numeric.Natural (Natural)
3133

3234
import Servant.API
33-
import Servant.Server
3435
import Servant.Exception (Throws)
36+
import Servant.Server
37+
3538
import System.Random (randomRIO)
3639

3740
import Text.Read (readMaybe)
3841

42+
import VVA.Account as Account
3943
import qualified VVA.AdaHolder as AdaHolder
4044
import VVA.API.Types
4145
import VVA.Cache (cacheRequest)
4246
import VVA.Config
4347
import qualified VVA.DRep as DRep
4448
import qualified VVA.Epoch as Epoch
49+
import qualified VVA.Ipfs as Ipfs
4550
import VVA.Network as Network
46-
import VVA.Account as Account
4751
import qualified VVA.Proposal as Proposal
4852
import qualified VVA.Transaction as Transaction
4953
import qualified VVA.Types as Types
5054
import VVA.Types (App, AppEnv (..),
51-
AppError (CriticalError, InternalError, ValidationError, AppIpfsError),
55+
AppError (AppIpfsError, CriticalError, InternalError, ValidationError),
5256
CacheEnv (..))
53-
import Data.Time (TimeZone, localTimeToUTC)
54-
import qualified VVA.Ipfs as Ipfs
55-
import Data.ByteString.Lazy (ByteString)
56-
import qualified Data.ByteString.Lazy as BSL
57-
import Servant.Exception (Throws)
5857

5958
type VVAApi =
6059
"ipfs"
@@ -127,7 +126,7 @@ upload mFileName fileContentText = do
127126
throwError $ ValidationError "The uploaded file is larger than 500Kb"
128127
eIpfsHash <- liftIO $ Ipfs.ipfsUpload vvaPinataJwt fileName fileContent
129128
case eIpfsHash of
130-
Left err -> throwError $ AppIpfsError err
129+
Left err -> throwError $ AppIpfsError err
131130
Right ipfsHash -> return $ UploadResponse ipfsHash
132131

133132
mapDRepType :: Types.DRepType -> DRepType
@@ -188,9 +187,9 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do
188187
viewLower = Text.toLower dRepRegistrationView
189188
hashLower = Text.toLower dRepRegistrationDRepHash
190189
in case dRepRegistrationType of
191-
Types.SoleVoter ->
190+
Types.SoleVoter ->
192191
searchLower == viewLower || searchLower == hashLower
193-
Types.DRep ->
192+
Types.DRep ->
194193
True
195194

196195

@@ -318,13 +317,13 @@ getVotes :: App m => HexText -> [GovernanceActionType] -> Maybe GovernanceAction
318317
getVotes (unHexText -> dRepId) selectedTypes sortMode mSearch = do
319318
CacheEnv {dRepGetVotesCache} <- asks vvaCache
320319
(votes, proposals) <- cacheRequest dRepGetVotesCache dRepId $ DRep.getVotes dRepId []
321-
320+
322321
let voteMapById = Map.fromList $
323322
map (\vote -> (Types.voteGovActionId vote, vote)) votes
324-
325-
processedProposals <- filter (isProposalSearchedFor mSearch) <$>
323+
324+
processedProposals <- filter (isProposalSearchedFor mSearch) <$>
326325
mapSortAndFilterProposals selectedTypes sortMode proposals
327-
326+
328327
return
329328
[ VoteResponse
330329
{ voteResponseVote = voteToResponse vote
@@ -334,7 +333,7 @@ getVotes (unHexText -> dRepId) selectedTypes sortMode mSearch = do
334333
, let govActionId = unHexText (proposalResponseTxHash proposalResponse) <> "#" <> pack (show $ proposalResponseIndex proposalResponse)
335334
, Just vote <- [Map.lookup govActionId voteMapById]
336335
]
337-
336+
338337
drepInfo :: App m => HexText -> m DRepInfoResponse
339338
drepInfo (unHexText -> dRepId) = do
340339
CacheEnv {dRepInfoCache} <- asks vvaCache
@@ -365,15 +364,15 @@ drepInfo (unHexText -> dRepId) = do
365364
drepVotingPowerList :: App m => [Text] -> m [DRepVotingPowerListResponse]
366365
drepVotingPowerList identifiers = do
367366
CacheEnv {dRepVotingPowerListCache} <- asks vvaCache
368-
367+
369368
let cacheKey = Text.intercalate "," (sort identifiers)
370-
371-
results <- cacheRequest dRepVotingPowerListCache cacheKey $
369+
370+
results <- cacheRequest dRepVotingPowerListCache cacheKey $
372371
DRep.getDRepsVotingPowerList identifiers
373-
372+
374373
return $ map toDRepVotingPowerListResponse results
375374
where
376-
toDRepVotingPowerListResponse Types.DRepVotingPowerList{..} =
375+
toDRepVotingPowerListResponse Types.DRepVotingPowerList{..} =
377376
DRepVotingPowerListResponse
378377
{ drepVotingPowerListResponseView = drepView
379378
, drepVotingPowerListResponseHashRaw = HexText drepHashRaw
@@ -456,9 +455,9 @@ getProposal g@(GovActionId govActionTxHash govActionIndex) mDrepId' = do
456455
let mDrepId = unHexText <$> mDrepId'
457456
CacheEnv {getProposalCache} <- asks vvaCache
458457
proposal@Types.Proposal {proposalUrl, proposalDocHash} <- cacheRequest getProposalCache (unHexText govActionTxHash, govActionIndex) (Proposal.getProposal (unHexText govActionTxHash) govActionIndex)
459-
458+
460459
timeZone <- liftIO getCurrentTimeZone
461-
460+
462461
let proposalResponse = proposalToResponse timeZone proposal
463462
voteResponse <- case mDrepId of
464463
Nothing -> return Nothing
@@ -478,20 +477,20 @@ getProposal g@(GovActionId govActionTxHash govActionIndex) mDrepId' = do
478477
getEnactedProposalDetails :: App m => Maybe GovernanceActionType -> m (Maybe EnactedProposalDetailsResponse)
479478
getEnactedProposalDetails maybeType = do
480479
let proposalType = maybe "HardForkInitiation" governanceActionTypeToText maybeType
481-
480+
482481
mDetails <- Proposal.getPreviousEnactedProposal proposalType
483-
482+
484483
let response = enactedProposalDetailsToResponse <$> mDetails
485-
484+
486485
return response
487486
where
488487
governanceActionTypeToText :: GovernanceActionType -> Text
489-
governanceActionTypeToText actionType =
488+
governanceActionTypeToText actionType =
490489
case actionType of
491490
HardForkInitiation -> "HardForkInitiation"
492-
ParameterChange -> "ParameterChange"
493-
_ -> "HardForkInitiation"
494-
491+
ParameterChange -> "ParameterChange"
492+
_ -> "HardForkInitiation"
493+
495494
enactedProposalDetailsToResponse :: Types.EnactedProposalDetails -> EnactedProposalDetailsResponse
496495
enactedProposalDetailsToResponse Types.EnactedProposalDetails{..} =
497496
EnactedProposalDetailsResponse
@@ -513,7 +512,7 @@ getTransactionStatus (unHexText -> transactionId) = do
513512
return $ GetTransactionStatusResponse $ case status of
514513
Just value -> Just $ toJSON value
515514
Nothing -> Nothing
516-
515+
517516
throw500 :: App m => m ()
518517
throw500 = throwError $ CriticalError "intentional system break for testing purposes"
519518

govtool/backend/src/VVA/API/Types.hs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ instance ToParamSchema GovernanceActionType where
205205
& enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [GovernanceActionType])
206206

207207

208-
data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving (Bounded, Enum, Eq, Generic, Read, Show)
208+
data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving
209+
( Bounded
210+
, Enum
211+
, Eq
212+
, Generic
213+
, Read
214+
, Show
215+
)
209216

210217
instance FromJSON DRepSortMode where
211218
parseJSON (Aeson.String dRepSortMode) = pure $ fromJust $ readMaybe (Text.unpack dRepSortMode)
@@ -406,7 +413,8 @@ data ProposalResponse
406413
}
407414
deriving (Generic, Show)
408415

409-
newtype ProposalAuthors = ProposalAuthors { getProposalAuthors :: Value }
416+
newtype ProposalAuthors
417+
= ProposalAuthors { getProposalAuthors :: Value }
410418
deriving newtype (Show)
411419

412420
instance FromJSON ProposalAuthors where
@@ -659,7 +667,7 @@ data DRepInfoResponse
659667
, dRepInfoResponseGivenName :: Maybe Text
660668
, dRepInfoResponseObjectives :: Maybe Text
661669
, dRepInfoResponseMotivations :: Maybe Text
662-
, dRepInfoResponseQualifications :: Maybe Text
670+
, dRepInfoResponseQualifications :: Maybe Text
663671
, dRepInfoResponseImageUrl :: Maybe Text
664672
, dRepInfoResponseImageHash :: Maybe HexText
665673
}
@@ -906,7 +914,7 @@ data DRep
906914
, dRepGivenName :: Maybe Text
907915
, dRepObjectives :: Maybe Text
908916
, dRepMotivations :: Maybe Text
909-
, dRepQualifications :: Maybe Text
917+
, dRepQualifications :: Maybe Text
910918
, dRepImageUrl :: Maybe Text
911919
, dRepImageHash :: Maybe HexText
912920
, dRepIdentityReferences :: Maybe DRepReferences
@@ -1011,11 +1019,11 @@ instance ToSchema DelegationResponse where
10111019

10121020
data GetNetworkInfoResponse
10131021
= GetNetworkInfoResponse
1014-
{ getNetworkInfoResponseCurrentTime :: UTCTime
1015-
, getNetworkInfoResponseEpochNo :: Integer
1016-
, getNetworkInfoResponseBlockNo :: Integer
1017-
, getNetworkInfoResponseNetworkName :: Text
1018-
}
1022+
{ getNetworkInfoResponseCurrentTime :: UTCTime
1023+
, getNetworkInfoResponseEpochNo :: Integer
1024+
, getNetworkInfoResponseBlockNo :: Integer
1025+
, getNetworkInfoResponseNetworkName :: Text
1026+
}
10191027

10201028
deriveJSON (jsonOptions "getNetworkInfoResponse") ''GetNetworkInfoResponse
10211029

@@ -1035,11 +1043,11 @@ instance ToSchema GetNetworkInfoResponse where
10351043

10361044
data GetNetworkTotalStakeResponse
10371045
= GetNetworkTotalStakeResponse
1038-
{ getNetworkTotalStakeResponseTotalStakeControlledByDReps :: Integer
1039-
, getNetworkTotalStakeResponseTotalStakeControlledBySPOs :: Integer
1040-
, getNetworkTotalStakeResponseAlwaysAbstainVotingPower :: Integer
1041-
, getNetworkTotalStakeResponseAlwaysNoConfidenceVotingPower :: Integer
1042-
}
1046+
{ getNetworkTotalStakeResponseTotalStakeControlledByDReps :: Integer
1047+
, getNetworkTotalStakeResponseTotalStakeControlledBySPOs :: Integer
1048+
, getNetworkTotalStakeResponseAlwaysAbstainVotingPower :: Integer
1049+
, getNetworkTotalStakeResponseAlwaysNoConfidenceVotingPower :: Integer
1050+
}
10431051

10441052
deriveJSON (jsonOptions "getNetworkTotalStakeResponse") ''GetNetworkTotalStakeResponse
10451053

@@ -1113,10 +1121,8 @@ data GetAccountInfoResponse
11131121
deriving (Generic, Show)
11141122
deriveJSON (jsonOptions "getAccountInfoResponse") ''GetAccountInfoResponse
11151123

1116-
data UploadResponse
1117-
= UploadResponse
1118-
{ uploadResponseIpfsCid :: Text
1119-
}
1124+
newtype UploadResponse
1125+
= UploadResponse { uploadResponseIpfsCid :: Text }
11201126
deriving (Generic, Show)
11211127
deriveJSON (jsonOptions "uploadResponse") ''UploadResponse
11221128

govtool/backend/src/VVA/Account.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
{-# LANGUAGE FlexibleContexts #-}
1+
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TemplateHaskell #-}
3+
{-# LANGUAGE TemplateHaskell #-}
44

55
module VVA.Account where
66

77
import Control.Monad.Except (MonadError, throwError)
88
import Control.Monad.Reader (MonadIO, MonadReader, liftIO)
9+
910
import Data.ByteString (ByteString)
1011
import Data.FileEmbed (embedFile)
12+
import Data.Has (Has)
1113
import Data.String (fromString)
12-
import qualified Database.PostgreSQL.Simple as SQL
13-
import VVA.Types (AppError(..), AccountInfo(..))
1414
import Data.Text (Text, unpack)
1515
import qualified Data.Text.Encoding as Text
1616
import qualified Data.Text.IO as Text
17-
import Data.Has (Has)
17+
18+
import qualified Database.PostgreSQL.Simple as SQL
19+
1820
import VVA.Pool (ConnectionPool, withPool)
21+
import VVA.Types (AccountInfo (..), AppError (..))
1922

2023
sqlFrom :: ByteString -> SQL.Query
2124
sqlFrom = fromString . unpack . Text.decodeUtf8

govtool/backend/src/VVA/AdaHolder.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
34
{-# LANGUAGE TemplateHaskell #-}
45
{-# LANGUAGE TypeApplications #-}
5-
{-# LANGUAGE ScopedTypeVariables #-}
66

77
module VVA.AdaHolder where
88

9-
import Control.Exception (try, SomeException)
9+
import Control.Exception (SomeException, try)
1010
import Control.Monad.Except
1111
import Control.Monad.Reader
1212

@@ -65,4 +65,4 @@ getStakeKeyVotingPower stakeKey = withPool $ \conn -> do
6565
return 0
6666
Right _ -> do
6767
Text.putStrLn ("Unexpected result for stake key: " <> stakeKey)
68-
return 0
68+
return 0

0 commit comments

Comments
 (0)