Skip to content

Commit

Permalink
[#957] drep/list drep type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jankun4 committed May 13, 2024
1 parent 4c53331 commit 90f1e02
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ changes.

### Fixed

- drep/list sql fix (now the drep type is correct) [Issue 957](https://github.com/IntersectMBO/govtool/issues/957)
- drep/list sql fix (now the latest tx date is correct) [Issue 826](https://github.com/IntersectMBO/govtool/issues/826)
- drep/info no longer returns null values [Issue 720](https://github.com/IntersectMBO/govtool/issues/720)
- drep/getVotes no longer returns 500 [Issue 685](https://github.com/IntersectMBO/govtool/issues/685)
Expand Down
32 changes: 29 additions & 3 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ SELECT
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no, block_first_register.epoch_no))) <= DRepActivity.drep_activity AS active,
second_to_newest_drep_registration.voting_anchor_id IS NOT NULL AS has_voting_anchor,
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
newestRegister.time AS last_register_time
newestRegister.time AS last_register_time,
COALESCE(latestDeposit.deposit, 0),
non_deregister_voting_anchor.url IS NOT NULL AS has_non_deregister_voting_anchor
FROM
drep_hash dh
JOIN (
Expand All @@ -42,6 +43,15 @@ FROM
WHERE
dr.deposit IS NOT NULL) AS dr_deposit ON dr_deposit.drep_hash_id = dh.id
AND dr_deposit.rn = 1
JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.deposit,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr) AS latestDeposit ON latestDeposit.drep_hash_id = dh.id
AND latestDeposit.rn = 1
LEFT JOIN (
SELECT
dr.id,
Expand All @@ -53,6 +63,19 @@ FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id
AND dr_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.voting_anchor_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn,
tx.hash AS tx_hash
FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id
WHERE dr.deposit is not null
AND dr.deposit >= 0) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor.drep_hash_id = dh.id
AND dr_non_deregister_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
Expand All @@ -65,6 +88,7 @@ FROM
LEFT JOIN DRepDistr ON DRepDistr.hash_id = dh.id
AND DRepDistr.rn = 1
LEFT JOIN voting_anchor va ON va.id = dr_voting_anchor.voting_anchor_id
LEFT JOIN voting_anchor non_deregister_voting_anchor on non_deregister_voting_anchor.id = dr_non_deregister_voting_anchor.voting_anchor_id
CROSS JOIN DRepActivity
LEFT JOIN voting_procedure AS voting_procedure ON voting_procedure.drep_voter = dh.id
LEFT JOIN tx AS tx ON tx.id = voting_procedure.tx_id
Expand Down Expand Up @@ -102,4 +126,6 @@ GROUP BY
DRepActivity.epoch_no,
DRepActivity.drep_activity,
dr_voting_anchor.tx_hash,
newestRegister.time
newestRegister.time,
latestDeposit.deposit,
non_deregister_voting_anchor.url
9 changes: 6 additions & 3 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ listDReps = withPool $ \conn -> do
timeZone <- liftIO getCurrentTimeZone
return
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date)
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep, txHash, date) <- results
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, txHash, date, latestDeposit, latestNonDeregisterVotingAnchorWasNotNull) <- results
, let status = case (isActive, deposit) of
(_, d) | d < 0 -> Retired
(isActive, d) | d >= 0 && isActive -> Active
| d >= 0 && not isActive -> Inactive
, let drepType | isNothing url && wasDRep = DRep
| isNothing url && not wasDRep = SoleVoter
, let latestDeposit' = floor @Scientific latestDeposit :: Integer
, let drepType | latestDeposit' >= 0 && isNothing url = SoleVoter
| latestDeposit' >= 0 && not (isNothing url) = DRep
| latestDeposit' < 0 && not latestNonDeregisterVotingAnchorWasNotNull = SoleVoter
| latestDeposit' < 0 && latestNonDeregisterVotingAnchorWasNotNull = DRep
| Data.Maybe.isJust url = DRep
]

Expand Down

0 comments on commit 90f1e02

Please sign in to comment.