|
1 | | -{-# LANGUAGE FlexibleContexts #-} |
2 | | -{-# LANGUAGE OverloadedStrings #-} |
3 | | -{-# LANGUAGE TemplateHaskell #-} |
4 | | -{-# LANGUAGE TypeApplications #-} |
| 1 | +{-# LANGUAGE FlexibleContexts #-} |
| 2 | +{-# LANGUAGE OverloadedStrings #-} |
| 3 | +{-# LANGUAGE TemplateHaskell #-} |
| 4 | +{-# LANGUAGE TypeApplications #-} |
| 5 | +{-# LANGUAGE ScopedTypeVariables #-} |
5 | 6 |
|
6 | 7 | module VVA.AdaHolder where |
7 | 8 |
|
| 9 | +import Control.Exception (try, SomeException) |
8 | 10 | import Control.Monad.Except |
9 | 11 | import Control.Monad.Reader |
10 | 12 |
|
@@ -51,9 +53,11 @@ getStakeKeyVotingPower :: |
51 | 53 | Text -> |
52 | 54 | m Integer |
53 | 55 | getStakeKeyVotingPower stakeKey = withPool $ \conn -> do |
54 | | - result <- liftIO $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey) |
55 | | - case result of |
56 | | - [(votingPower,_)] -> return $ floor votingPower |
57 | | - _ -> do |
58 | | - liftIO $ Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey) |
59 | | - return 0 |
| 56 | + liftIO $ do |
| 57 | + result <- try $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey) |
| 58 | + case result of |
| 59 | + Left (e :: SomeException) -> do |
| 60 | + Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey) |
| 61 | + return 0 |
| 62 | + Right [(votingPower,_)] -> return $ floor votingPower |
| 63 | + _ -> error ("multiple voting power entries for stake key: " <> unpack stakeKey) |
0 commit comments