diff --git a/CHANGELOG.md b/CHANGELOG.md index efa898655..6a81c409b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/govtool/backend/sql/get-drep-info.sql b/govtool/backend/sql/get-drep-info.sql index e1bfcbbc6..de5048afb 100644 --- a/govtool/backend/sql/get-drep-info.sql +++ b/govtool/backend/sql/get-drep-info.sql @@ -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 \ No newline at end of file + CurrentDeposit.value +FROM + IsRegisteredAsDRep + CROSS JOIN IsRegisteredAsSoleVoter + CROSS JOIN WasRegisteredAsDRep + CROSS JOIN WasRegisteredAsSoleVoter + CROSS JOIN CurrentDeposit