-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jankun4 <michaljankun@gmail.com>
- Loading branch information
Showing
2 changed files
with
79 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |