Skip to content

Commit 2897939

Browse files
Fix vote count query: Only count actions expiring after DRep's first registration
1 parent 8d1e452 commit 2897939

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/repository/drep.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ export const fetchDrepLiveStats = async (drepId: string, isScript?: boolean) =>
573573

574574
const drepVotingHistory = (await prisma.$queryRaw`
575575
WITH firstRegistration AS (
576-
SELECT b.time AS firstRegistrationTime
576+
SELECT b.epoch_no AS firstRegistrationEpoch
577577
FROM drep_registration dr
578578
JOIN drep_hash dh ON dh.id = dr.drep_hash_id
579579
JOIN tx ON tx.id = dr.tx_id
@@ -586,10 +586,8 @@ export const fetchDrepLiveStats = async (drepId: string, isScript?: boolean) =>
586586
govActionsAfter AS (
587587
SELECT COALESCE(COUNT(DISTINCT gp.id), 0) AS totalGovActionsAfter
588588
FROM gov_action_proposal AS gp
589-
JOIN tx ON tx.id = gp.tx_id
590-
JOIN block b ON b.id = tx.block_id
591589
LEFT JOIN firstRegistration ON TRUE
592-
WHERE b.time > firstRegistration.firstRegistrationTime
590+
WHERE gp.expiration > firstRegistration.firstRegistrationEpoch
593591
),
594592
votedGovActions AS (
595593
SELECT COUNT(DISTINCT gp.id) AS voted
@@ -959,4 +957,4 @@ export const fetchDrepDelegationHistory = async (dRepId: string, isScript?: bool
959957
})
960958
flattenedDelegations.sort((a: Delegation, b: Delegation) => new Date(b.time).getTime() - new Date(a.time).getTime())
961959
return flattenedDelegations
962-
}
960+
}

0 commit comments

Comments
 (0)