@@ -17,6 +17,24 @@ DRepActivity AS (
1717 ORDER BY
1818 epoch_no DESC
1919 LIMIT 1
20+ ),
21+ LatestVotingProcedure AS (
22+ SELECT
23+ vp.* ,
24+ ROW_NUMBER() OVER (PARTITION BY drep_voter ORDER BY tx_id DESC ) AS rn
25+ FROM
26+ voting_procedure vp
27+ ),
28+ LatestVoteEpoch AS (
29+ SELECT
30+ block .epoch_no ,
31+ lvp .drep_voter as drep_id
32+ FROM
33+ LatestVotingProcedure lvp
34+ JOIN tx ON tx .id = lvp .tx_id
35+ JOIN block ON block .id = tx .block_id
36+ WHERE
37+ lvp .rn = 1
2038)
2139SELECT DISTINCT ON (dh .raw )
2240 encode(dh .raw , ' hex' ),
@@ -26,7 +44,7 @@ SELECT DISTINCT ON (dh.raw)
2644 encode(va .data_hash , ' hex' ),
2745 dr_deposit .deposit ,
2846 DRepDistr .amount ,
29- (DRepActivity .epoch_no - newestRegister .epoch_no ) <= DRepActivity .drep_activity AS active,
47+ (DRepActivity .epoch_no - GREATEST( MAX (COALESCE( block .epoch_no , block_first_register . epoch_no )), lve . epoch_no ) ) <= DRepActivity .drep_activity AS active,
3048 encode(dr_voting_anchor .tx_hash , ' hex' ) AS tx_hash,
3149 newestRegister .time AS last_register_time,
3250 COALESCE(latestDeposit .deposit , 0 ),
143161 ) AS dr_first_register ON dr_first_register .drep_hash_id = dh .id AND dr_first_register .rn = 1
144162 LEFT JOIN tx AS tx_first_register ON tx_first_register .id = dr_first_register .tx_id
145163 LEFT JOIN block AS block_first_register ON block_first_register .id = tx_first_register .block_id
164+ LEFT JOIN LatestVoteEpoch lve ON lve .drep_id = dh .id
146165WHERE
147166 (
148167 COALESCE(?, ' ' ) = ' ' OR
@@ -163,6 +182,7 @@ GROUP BY
163182 DRepDistr .amount ,
164183 DRepActivity .epoch_no ,
165184 DRepActivity .drep_activity ,
185+ lve .epoch_no ,
166186 dr_voting_anchor .tx_hash ,
167187 newestRegister .time ,
168188 newestRegister .epoch_no ,
0 commit comments