@@ -15,7 +15,7 @@ import Control.Monad.Reader
1515
1616import Data.Aeson (Value (.. ), Array , decode , encode , ToJSON , toJSON )
1717import Data.Bool (Bool )
18- import Data.List (sortOn )
18+ import Data.List (sortOn , sort )
1919import qualified Data.Map as Map
2020import Data.Maybe (Maybe (Nothing ), catMaybes , fromMaybe , mapMaybe )
2121import Data.Ord (Down (.. ))
@@ -64,6 +64,9 @@ type VVAApi =
6464 :> QueryParam " search" Text
6565 :> Get '[JSON ] [VoteResponse ]
6666 :<|> " drep" :> " info" :> Capture " drepId" HexText :> Get '[JSON ] DRepInfoResponse
67+ :<|> " drep" :> " voting-power-list"
68+ :> QueryParams " identifiers" Text
69+ :> Get '[JSON ] [DRepVotingPowerListResponse ]
6770 :<|> " ada-holder" :> " get-current-delegation" :> Capture " stakeKey" HexText :> Get '[JSON ] (Maybe DelegationResponse )
6871 :<|> " ada-holder" :> " get-voting-power" :> Capture " stakeKey" HexText :> Get '[JSON ] Integer
6972 :<|> " proposal" :> " list"
@@ -87,6 +90,7 @@ server = drepList
8790 :<|> getVotingPower
8891 :<|> getVotes
8992 :<|> drepInfo
93+ :<|> drepVotingPowerList
9094 :<|> getCurrentDelegation
9195 :<|> getStakeKeyVotingPower
9296 :<|> listProposals
@@ -283,18 +287,20 @@ getVotes (unHexText -> dRepId) selectedTypes sortMode mSearch = do
283287 CacheEnv {dRepGetVotesCache} <- asks vvaCache
284288 (votes, proposals) <- cacheRequest dRepGetVotesCache dRepId $ DRep. getVotes dRepId []
285289
286- let voteMap = Map. fromList $ map (\ vote@ Types. Vote {.. } -> (voteProposalId, vote)) votes
287-
288- processedProposals <- filter (isProposalSearchedFor mSearch) <$> mapSortAndFilterProposals selectedTypes sortMode proposals
289-
290+ let voteMapByTxHash = Map. fromList $
291+ map (\ vote -> (pack $ Prelude. takeWhile (/= ' #' ) (unpack $ Types. voteGovActionId vote), vote)) votes
292+
293+ processedProposals <- filter (isProposalSearchedFor mSearch) <$>
294+ mapSortAndFilterProposals selectedTypes sortMode proposals
295+
290296 return $
291297 [ VoteResponse
292298 { voteResponseVote = voteToResponse vote
293299 , voteResponseProposal = proposalResponse
294300 }
295- | proposalResponse@ ProposalResponse {proposalResponseId} <- processedProposals
296- , let proposalIdInt = read (unpack proposalResponseId) :: Int
297- , Just vote <- [Map. lookup ( toInteger proposalIdInt) voteMap ]
301+ | proposalResponse <- processedProposals
302+ , let txHash = unHexText (proposalResponseTxHash proposalResponse)
303+ , Just vote <- [Map. lookup txHash voteMapByTxHash ]
298304 ]
299305
300306drepInfo :: App m => HexText -> m DRepInfoResponse
@@ -324,6 +330,25 @@ drepInfo (unHexText -> dRepId) = do
324330 , dRepInfoResponseImageHash = HexText <$> dRepInfoImageHash
325331 }
326332
333+ drepVotingPowerList :: App m => [Text ] -> m [DRepVotingPowerListResponse ]
334+ drepVotingPowerList identifiers = do
335+ CacheEnv {dRepVotingPowerListCache} <- asks vvaCache
336+
337+ let cacheKey = Text. intercalate " ," (sort identifiers)
338+
339+ results <- cacheRequest dRepVotingPowerListCache cacheKey $
340+ DRep. getDRepsVotingPowerList identifiers
341+
342+ return $ map toDRepVotingPowerListResponse results
343+ where
344+ toDRepVotingPowerListResponse Types. DRepVotingPowerList {.. } =
345+ DRepVotingPowerListResponse
346+ { drepVotingPowerListResponseView = drepView
347+ , drepVotingPowerListResponseHashRaw = HexText drepHashRaw
348+ , drepVotingPowerListResponseVotingPower = drepVotingPower
349+ , drepVotingPowerListResponseGivenName = drepGivenName
350+ }
351+
327352getCurrentDelegation :: App m => HexText -> m (Maybe DelegationResponse )
328353getCurrentDelegation (unHexText -> stakeKey) = do
329354 CacheEnv {adaHolderGetCurrentDelegationCache} <- asks vvaCache
0 commit comments