Skip to content

Commit

Permalink
Merge pull request #1182 from cardano-foundation/feat/MET-2055-update…
Browse files Browse the repository at this point in the history
…-votes-section-dev-test

chore: merge dev-test
  • Loading branch information
Sotatek-DucPhung committed May 3, 2024
2 parents 19ae538 + bbe6af9 commit ab6c3a2
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.cardanofoundation.explorer.api.common.enumeration;

public enum ProtocolParamGroup {
NETWORK,
ECONOMIC,
TECHNICAL,
GOVERNANCE,
SECURITY
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.cardanofoundation.explorer.api.model.response.governanceAction.GovernanceActionResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.VotingChartResponse;
import org.cardanofoundation.explorer.api.service.GovernanceActionService;
import org.cardanofoundation.explorer.common.entity.enumeration.VoterType;
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;
Expand Down Expand Up @@ -82,8 +83,9 @@ public ResponseEntity<GovernanceActionDetailsResponse> getGovActionByTxHashAndVo
tags = {"gov-actions"})
public ResponseEntity<VotingChartResponse> getVotingChartByGovAction(
@RequestParam @Parameter(description = "The tx hash of governance action") String txHash,
@RequestParam @Parameter(description = "The index of governance action") Integer index) {
@RequestParam @Parameter(description = "The index of governance action") Integer index,
@RequestParam @Parameter(description = "The type of voter") VoterType voterType) {
return ResponseEntity.ok(
governanceActionService.getVotingChartByGovActionTxHashAndIndex(txHash, index));
governanceActionService.getVotingChartByGovActionTxHashAndIndex(txHash, index, voterType));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.cardanofoundation.explorer.api.model.response.governanceAction;

import java.util.List;
import java.math.BigInteger;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import org.cardanofoundation.explorer.common.entity.enumeration.VoterType;

@Getter
@Setter
@SuperBuilder
Expand All @@ -16,9 +18,17 @@
public class VotingChartResponse {
String txHash;
Integer index;
private Long numberOfYesVote;
private Long numberOfNoVotes;
private Long numberOfAbstainVotes;
VoterType voterType;

BigInteger activeVoteStake;
BigInteger abstainVoteStake;
BigInteger totalYesVoteStake;
BigInteger totalNoVoteStake;

Double threshold;

List<VotingChart> votingChartsList;
Long ccMembers;
Long abstainCcMembers;
Long yesCcMembers;
Long noCcMembers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cardanofoundation.explorer.api.projection;

import org.cardanofoundation.explorer.common.entity.enumeration.Vote;

public interface VotingCCProjection {

String getTxHash();

Integer getIndex();

Vote getVote();

String getVoterHash();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cardanofoundation.explorer.api.repository.ledgersync;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import org.cardanofoundation.explorer.api.projection.VotingCCProjection;
import org.cardanofoundation.explorer.common.entity.compositeKey.CommitteeRegistrationId;
import org.cardanofoundation.explorer.common.entity.ledgersync.CommitteeRegistration;

public interface CommitteeRegistrationRepository
extends JpaRepository<CommitteeRegistration, CommitteeRegistrationId> {
@Query(
value =
"SELECT COUNT(cr) FROM CommitteeRegistration cr "
+ "JOIN EpochParam ep ON cr.epoch = ep.epochNo "
+ "WHERE (ep.epochNo + ep.committeeMaxTermLength) >= :expiredEpoch")
Integer countByExpiredEpochNo(@Param("expiredEpoch") Integer expiredEpoch);

@Query(
value =
"""
select lvp.voterHash as voterHash, lvp.txHash as txHash, lvp.index as index, lvp.vote as vote from CommitteeRegistration cr
left join LatestVotingProcedure lvp on lvp.govActionTxHash = :txHash
and lvp.govActionIndex = :index and lvp.voterType = 'CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH' and lvp.voterHash = cr.hotKey
where not exists ( select 1 from CommitteeRegistration cr2 where cr2.coldKey = cr.coldKey and cr2.blockTime > cr.blockTime)
and not exists (select 1 from CommitteeDeRegistration cd where cd.coldKey = cr.coldKey and cd.blockTime > cr.blockTime)
""")
List<VotingCCProjection> findByTxHashAndIndex(
@Param("txHash") String txHash, @Param("index") Integer index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.cardanofoundation.explorer.api.projection.CountVoteOnGovActionProjection;
import org.cardanofoundation.explorer.common.entity.compositeKey.LatestVotingProcedureId;
import org.cardanofoundation.explorer.common.entity.enumeration.VoterType;
import org.cardanofoundation.explorer.common.entity.ledgersync.LatestVotingProcedure;

@Repository
Expand All @@ -17,12 +18,14 @@ public interface LatestVotingProcedureRepository

@Query(
value =
"select lvp.voterHash,lvp.vote as vote, lvp.voterType as voterType"
"select lvp.voterHash as voterHash, lvp.vote as vote, lvp.voterType as voterType"
+ " from LatestVotingProcedure lvp"
+ " where lvp.govActionTxHash = :govActionTxHash and lvp.govActionIndex = :govActionIndex")
+ " where lvp.govActionTxHash = :govActionTxHash and lvp.govActionIndex = :govActionIndex"
+ " and lvp.voterType = :voterType")
List<CountVoteOnGovActionProjection> getLatestVotingProcedureByGovActionTxHashAndGovActionIndex(
@Param("govActionTxHash") String govActionTxHash,
@Param("govActionIndex") Integer govActionIndex);
@Param("govActionIndex") Integer govActionIndex,
@Param("voterType") VoterType voterType);

@Query(
value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.cardanofoundation.explorer.api.model.response.governanceAction.GovernanceActionDetailsResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.GovernanceActionResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.VotingChartResponse;
import org.cardanofoundation.explorer.common.entity.enumeration.VoterType;

public interface GovernanceActionService {
BaseFilterResponse<GovernanceActionResponse> getGovernanceActions(
Expand All @@ -16,5 +17,6 @@ BaseFilterResponse<GovernanceActionResponse> getGovernanceActions(
GovernanceActionDetailsResponse getGovernanceActionDetails(
String dRepHashOrPoolHashOrPoolView, GovernanceActionRequest governanceActionRequest);

VotingChartResponse getVotingChartByGovActionTxHashAndIndex(String txHash, Integer index);
VotingChartResponse getVotingChartByGovActionTxHashAndIndex(
String txHash, Integer index, VoterType voterType);
}

0 comments on commit ab6c3a2

Please sign in to comment.