Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ changes.
### Added

- Add redirection to outcomes when proposal is not found [Issue 3230](https://github.com/IntersectMBO/govtool/issues/3230)
- Add drep voting power list endpoint [Issue 3263](https://github.com/IntersectMBO/govtool/issues/3263)
- Add DRep voting power list endpoint [Issue 3263](https://github.com/IntersectMBO/govtool/issues/3263)
- Add DRep given name to the voting power list endpoint [Issue 3273](https://github.com/IntersectMBO/govtool/issues/3273)

### Fixed

Expand Down
35 changes: 33 additions & 2 deletions govtool/backend/sql/get-dreps-voting-power-list.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
WITH LatestExistingVotingAnchor AS (
SELECT
subquery.drep_registration_id,
subquery.drep_hash_id,
subquery.voting_anchor_id,
subquery.url,
subquery.metadata_hash,
subquery.ocvd_id
FROM (
SELECT
dr.id AS drep_registration_id,
dr.drep_hash_id,
va.id AS voting_anchor_id,
va.url,
encode(va.data_hash, 'hex') AS metadata_hash,
ocvd.id AS ocvd_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
WHERE
ocvd.voting_anchor_id IS NOT NULL
) subquery
WHERE
subquery.rn = 1
)
SELECT DISTINCT ON (raw)
view,
encode(raw, 'hex') AS hash_raw,
COALESCE(dd.amount, 0) AS voting_power
COALESCE(dd.amount, 0) AS voting_power,
ocvdd.given_name
FROM drep_hash dh
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
LEFT JOIN LatestExistingVotingAnchor leva ON leva.drep_hash_id = dh.id
LEFT JOIN off_chain_vote_data ocvd ON ocvd.id = leva.ocvd_id
LEFT JOIN off_chain_vote_drep_data ocvdd ON ocvdd.off_chain_vote_data_id = ocvd.id
33 changes: 32 additions & 1 deletion govtool/backend/sql/get-filtered-dreps-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
WITH LatestExistingVotingAnchor AS (
SELECT
subquery.drep_registration_id,
subquery.drep_hash_id,
subquery.voting_anchor_id,
subquery.url,
subquery.metadata_hash,
subquery.ocvd_id
FROM (
SELECT
dr.id AS drep_registration_id,
dr.drep_hash_id,
va.id AS voting_anchor_id,
va.url,
encode(va.data_hash, 'hex') AS metadata_hash,
ocvd.id AS ocvd_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
WHERE
ocvd.voting_anchor_id IS NOT NULL
) subquery
WHERE
subquery.rn = 1
)
SELECT DISTINCT ON (raw)
view,
encode(raw, 'hex') AS hash_raw,
COALESCE(dd.amount, 0) AS voting_power
COALESCE(dd.amount, 0) AS voting_power,
ocvdd.given_name
FROM drep_hash dh
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
LEFT JOIN LatestExistingVotingAnchor leva ON leva.drep_hash_id = dh.id
LEFT JOIN off_chain_vote_data ocvd ON ocvd.id = leva.ocvd_id
LEFT JOIN off_chain_vote_drep_data ocvdd ON ocvdd.off_chain_vote_data_id = ocvd.id
WHERE view = ? OR encode(raw, 'hex') = ?
1 change: 1 addition & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ drepVotingPowerList identifiers = do
{ drepVotingPowerListResponseView = drepView
, drepVotingPowerListResponseHashRaw = HexText drepHashRaw
, drepVotingPowerListResponseVotingPower = drepVotingPower
, drepVotingPowerListResponseGivenName = drepGivenName
}

getCurrentDelegation :: App m => HexText -> m (Maybe DelegationResponse)
Expand Down
4 changes: 3 additions & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ data DRepVotingPowerListResponse
{ drepVotingPowerListResponseView :: Text
, drepVotingPowerListResponseHashRaw :: HexText
, drepVotingPowerListResponseVotingPower :: Integer
, drepVotingPowerListResponseGivenName :: Maybe Text
}
deriving (Generic, Show)

Expand All @@ -636,7 +637,8 @@ exampleDRepVotingPowerListResponse :: Text
exampleDRepVotingPowerListResponse =
"{\"view\": \"drep1qq5n7k0r0ff6lf4qvndw9t7vmdqa9y3q9qtjq879rrk9vcjcdy8a4xf92mqsajf9u3nrsh3r6zrp29kuydmfq45fz88qpzmjkc\","
<> "\"hashRaw\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"votingPower\": 1000000}"
<> "\"votingPower\": 1000000,"
<> "\"givenName\": \"John Doe\"}"

instance ToSchema DRepVotingPowerListResponse where
declareNamedSchema proxy = do
Expand Down
4 changes: 2 additions & 2 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ getDRepsVotingPowerList identifiers = withPool $ \conn -> do
return $ concat resultsPerIdentifier

return
[ DRepVotingPowerList view hashRaw votingPower
| (view, hashRaw, votingPower') <- results
[ DRepVotingPowerList view hashRaw votingPower givenName
| (view, hashRaw, votingPower', givenName) <- results
, let votingPower = floor @Scientific votingPower'
]
1 change: 1 addition & 0 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ data DRepVotingPowerList
{ drepView :: Text
, drepHashRaw :: Text
, drepVotingPower :: Integer
, drepGivenName :: Maybe Text
}
deriving (Show, Eq)

Expand Down