Skip to content

Commit d99f342

Browse files
authored
Merge pull request #3276 from IntersectMBO/feat/3273-add-given-name-to-list-of-dreps-voting-power-endpoint
feat(#3273): add given name to drep voting power list endpoint
2 parents c94ff7a + 324c9db commit d99f342

File tree

7 files changed

+74
-7
lines changed

7 files changed

+74
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ changes.
2323
### Added
2424

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

2829
### Fixed
2930

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1+
WITH LatestExistingVotingAnchor AS (
2+
SELECT
3+
subquery.drep_registration_id,
4+
subquery.drep_hash_id,
5+
subquery.voting_anchor_id,
6+
subquery.url,
7+
subquery.metadata_hash,
8+
subquery.ocvd_id
9+
FROM (
10+
SELECT
11+
dr.id AS drep_registration_id,
12+
dr.drep_hash_id,
13+
va.id AS voting_anchor_id,
14+
va.url,
15+
encode(va.data_hash, 'hex') AS metadata_hash,
16+
ocvd.id AS ocvd_id,
17+
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
18+
FROM
19+
drep_registration dr
20+
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
21+
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
22+
WHERE
23+
ocvd.voting_anchor_id IS NOT NULL
24+
) subquery
25+
WHERE
26+
subquery.rn = 1
27+
)
128
SELECT DISTINCT ON (raw)
229
view,
330
encode(raw, 'hex') AS hash_raw,
4-
COALESCE(dd.amount, 0) AS voting_power
31+
COALESCE(dd.amount, 0) AS voting_power,
32+
ocvdd.given_name
533
FROM drep_hash dh
6-
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
34+
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
35+
LEFT JOIN LatestExistingVotingAnchor leva ON leva.drep_hash_id = dh.id
36+
LEFT JOIN off_chain_vote_data ocvd ON ocvd.id = leva.ocvd_id
37+
LEFT JOIN off_chain_vote_drep_data ocvdd ON ocvdd.off_chain_vote_data_id = ocvd.id
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
WITH LatestExistingVotingAnchor AS (
2+
SELECT
3+
subquery.drep_registration_id,
4+
subquery.drep_hash_id,
5+
subquery.voting_anchor_id,
6+
subquery.url,
7+
subquery.metadata_hash,
8+
subquery.ocvd_id
9+
FROM (
10+
SELECT
11+
dr.id AS drep_registration_id,
12+
dr.drep_hash_id,
13+
va.id AS voting_anchor_id,
14+
va.url,
15+
encode(va.data_hash, 'hex') AS metadata_hash,
16+
ocvd.id AS ocvd_id,
17+
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
18+
FROM
19+
drep_registration dr
20+
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
21+
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
22+
WHERE
23+
ocvd.voting_anchor_id IS NOT NULL
24+
) subquery
25+
WHERE
26+
subquery.rn = 1
27+
)
128
SELECT DISTINCT ON (raw)
229
view,
330
encode(raw, 'hex') AS hash_raw,
4-
COALESCE(dd.amount, 0) AS voting_power
31+
COALESCE(dd.amount, 0) AS voting_power,
32+
ocvdd.given_name
533
FROM drep_hash dh
634
LEFT JOIN drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = (SELECT MAX(no) from epoch)
35+
LEFT JOIN LatestExistingVotingAnchor leva ON leva.drep_hash_id = dh.id
36+
LEFT JOIN off_chain_vote_data ocvd ON ocvd.id = leva.ocvd_id
37+
LEFT JOIN off_chain_vote_drep_data ocvdd ON ocvdd.off_chain_vote_data_id = ocvd.id
738
WHERE view = ? OR encode(raw, 'hex') = ?

govtool/backend/src/VVA/API.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ drepVotingPowerList identifiers = do
346346
{ drepVotingPowerListResponseView = drepView
347347
, drepVotingPowerListResponseHashRaw = HexText drepHashRaw
348348
, drepVotingPowerListResponseVotingPower = drepVotingPower
349+
, drepVotingPowerListResponseGivenName = drepGivenName
349350
}
350351

351352
getCurrentDelegation :: App m => HexText -> m (Maybe DelegationResponse)

govtool/backend/src/VVA/API/Types.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ data DRepVotingPowerListResponse
627627
{ drepVotingPowerListResponseView :: Text
628628
, drepVotingPowerListResponseHashRaw :: HexText
629629
, drepVotingPowerListResponseVotingPower :: Integer
630+
, drepVotingPowerListResponseGivenName :: Maybe Text
630631
}
631632
deriving (Generic, Show)
632633

@@ -636,7 +637,8 @@ exampleDRepVotingPowerListResponse :: Text
636637
exampleDRepVotingPowerListResponse =
637638
"{\"view\": \"drep1qq5n7k0r0ff6lf4qvndw9t7vmdqa9y3q9qtjq879rrk9vcjcdy8a4xf92mqsajf9u3nrsh3r6zrp29kuydmfq45fz88qpzmjkc\","
638639
<> "\"hashRaw\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
639-
<> "\"votingPower\": 1000000}"
640+
<> "\"votingPower\": 1000000,"
641+
<> "\"givenName\": \"John Doe\"}"
640642

641643
instance ToSchema DRepVotingPowerListResponse where
642644
declareNamedSchema proxy = do

govtool/backend/src/VVA/DRep.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ getDRepsVotingPowerList identifiers = withPool $ \conn -> do
222222
return $ concat resultsPerIdentifier
223223

224224
return
225-
[ DRepVotingPowerList view hashRaw votingPower
226-
| (view, hashRaw, votingPower') <- results
225+
[ DRepVotingPowerList view hashRaw votingPower givenName
226+
| (view, hashRaw, votingPower', givenName) <- results
227227
, let votingPower = floor @Scientific votingPower'
228228
]

govtool/backend/src/VVA/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ data DRepVotingPowerList
101101
{ drepView :: Text
102102
, drepHashRaw :: Text
103103
, drepVotingPower :: Integer
104+
, drepGivenName :: Maybe Text
104105
}
105106
deriving (Show, Eq)
106107

0 commit comments

Comments
 (0)