Skip to content

Commit 91758bd

Browse files
authored
Merge pull request #2250 from IntersectMBO/develop
GovTool-v1.0.23
2 parents c80d37d + 59ed1f2 commit 91758bd

File tree

86 files changed

+270
-9676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+270
-9676
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ changes.
2626

2727
-
2828

29+
## [v1.0.23](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.23) 2024-10-28
30+
31+
### Added
32+
33+
- Add searching for DRep and Proposal metadatas [Issue 1893](https://github.com/IntersectMBO/govtool/issues/1783)
34+
35+
### Fixed
36+
37+
- Fix validating metadata against the CIP standard [Issue 2233](https://github.com/IntersectMBO/govtool/issues/2233)
38+
- Fix counting the CC votes [Issue 2247](https://github.com/IntersectMBO/govtool/issues/2247)
39+
40+
### Changed
41+
42+
-
43+
44+
### Removed
45+
46+
-
47+
2948
## [v1.0.22](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.22) 2024-10-24
3049

3150
### Added
@@ -43,6 +62,7 @@ changes.
4362
### Changed
4463

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

4767
### Removed
4868

govtool/backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
44
WORKDIR /src
55
COPY . .
66
RUN cabal build
7-
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
7+
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

govtool/backend/Dockerfile.qovery

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
44
WORKDIR /src
55
COPY . .
66
RUN cabal build
7-
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
7+
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
88

99
# Expose the necessary port
1010
EXPOSE 9876

govtool/backend/sql/list-dreps.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ FROM
134134
AND dr_first_register.rn = 1
135135
LEFT JOIN tx AS tx_first_register ON tx_first_register.id = dr_first_register.tx_id
136136
LEFT JOIN block AS block_first_register ON block_first_register.id = tx_first_register.block_id
137+
WHERE
138+
(
139+
COALESCE(?, '') = '' OR
140+
dh.view ILIKE ? OR
141+
off_chain_vote_drep_data.given_name ILIKE ?
142+
)
137143
GROUP BY
138144
dh.raw,
139145
second_to_newest_drep_registration.voting_anchor_id,

govtool/backend/sql/list-proposals.sql

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,30 @@ FROM
129129
SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS ccNoVotes,
130130
SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS ccAbstainVotes
131131
FROM
132-
voting_procedure
132+
voting_procedure AS vp
133133
WHERE
134-
committee_voter IS NOT NULL
134+
vp.committee_voter IS NOT NULL
135+
AND (vp.tx_id, vp.committee_voter, vp.gov_action_proposal_id) IN (
136+
SELECT MAX(tx_id), committee_voter, gov_action_proposal_id
137+
FROM voting_procedure
138+
WHERE committee_voter IS NOT NULL
139+
GROUP BY committee_voter, gov_action_proposal_id
140+
)
135141
GROUP BY
136142
gov_action_proposal_id
137143
) vp_by_cc
138144
ON gov_action_proposal.id = vp_by_cc.gov_action_proposal_id
139-
140145
LEFT JOIN LatestDrepDistr ldd_cc ON ldd_cc.hash_id = voting_procedure.committee_voter
141146
AND ldd_cc.rn = 1
142147
LEFT JOIN gov_action_proposal AS prev_gov_action ON gov_action_proposal.prev_gov_action_proposal = prev_gov_action.id
143148
LEFT JOIN tx AS prev_gov_action_tx ON prev_gov_action.tx_id = prev_gov_action_tx.id
144-
WHERE (NOT ?
145-
OR (concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) IN ?))
149+
WHERE
150+
(COALESCE(?, '') = '' OR
151+
off_chain_vote_gov_action_data.title ILIKE ? OR
152+
off_chain_vote_gov_action_data.abstract ILIKE ? OR
153+
off_chain_vote_gov_action_data.motivation ILIKE ? OR
154+
off_chain_vote_gov_action_data.rationale ILIKE ? OR
155+
concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) ILIKE ?)
146156
AND gov_action_proposal.expiration >(
147157
SELECT
148158
Max(NO)

govtool/backend/src/VVA/API.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ delegationToResponse Types.Delegation {..} =
140140
drepList :: App m => Maybe Text -> [DRepStatus] -> Maybe DRepSortMode -> Maybe Natural -> Maybe Natural -> m ListDRepsResponse
141141
drepList mSearchQuery statuses mSortMode mPage mPageSize = do
142142
CacheEnv {dRepListCache} <- asks vvaCache
143-
dreps <- cacheRequest dRepListCache () DRep.listDReps
143+
dreps <- cacheRequest dRepListCache () (DRep.listDReps mSearchQuery)
144144

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

360-
361360
CacheEnv {proposalListCache} <- asks vvaCache
362-
mappedAndSortedProposals <- do
363-
proposals <- cacheRequest proposalListCache () Proposal.listProposals
364-
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
365-
return $ filter
366-
( \p@ProposalResponse {proposalResponseId} ->
367-
proposalResponseId `notElem` proposalsToRemove
368-
&& isProposalSearchedFor mSearchQuery p
369-
) mappedSortedAndFilteredProposals
370-
371-
let total = length mappedAndSortedProposals :: Int
372-
373-
let elements = take pageSize $ drop (page * pageSize) mappedAndSortedProposals
361+
362+
proposals <- cacheRequest proposalListCache () (Proposal.listProposals mSearchQuery)
363+
364+
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
365+
let filteredProposals = filter
366+
( \p@ProposalResponse {proposalResponseId} ->
367+
proposalResponseId `notElem` proposalsToRemove
368+
&& isProposalSearchedFor mSearchQuery p
369+
) mappedSortedAndFilteredProposals
370+
371+
let total = length filteredProposals :: Int
372+
373+
let elements = take pageSize $ drop (page * pageSize) filteredProposals
374374

375375
return $ ListProposalsResponse
376376
{ listProposalsResponsePage = fromIntegral page

govtool/backend/src/VVA/AdaHolder.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import VVA.Types
2929
sqlFrom :: ByteString -> SQL.Query
3030
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs
3131

32-
listDRepsSql :: SQL.Query
33-
listDRepsSql = sqlFrom $(embedFile "sql/list-dreps.sql")
34-
3532
getCurrentDelegationSql :: SQL.Query
3633
getCurrentDelegationSql = sqlFrom $(embedFile "sql/get-current-delegation.sql")
3734

govtool/backend/src/VVA/DRep.hs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import qualified Data.Text.Encoding as Text
2626
import Data.Time
2727

2828
import qualified Database.PostgreSQL.Simple as SQL
29-
3029
import VVA.Config
3130
import VVA.Pool (ConnectionPool, withPool)
3231
import qualified VVA.Proposal as Proposal
@@ -36,29 +35,19 @@ import VVA.Types (AppError, DRepInfo (..), DRepRegist
3635
sqlFrom :: ByteString -> SQL.Query
3736
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs
3837

39-
getVotingPowerSql :: SQL.Query
40-
getVotingPowerSql = sqlFrom $(embedFile "sql/get-voting-power.sql")
41-
42-
getVotingPower ::
43-
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m) =>
44-
Text ->
45-
m Integer
46-
getVotingPower drepId = withPool $ \conn -> do
47-
result <-
48-
liftIO
49-
(SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ SQL.Only drepId)
50-
case result of
51-
[SQL.Only votingPower] -> return $ floor votingPower
52-
[] -> return 0
53-
5438
listDRepsSql :: SQL.Query
5539
listDRepsSql = sqlFrom $(embedFile "sql/list-dreps.sql")
5640

5741
listDReps ::
5842
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m) =>
59-
m [DRepRegistration]
60-
listDReps = withPool $ \conn -> do
61-
results <- liftIO $ SQL.query_ conn listDRepsSql
43+
Maybe Text -> m [DRepRegistration]
44+
listDReps mSearchQuery = withPool $ \conn -> do
45+
let searchParam = fromMaybe "" mSearchQuery
46+
results <- liftIO $ SQL.query conn listDRepsSql
47+
( searchParam
48+
, "%" <> searchParam <> "%"
49+
, "%" <> searchParam <> "%"
50+
)
6251
timeZone <- liftIO getCurrentTimeZone
6352
return
6453
[ DRepRegistration drepHash drepView isScriptBased url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash
@@ -95,6 +84,19 @@ listDReps = withPool $ \conn -> do
9584
| Data.Maybe.isJust url = DRep
9685
]
9786

87+
getVotingPowerSql :: SQL.Query
88+
getVotingPowerSql = sqlFrom $(embedFile "sql/get-voting-power.sql")
89+
90+
getVotingPower ::
91+
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m) =>
92+
Text ->
93+
m Integer
94+
getVotingPower drepId = withPool $ \conn -> do
95+
result <- liftIO (SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ SQL.Only drepId)
96+
case result of
97+
[SQL.Only votingPower] -> return $ floor votingPower
98+
[] -> return 0
99+
98100
getVotesSql :: SQL.Query
99101
getVotesSql = sqlFrom $(embedFile "sql/get-votes.sql")
100102

govtool/backend/src/VVA/Proposal.hs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ import qualified Data.Text.IO as Text
2828
import Data.Time
2929

3030
import qualified Database.PostgreSQL.Simple as SQL
31-
32-
import qualified GHC.Generics as SQL
33-
34-
import Text.Read (readMaybe)
31+
import qualified Database.PostgreSQL.Simple.Types as PG
32+
import Database.PostgreSQL.Simple.ToField (ToField(..))
33+
import Database.PostgreSQL.Simple.ToRow (ToRow(..))
3534

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

45+
newtype TextArray = TextArray [Text]
46+
47+
instance ToRow TextArray where
48+
toRow (TextArray texts) = map toField texts
49+
4650
listProposals ::
4751
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
48-
m [Proposal]
49-
listProposals = getProposals Nothing
52+
Maybe Text -> m [Proposal]
53+
listProposals mSearch = getProposals (fmap (:[]) mSearch)
5054

5155
getProposal ::
5256
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
5357
Text ->
5458
Integer ->
5559
m Proposal
5660
getProposal txHash index = do
57-
result <- getProposals (Just [txHash <> "#" <> pack (show index)])
61+
let proposalId = txHash <> "#" <> pack (show index)
62+
result <- getProposals (Just [proposalId])
5863
case result of
59-
[] -> throwError $ NotFoundError ("Proposal with id: " <> txHash <> "#" <> pack (show index) <> " not found")
64+
[] -> throwError $ NotFoundError ("Proposal with id: " <> proposalId <> " not found")
6065
[a] -> return a
61-
_ -> throwError $ CriticalError ("Multiple proposal found for id: " <> txHash <> "#" <> pack (show index) <> ". This should never happen")
66+
_ -> throwError $ CriticalError ("Multiple proposals found for id: " <> proposalId <> ". This should never happen")
6267

6368
getProposals ::
6469
(Has ConnectionPool r, Has VVAConfig r, MonadReader r m, MonadIO m, MonadFail m, MonadError AppError m) =>
65-
Maybe [Text] ->
66-
m [Proposal]
67-
getProposals mProposalIds = withPool $ \conn ->
68-
liftIO $ case mProposalIds of
69-
Nothing -> SQL.query @(Bool, SQL.In [Text]) conn listProposalsSql (False, SQL.In [])
70-
Just proposalIds -> SQL.query conn listProposalsSql (True, SQL.In proposalIds)
70+
Maybe [Text] -> m [Proposal]
71+
getProposals mSearchTerms = withPool $ \conn -> do
72+
let searchParam = maybe "" head mSearchTerms
73+
liftIO $ SQL.query conn listProposalsSql
74+
( searchParam
75+
, "%" <> searchParam <> "%"
76+
, "%" <> searchParam <> "%"
77+
, "%" <> searchParam <> "%"
78+
, "%" <> searchParam <> "%"
79+
, "%" <> searchParam <> "%"
80+
)

govtool/backend/vva-be.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.6
22
name: vva-be
3-
version: 1.0.22
3+
version: 1.0.23
44

55
-- A short (one-line) description of the package.
66
-- synopsis:

0 commit comments

Comments
 (0)