Skip to content

Commit

Permalink
[#333] fix drep type detection
Browse files Browse the repository at this point in the history
Signed-off-by: jankun4 <michaljankun@gmail.com>
  • Loading branch information
jankun4 committed Feb 28, 2024
1 parent 804f906 commit 198b2de
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ changes.
- Added `isRegisteredAsSoleVoter` and `wasRegisteredAsSoleVoter` fields to the drep/info response [Issue 212](https://github.com/IntersectMBO/govtool/issues/212)

### Fixed
- Fix drep type detection when changing metadata [Issue 333](https://github.com/IntersectMBO/govtool/issues/333)
- Fix make button disble when wallet tries connect [Issue 265](https://github.com/IntersectMBO/govtool/issues/265)
- Fix drep voting power calculation [Issue 231](https://github.com/IntersectMBO/govtool/issues/231)
- Fix proposal/list and network/metrics bug that appeared when noone has delegated their funds either to drep_always_abstain or drep_always_no_confidence [Issue 231](https://github.com/IntersectMBO/govtool/issues/231)
Expand Down
130 changes: 78 additions & 52 deletions govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
@@ -1,60 +1,86 @@
WITH DRepId AS (
SELECT decode(?, 'hex') as raw
), IsRegisteredAsDRep AS (
SELECT (drep_registration.voting_anchor_id is not null and deposit>0) as value,
deposit as deposit
FROM drep_registration
JOIN drep_hash
ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE drep_hash.raw = DRepId.raw
and deposit is not null
ORDER BY drep_registration.tx_id DESC
SELECT
decode(?, 'hex') AS raw
),
LatestRegistrationEntry AS (
SELECT
drep_registration.voting_anchor_id AS voting_anchor_id,
deposit AS deposit
FROM
drep_registration
CROSS JOIN DrepId
JOIN drep_hash ON drep_hash.id = drep_registration.drep_hash_id
WHERE
drep_hash.raw = DRepId.raw
ORDER BY
drep_registration.tx_id DESC
LIMIT 1
), WasRegisteredAsDRep AS (
select (EXISTS (
SELECT *
FROM drep_registration
JOIN drep_hash
ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE drep_hash.raw = DRepId.raw
and drep_registration.deposit > 0
and drep_registration.voting_anchor_id is not null
)) as value
), IsRegisteredAsSoleVoter AS (
SELECT (drep_registration.voting_anchor_id is null and deposit>0) as value,
deposit as deposit
FROM drep_registration
JOIN drep_hash
ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE drep_hash.raw = DRepId.raw
and deposit is not null
ORDER BY drep_registration.tx_id DESC
),
IsRegisteredAsDRep AS (
SELECT
(LatestRegistrationEntry.deposit is null or LatestRegistrationEntry.deposit > 0)
AND LatestRegistrationEntry.voting_anchor_id IS NOT NULL AS value
FROM
LatestRegistrationEntry
),
IsRegisteredAsSoleVoter AS (
SELECT
(LatestRegistrationEntry.deposit is null or LatestRegistrationEntry.deposit > 0)
AND LatestRegistrationEntry.voting_anchor_id IS NULL AS value
FROM
LatestRegistrationEntry
),
CurrentDeposit AS (
SELECT
GREATEST(drep_registration.deposit, 0) AS value
FROM
drep_registration
join drep_hash
on drep_hash.id = drep_registration.drep_hash_id
cross join DRepId

WHERE
drep_registration.deposit IS NOT NULL
and drep_hash.raw = DRepId.raw
ORDER BY
drep_registration.tx_id DESC
LIMIT 1
), WasRegisteredAsSoleVoter AS (
select (EXISTS (
SELECT *
FROM drep_registration
JOIN drep_hash
ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE drep_hash.raw = DRepId.raw
and drep_registration.deposit > 0
and drep_registration.voting_anchor_id is null
)) as value
),
WasRegisteredAsDRep AS (
SELECT
(EXISTS (
SELECT
*
FROM
drep_registration
JOIN drep_hash ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE
drep_hash.raw = DRepId.raw
AND drep_registration.voting_anchor_id IS NOT NULL)) AS value
),
WasRegisteredAsSoleVoter AS (
SELECT
(EXISTS (
SELECT
*
FROM
drep_registration
JOIN drep_hash ON drep_hash.id = drep_registration.drep_hash_id
CROSS JOIN DRepId
WHERE
drep_hash.raw = DRepId.raw
AND drep_registration.voting_anchor_id IS NULL)) AS value
)
SELECT
IsRegisteredAsDrep.value,
IsRegisteredAsDRep.value,
WasRegisteredAsDRep.value,
IsRegisteredAsSoleVoter.value,
WasRegisteredAsSoleVoter.value,
coalesce(IsRegisteredAsDRep.deposit, IsRegisteredAsSoleVoter.deposit)
FROM WasRegisteredAsDRep
LEFT JOIN IsRegisteredAsDRep
ON 1=1
LEFT JOIN WasRegisteredAsSoleVoter
ON 1=1
LEFT JOIN IsRegisteredAsSoleVoter
ON 1=1
CurrentDeposit.value
FROM
IsRegisteredAsDRep
CROSS JOIN IsRegisteredAsSoleVoter
CROSS JOIN WasRegisteredAsDRep
CROSS JOIN WasRegisteredAsSoleVoter
CROSS JOIN CurrentDeposit

0 comments on commit 198b2de

Please sign in to comment.