Skip to content

Commit

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

fix: filter by CC in voting chart not working
  • Loading branch information
Sotatek-DucPhung committed May 9, 2024
2 parents 1fb623f + 8b8deb7 commit 8d0082d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public class GovernanceActionDetails {
Date expiryDate;

String poolName;

Boolean allowedVoteBySPO;

Boolean allowedVoteByCC;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface CommitteeRegistrationRepository
"""
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 = :voterType and lvp.voterHash = cr.hotKey
and lvp.govActionIndex = :index and lvp.voterType in :voterType 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)
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ List<VotingProcedureProjection> findVotingProcedureByVoterHashAndGovActionType(
value =
"select vp.govActionTxHash as govActionTxHash, vp.govActionIndex as govActionIndex, vp.vote as vote, vp.txHash as votingProcedureTxHash, vp.index as votingProcedureTxIndex,"
+ " vp.blockTime as blockTime"
+ " from VotingProcedure vp where vp.govActionTxHash = :txHash and vp.govActionIndex = :index and vp.voterHash = :voterHash and vp.voterType = :voterType"
+ " from VotingProcedure vp where vp.govActionTxHash = :txHash and vp.govActionIndex = :index and vp.voterHash = :voterHash and vp.voterType in :voterType"
+ " order by vp.blockTime desc")
List<VotingProcedureProjection> getVotingProcedureByTxHashAndIndexAndVoterHash(
@Param("txHash") String txHash,
@Param("index") Integer index,
@Param("voterHash") String voterHash,
@Param("voterType") VoterType voterType);
@Param("voterType") List<VoterType> voterType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,24 @@ public GovernanceActionDetailsResponse getGovernanceActionDetails(
Optional<GovActionDetailsProjection> govActionDetailsProjections =
governanceActionRepository.getGovActionDetailsByTxHashAndIndex(
governanceActionRequest.getTxHash(), governanceActionRequest.getIndex());

if (govActionDetailsProjections.isEmpty()) {
throw new BusinessException(BusinessCode.GOVERNANCE_ACTION_NOT_FOUND);
}
GovActionType govActionType = govActionDetailsProjections.get().getType();

// STAKING POOL not allowed to vote on treasury withdrawals, parameter change and update
// committee
List<GovActionType> govActionTypeListAllowedVoteBySPO =
List.of(
GovActionType.TREASURY_WITHDRAWALS_ACTION,
GovActionType.PARAMETER_CHANGE_ACTION,
GovActionType.NEW_CONSTITUTION);

List<GovActionType> govActionTypeListAllowedVoteByCc =
List.of(GovActionType.NO_CONFIDENCE, GovActionType.UPDATE_COMMITTEE);
Boolean allowedVoteBySPO = !govActionTypeListAllowedVoteBySPO.contains(govActionType);
Boolean allowedVoteByCC = !govActionTypeListAllowedVoteByCc.contains(govActionType);
if (dRepHashOrPoolHashOrPoolView.toLowerCase().startsWith("pool")) {
dRepHashOrPoolHashOrPoolView =
poolHashRepository
Expand All @@ -225,35 +240,43 @@ public GovernanceActionDetailsResponse getGovernanceActionDetails(
.orElseThrow(() -> new BusinessException(BusinessCode.DREP_NOT_FOUND));
dRepHashOrPoolHashOrPoolView = dRepInfo.getDrepHash();
}
GovActionType govActionType = govActionDetailsProjections.get().getType();
// STAKING POOL not allowed to vote on treasury withdrawals, parameter change and update
// committee
List<GovActionType> govActionTypes =
List.of(
GovActionType.TREASURY_WITHDRAWALS_ACTION,
GovActionType.PARAMETER_CHANGE_ACTION,
GovActionType.NEW_CONSTITUTION);
if (governanceActionRequest.getVoterType().equals(VoterType.STAKING_POOL_KEY_HASH)
&& govActionTypes.contains(govActionType)) {
return new GovernanceActionDetailsResponse();
&& govActionTypeListAllowedVoteBySPO.contains(govActionType)) {
return GovernanceActionDetailsResponse.builder()
.allowedVoteBySPO(allowedVoteBySPO)
.allowedVoteByCC(allowedVoteByCC)
.build();
}
GovernanceActionDetailsResponse response =
governanceActionMapper.fromGovActionDetailsProjection(govActionDetailsProjections.get());
response.setAllowedVoteByCC(allowedVoteByCC);
response.setAllowedVoteBySPO(allowedVoteBySPO);
// get pool name for SPO
if (governanceActionRequest.getVoterType().equals(VoterType.STAKING_POOL_KEY_HASH)) {
Optional<String> poolName =
poolHashRepository.getPoolNameByPoolHashOrPoolView(dRepHashOrPoolHashOrPoolView);
response.setPoolName(poolName.orElse(null));
}

VoterType voterType = VoterType.valueOf(governanceActionRequest.getVoterType().name());
List<VoterType> voterTypes = new ArrayList<>();

if (VoterType.DREP_KEY_HASH.equals(governanceActionRequest.getVoterType())) {
voterTypes.add(VoterType.DREP_KEY_HASH);
voterTypes.add(VoterType.DREP_SCRIPT_HASH);
} else if (VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH.equals(
governanceActionRequest.getVoterType())) {
voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH);
voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH);
} else if (VoterType.STAKING_POOL_KEY_HASH.equals(governanceActionRequest.getVoterType())) {
voterTypes.add(VoterType.STAKING_POOL_KEY_HASH);
}

List<VotingProcedureProjection> votingProcedureProjections =
votingProcedureRepository.getVotingProcedureByTxHashAndIndexAndVoterHash(
governanceActionRequest.getTxHash(),
governanceActionRequest.getIndex(),
dRepHashOrPoolHashOrPoolView,
voterType);
voterTypes);
setExpiryDateOfGovAction(response);
// no vote procedure found = none vote
if (votingProcedureProjections.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void getGovActionDetails() {
when(votingProcedureProjection1.getBlockTime()).thenReturn(1707695293L);

when(votingProcedureRepository.getVotingProcedureByTxHashAndIndexAndVoterHash(
txHash, index, voterHash, VoterType.DREP_KEY_HASH))
txHash, index, voterHash, List.of(VoterType.DREP_KEY_HASH, VoterType.DREP_SCRIPT_HASH)))
.thenReturn(List.of(votingProcedureProjection1, votingProcedureProjection));

EpochParam epochParam =
Expand Down Expand Up @@ -233,7 +233,7 @@ void getGovActionDetails_withPoolView() {
when(votingProcedureProjection1.getBlockTime()).thenReturn(1707695293L);

when(votingProcedureRepository.getVotingProcedureByTxHashAndIndexAndVoterHash(
txHash, index, voterHash, VoterType.DREP_KEY_HASH))
txHash, index, voterHash, List.of(VoterType.DREP_KEY_HASH, VoterType.DREP_SCRIPT_HASH)))
.thenReturn(List.of(votingProcedureProjection1, votingProcedureProjection));

EpochParam epochParam =
Expand Down

0 comments on commit 8d0082d

Please sign in to comment.