Skip to content

Commit

Permalink
Merge pull request #2271 from IntersectMBO/staging
Browse files Browse the repository at this point in the history
GovTool v1.0.23
  • Loading branch information
MSzalowski authored Oct 29, 2024
2 parents 9160a09 + 5f5fb5a commit d43c189
Show file tree
Hide file tree
Showing 86 changed files with 287 additions and 9,687 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ changes.

-

## [v1.0.23](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.23) 2024-10-29

### Added

- Add searching for DRep and Proposal metadatas [Issue 1893](https://github.com/IntersectMBO/govtool/issues/1783)

### Fixed

- Fix validating metadata against the CIP standard [Issue 2233](https://github.com/IntersectMBO/govtool/issues/2233)
- Fix counting the CC votes [Issue 2247](https://github.com/IntersectMBO/govtool/issues/2247)

### Changed

-

### Removed

-

## [v1.0.22](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.22) 2024-10-24

### Added
Expand All @@ -43,6 +62,7 @@ changes.
### Changed

- Bump to use Cardano Node `10.0.0-pre`
- Changed copy for no DRep found via search

### Removed

Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.22/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.23/x/vva-be/build/vva-be/vva-be /usr/local/bin
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile.qovery
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.22/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.23/x/vva-be/build/vva-be/vva-be /usr/local/bin

# Expose the necessary port
EXPOSE 9876
Expand Down
6 changes: 6 additions & 0 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ FROM
AND dr_first_register.rn = 1
LEFT JOIN tx AS tx_first_register ON tx_first_register.id = dr_first_register.tx_id
LEFT JOIN block AS block_first_register ON block_first_register.id = tx_first_register.block_id
WHERE
(
COALESCE(?, '') = '' OR
dh.view ILIKE ? OR
off_chain_vote_drep_data.given_name ILIKE ?
)
GROUP BY
dh.raw,
second_to_newest_drep_registration.voting_anchor_id,
Expand Down
20 changes: 15 additions & 5 deletions govtool/backend/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,30 @@ FROM
SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS ccNoVotes,
SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS ccAbstainVotes
FROM
voting_procedure
voting_procedure AS vp
WHERE
committee_voter IS NOT NULL
vp.committee_voter IS NOT NULL
AND (vp.tx_id, vp.committee_voter, vp.gov_action_proposal_id) IN (
SELECT MAX(tx_id), committee_voter, gov_action_proposal_id
FROM voting_procedure
WHERE committee_voter IS NOT NULL
GROUP BY committee_voter, gov_action_proposal_id
)
GROUP BY
gov_action_proposal_id
) vp_by_cc
ON gov_action_proposal.id = vp_by_cc.gov_action_proposal_id

LEFT JOIN LatestDrepDistr ldd_cc ON ldd_cc.hash_id = voting_procedure.committee_voter
AND ldd_cc.rn = 1
LEFT JOIN gov_action_proposal AS prev_gov_action ON gov_action_proposal.prev_gov_action_proposal = prev_gov_action.id
LEFT JOIN tx AS prev_gov_action_tx ON prev_gov_action.tx_id = prev_gov_action_tx.id
WHERE (NOT ?
OR (concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) IN ?))
WHERE
(COALESCE(?, '') = '' OR
off_chain_vote_gov_action_data.title ILIKE ? OR
off_chain_vote_gov_action_data.abstract ILIKE ? OR
off_chain_vote_gov_action_data.motivation ILIKE ? OR
off_chain_vote_gov_action_data.rationale ILIKE ? OR
concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) ILIKE ?)
AND gov_action_proposal.expiration >(
SELECT
Max(NO)
Expand Down
28 changes: 14 additions & 14 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ delegationToResponse Types.Delegation {..} =
drepList :: App m => Maybe Text -> [DRepStatus] -> Maybe DRepSortMode -> Maybe Natural -> Maybe Natural -> m ListDRepsResponse
drepList mSearchQuery statuses mSortMode mPage mPageSize = do
CacheEnv {dRepListCache} <- asks vvaCache
dreps <- cacheRequest dRepListCache () DRep.listDReps
dreps <- cacheRequest dRepListCache () (DRep.listDReps mSearchQuery)

let filterDRepsByQuery = case mSearchQuery of
Nothing -> filter $ \Types.DRepRegistration {..} -> dRepRegistrationType == Types.DRep
Expand Down Expand Up @@ -357,20 +357,20 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
map (voteParamsProposalId . voteResponseVote)
<$> getVotes drepId [] Nothing Nothing


CacheEnv {proposalListCache} <- asks vvaCache
mappedAndSortedProposals <- do
proposals <- cacheRequest proposalListCache () Proposal.listProposals
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
return $ filter
( \p@ProposalResponse {proposalResponseId} ->
proposalResponseId `notElem` proposalsToRemove
&& isProposalSearchedFor mSearchQuery p
) mappedSortedAndFilteredProposals

let total = length mappedAndSortedProposals :: Int

let elements = take pageSize $ drop (page * pageSize) mappedAndSortedProposals

proposals <- cacheRequest proposalListCache () (Proposal.listProposals mSearchQuery)

mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
let filteredProposals = filter
( \p@ProposalResponse {proposalResponseId} ->
proposalResponseId `notElem` proposalsToRemove
&& isProposalSearchedFor mSearchQuery p
) mappedSortedAndFilteredProposals

let total = length filteredProposals :: Int

let elements = take pageSize $ drop (page * pageSize) filteredProposals

return $ ListProposalsResponse
{ listProposalsResponsePage = fromIntegral page
Expand Down
3 changes: 0 additions & 3 deletions govtool/backend/src/VVA/AdaHolder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import VVA.Types
sqlFrom :: ByteString -> SQL.Query
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs

listDRepsSql :: SQL.Query
listDRepsSql = sqlFrom $(embedFile "sql/list-dreps.sql")

getCurrentDelegationSql :: SQL.Query
getCurrentDelegationSql = sqlFrom $(embedFile "sql/get-current-delegation.sql")

Expand Down
68 changes: 38 additions & 30 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import qualified Data.Text.Encoding as Text
import Data.Time

import qualified Database.PostgreSQL.Simple as SQL

import VVA.Config
import VVA.Pool (ConnectionPool, withPool)
import qualified VVA.Proposal as Proposal
Expand All @@ -36,29 +35,19 @@ import VVA.Types (AppError, DRepInfo (..), DRepRegist
sqlFrom :: ByteString -> SQL.Query
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs

getVotingPowerSql :: SQL.Query
getVotingPowerSql = sqlFrom $(embedFile "sql/get-voting-power.sql")

getVotingPower ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m) =>
Text ->
m Integer
getVotingPower drepId = withPool $ \conn -> do
result <-
liftIO
(SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ SQL.Only drepId)
case result of
[SQL.Only votingPower] -> return $ floor votingPower
[] -> return 0

listDRepsSql :: SQL.Query
listDRepsSql = sqlFrom $(embedFile "sql/list-dreps.sql")

listDReps ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m) =>
m [DRepRegistration]
listDReps = withPool $ \conn -> do
results <- liftIO $ SQL.query_ conn listDRepsSql
Maybe Text -> m [DRepRegistration]
listDReps mSearchQuery = withPool $ \conn -> do
let searchParam = fromMaybe "" mSearchQuery
results <- liftIO $ SQL.query conn listDRepsSql
( searchParam
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
)
timeZone <- liftIO getCurrentTimeZone
return
[ DRepRegistration drepHash drepView isScriptBased url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash
Expand Down Expand Up @@ -95,6 +84,19 @@ listDReps = withPool $ \conn -> do
| Data.Maybe.isJust url = DRep
]

getVotingPowerSql :: SQL.Query
getVotingPowerSql = sqlFrom $(embedFile "sql/get-voting-power.sql")

getVotingPower ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m) =>
Text ->
m Integer
getVotingPower drepId = withPool $ \conn -> do
result <- liftIO (SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ SQL.Only drepId)
case result of
[SQL.Only votingPower] -> return $ floor votingPower
[] -> return 0

getVotesSql :: SQL.Query
getVotesSql = sqlFrom $(embedFile "sql/get-votes.sql")

Expand All @@ -105,17 +107,23 @@ getVotes ::
m ([Vote], [Proposal])
getVotes drepId selectedProposals = withPool $ \conn -> do
results <- liftIO $ SQL.query conn getVotesSql (SQL.Only drepId)
let proposalsToSelect = if null selectedProposals
then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results]
else selectedProposals
proposals <- Proposal.getProposals (Just proposalsToSelect)
let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals
timeZone <- liftIO getCurrentTimeZone
return
([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
], proposals)

if null results
then return ([], [])
else do
let proposalsToSelect = if null selectedProposals
then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results]
else selectedProposals
proposals <- if null proposalsToSelect
then return []
else Proposal.getProposals (Just proposalsToSelect)
let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals
timeZone <- liftIO getCurrentTimeZone
let votes = [ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
]
return (votes, proposals)

getDRepInfoSql :: SQL.Query
getDRepInfoSql = sqlFrom $(embedFile "sql/get-drep-info.sql")
Expand Down
40 changes: 25 additions & 15 deletions govtool/backend/src/VVA/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import qualified Data.Text.IO as Text
import Data.Time

import qualified Database.PostgreSQL.Simple as SQL

import qualified GHC.Generics as SQL

import Text.Read (readMaybe)
import qualified Database.PostgreSQL.Simple.Types as PG
import Database.PostgreSQL.Simple.ToField (ToField(..))
import Database.PostgreSQL.Simple.ToRow (ToRow(..))

import VVA.Config
import VVA.Pool (ConnectionPool, withPool)
Expand All @@ -43,28 +42,39 @@ sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs
listProposalsSql :: SQL.Query
listProposalsSql = sqlFrom $(embedFile "sql/list-proposals.sql")

newtype TextArray = TextArray [Text]

instance ToRow TextArray where
toRow (TextArray texts) = map toField texts

listProposals ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
m [Proposal]
listProposals = getProposals Nothing
Maybe Text -> m [Proposal]
listProposals mSearch = getProposals (fmap (:[]) mSearch)

getProposal ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
Text ->
Integer ->
m Proposal
getProposal txHash index = do
result <- getProposals (Just [txHash <> "#" <> pack (show index)])
let proposalId = txHash <> "#" <> pack (show index)
result <- getProposals (Just [proposalId])
case result of
[] -> throwError $ NotFoundError ("Proposal with id: " <> txHash <> "#" <> pack (show index) <> " not found")
[] -> throwError $ NotFoundError ("Proposal with id: " <> proposalId <> " not found")
[a] -> return a
_ -> throwError $ CriticalError ("Multiple proposal found for id: " <> txHash <> "#" <> pack (show index) <> ". This should never happen")
_ -> throwError $ CriticalError ("Multiple proposals found for id: " <> proposalId <> ". This should never happen")

getProposals ::
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
Maybe [Text] ->
m [Proposal]
getProposals mProposalIds = withPool $ \conn ->
liftIO $ case mProposalIds of
Nothing -> SQL.query @(Bool, SQL.In [Text]) conn listProposalsSql (False, SQL.In [])
Just proposalIds -> SQL.query conn listProposalsSql (True, SQL.In proposalIds)
Maybe [Text] -> m [Proposal]
getProposals mSearchTerms = withPool $ \conn -> do
let searchParam = maybe "" head mSearchTerms
liftIO $ SQL.query conn listProposalsSql
( searchParam
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
)
2 changes: 1 addition & 1 deletion govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.6
name: vva-be
version: 1.0.22
version: 1.0.23

-- A short (one-line) description of the package.
-- synopsis:
Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions govtool/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@govtool/frontend",
"private": true,
"version": "1.0.22",
"version": "1.0.23",
"type": "module",
"scripts": {
"build": "vite build",
Expand Down Expand Up @@ -109,5 +109,5 @@
"typescript": "^5.0.2"
},
"readme": "ERROR: No README data found!",
"_id": "govtool@1.0.22"
"_id": "govtool@1.0.23"
}
18 changes: 10 additions & 8 deletions govtool/frontend/src/components/molecules/GovernanceActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({ ...props }) => {
title={title}
isDataMissing={metadataStatus}
/>
<GovernanceActionCardElement
label={t("govActions.abstract")}
text={abstract}
textVariant="twoLines"
dataTestId="governance-action-abstract"
isSliderCard
isMarkdown
/>
{!metadataStatus && (
<GovernanceActionCardElement
label={t("govActions.abstract")}
text={abstract}
textVariant="twoLines"
dataTestId="governance-action-abstract"
isSliderCard
isMarkdown
/>
)}
<GovernanceActionCardElement
label={t("govActions.governanceActionType")}
text={getProposalTypeLabel(type)}
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export const en = {
"Select this to signal no confidence in the current constitutional committee by voting NO on every proposal and voting YES to no confidence proposals",
noConfidenceDefaultTitle: "Signal No Confidence on Every Vote",
noResultsForTheSearchTitle: "No DReps found",
noResultsForTheSearchDescription: "Please try a different search",
noResultsForTheSearchDescription: "If you can't find the DRep you're looking for, either they are not registered, requested not to be listed in the DRep Directory, or did not submit correct metadata during registration.",
title: "DRep Directory",
votingPower: "Voting Power",
},
Expand Down
Loading

0 comments on commit d43c189

Please sign in to comment.