Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#333] fix drep type detection #334

Merged
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
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