-
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.
fix(#2460): fix calculating live voting power
- Loading branch information
1 parent
9e2f035
commit 904f329
Showing
2 changed files
with
22 additions
and
7 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,6 +1,21 @@ | ||
select coalesce(sum(uv.value), 0) as amount | ||
from utxo_view uv | ||
join delegation_vote dv on uv.stake_address_id = dv.addr_id | ||
join drep_hash dh on dv.drep_hash_id = dh.id | ||
where dh.raw = decode(?,'hex') | ||
and dv.cert_index != 0 | ||
WITH LatestDelegationVote AS ( | ||
SELECT | ||
addr_id, | ||
MAX(id) AS latest_vote_id | ||
FROM | ||
delegation_vote | ||
GROUP BY | ||
addr_id | ||
) | ||
SELECT | ||
SUM(uv.value) AS total_value | ||
FROM | ||
utxo_view uv | ||
JOIN | ||
stake_address sa ON sa.id = uv.stake_address_id | ||
JOIN | ||
LatestDelegationVote ldv ON uv.stake_address_id = ldv.addr_id | ||
JOIN | ||
delegation_vote dv ON dv.id = ldv.latest_vote_id | ||
WHERE | ||
dv.drep_hash_id = (SELECT id FROM drep_hash WHERE raw = decode(?,'hex')) |