Skip to content

Commit 295996e

Browse files
authored
Merge pull request #7 from cardanoapi/fix/cc-vote-count
Fix/cc vote count
2 parents 8e4b5d9 + 60f1fed commit 295996e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
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+
}

src/repository/proposal.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Prisma } from '@prisma/client'
22
import { prisma } from '../config/db'
3-
import { formatResult } from '../helpers/formatter'
43
import { ProposalTypes, SortTypes } from '../types/proposal'
54

65
export const fetchProposals = async (
@@ -503,7 +502,24 @@ export const fetchProposalVoteCount = async (proposalId: string, proposalIndex:
503502
`
504503
const spoSelectionQuery = Prisma.sql`SELECT 'spo' AS voterRole, (SELECT jsonb_agg(to_jsonb(poolVoteRecord)) FROM poolVoteRecord) AS voteRecord`
505504
const ccVoteQuery = Prisma.sql`
506-
, committeeVoteRecord AS (
505+
, RatifiedCommitteeGovAction AS (
506+
SELECT gap.id
507+
FROM gov_action_proposal gap
508+
WHERE gap.type = 'NewCommittee'
509+
AND ratified_epoch IS NOT NULL
510+
ORDER BY gap.id DESC
511+
LIMIT 1
512+
),
513+
Committee AS (
514+
SELECT Count(DISTINCT(ch.raw)) as committeeMembersCount
515+
FROM committee c
516+
JOIN committee_member cm ON cm.committee_id = c.id
517+
JOIN committee_hash ch ON cm.committee_hash_id = ch.id
518+
LEFT JOIN RatifiedCommitteeGovAction rc
519+
ON rc.id = c.gov_action_proposal_id
520+
WHERE c.gov_action_proposal_id IS NULL
521+
),
522+
committeeVoteRecord AS (
507523
WITH CommitteeVotes AS (
508524
-- Count committee votes for each vote type
509525
SELECT
@@ -531,8 +547,8 @@ export const fetchProposalVoteCount = async (proposalId: string, proposalIndex:
531547
WHERE cm.expiration_epoch > (SELECT epoch FROM latestOrGovActionExpiration)
532548
ORDER BY ch.raw, cm.expiration_epoch DESC
533549
)
534-
SELECT 'total_distribution' as vote_type, COUNT(DISTINCT hash) AS count
535-
FROM CommitteeData
550+
SELECT 'total_distribution' as vote_type, committeeMembersCount AS count
551+
FROM Committee
536552
UNION ALL
537553
SELECT 'yes_votes' as vote_type, COALESCE(cc_Yes_Votes, 0) AS count FROM CommitteeVotes
538554
UNION ALL
@@ -1308,6 +1324,7 @@ export const fetchProposalById = async (proposalId: string, proposaIndex: number
13081324
any,
13091325
any
13101326
>[]
1327+
if (result.length == 0) return result
13111328
const proposalVoteCount = includeVoteCount
13121329
? { vote: await fetchProposalVoteCount(proposalId, proposaIndex) }
13131330
: undefined

0 commit comments

Comments
 (0)