1 | package org.cardanofoundation.explorer.api.service.impl; | |
2 | ||
3 | import java.math.BigInteger; | |
4 | import java.sql.Timestamp; | |
5 | import java.time.Instant; | |
6 | import java.time.LocalDateTime; | |
7 | import java.time.ZoneOffset; | |
8 | import java.time.temporal.ChronoUnit; | |
9 | import java.util.*; | |
10 | import java.util.concurrent.CompletableFuture; | |
11 | import java.util.stream.Collectors; | |
12 | ||
13 | import lombok.RequiredArgsConstructor; | |
14 | import lombok.extern.log4j.Log4j2; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Value; | |
17 | import org.springframework.data.domain.Page; | |
18 | import org.springframework.data.domain.Pageable; | |
19 | import org.springframework.data.redis.core.RedisTemplate; | |
20 | import org.springframework.stereotype.Service; | |
21 | import org.springframework.util.CollectionUtils; | |
22 | ||
23 | import com.bloxbean.cardano.client.crypto.Blake2bUtil; | |
24 | import com.fasterxml.jackson.core.JsonProcessingException; | |
25 | import com.fasterxml.jackson.databind.DeserializationFeature; | |
26 | import com.fasterxml.jackson.databind.JsonNode; | |
27 | import com.fasterxml.jackson.databind.ObjectMapper; | |
28 | import org.apache.commons.lang3.StringUtils; | |
29 | ||
30 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
31 | import org.cardanofoundation.explorer.api.common.enumeration.ProtocolParamGroup; | |
32 | import org.cardanofoundation.explorer.api.exception.BusinessCode; | |
33 | import org.cardanofoundation.explorer.api.mapper.GovernanceActionMapper; | |
34 | import org.cardanofoundation.explorer.api.mapper.LatestVotingProcedureMapper; | |
35 | import org.cardanofoundation.explorer.api.mapper.VotingProcedureMapper; | |
36 | import org.cardanofoundation.explorer.api.model.ProtocolParamUpdate; | |
37 | import org.cardanofoundation.explorer.api.model.dto.GovActionMetaData; | |
38 | import org.cardanofoundation.explorer.api.model.request.governanceAction.GovCommitteeHistoryFilter; | |
39 | import org.cardanofoundation.explorer.api.model.request.governanceAction.GovernanceActionFilter; | |
40 | import org.cardanofoundation.explorer.api.model.request.governanceAction.GovernanceActionRequest; | |
41 | import org.cardanofoundation.explorer.api.model.request.governanceAction.VoteFilter; | |
42 | import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse; | |
43 | import org.cardanofoundation.explorer.api.model.response.governanceAction.*; | |
44 | import org.cardanofoundation.explorer.api.projection.*; | |
45 | import org.cardanofoundation.explorer.api.repository.ledgersync.*; | |
46 | import org.cardanofoundation.explorer.api.repository.ledgersync.DrepInfoRepository; | |
47 | import org.cardanofoundation.explorer.api.repository.ledgersyncagg.StakeAddressBalanceRepository; | |
48 | import org.cardanofoundation.explorer.api.service.FetchRewardDataService; | |
49 | import org.cardanofoundation.explorer.api.service.GovernanceActionService; | |
50 | import org.cardanofoundation.explorer.api.service.ProtocolParamService; | |
51 | import org.cardanofoundation.explorer.api.util.BatchUtils; | |
52 | import org.cardanofoundation.explorer.api.util.ProtocolParamUtil; | |
53 | import org.cardanofoundation.explorer.common.entity.enumeration.CommitteeState; | |
54 | import org.cardanofoundation.explorer.common.entity.enumeration.DRepStatus; | |
55 | import org.cardanofoundation.explorer.common.entity.enumeration.GovActionStatus; | |
56 | import org.cardanofoundation.explorer.common.entity.enumeration.GovActionType; | |
57 | import org.cardanofoundation.explorer.common.entity.enumeration.Vote; | |
58 | import org.cardanofoundation.explorer.common.entity.enumeration.VoterType; | |
59 | import org.cardanofoundation.explorer.common.entity.ledgersync.DRepInfo; | |
60 | import org.cardanofoundation.explorer.common.entity.ledgersync.EpochParam; | |
61 | import org.cardanofoundation.explorer.common.exception.BusinessException; | |
62 | import org.cardanofoundation.explorer.common.utils.HexUtil; | |
63 | ||
64 | @Service | |
65 | @RequiredArgsConstructor | |
66 | @Log4j2 | |
67 | public class GovernanceActionServiceImpl implements GovernanceActionService { | |
68 | ||
69 | private final DRepRegistrationRepository dRepRegistrationRepository; | |
70 | private final GovernanceActionRepository governanceActionRepository; | |
71 | private final PoolHashRepository poolHashRepository; | |
72 | private final GovernanceActionMapper governanceActionMapper; | |
73 | private final VotingProcedureMapper votingProcedureMapper; | |
74 | private final VotingProcedureRepository votingProcedureRepository; | |
75 | private final DrepInfoRepository drepInfoRepository; | |
76 | private final EpochParamRepository epochParamRepository; | |
77 | private final LatestVotingProcedureRepository latestVotingProcedureRepository; | |
78 | private final DelegationRepository delegationRepository; | |
79 | private final ProtocolParamService protocolParamService; | |
80 | private final CommitteeMemberRepository committeeMemberRepository; | |
81 | private final StakeAddressBalanceRepository stakeAddressBalanceRepository; | |
82 | private final OffChainVoteGovActionDataRepository offChainVoteGovActionDataRepository; | |
83 | private final LatestVotingProcedureMapper latestVotingProcedureMapper; | |
84 | private final CommitteeRepository committeeRepository; | |
85 | private final FetchRewardDataService fetchRewardDataService; | |
86 | private final PoolInfoRepository poolInfoRepository; | |
87 | ||
88 | private final RedisTemplate<String, Integer> redisTemplate; | |
89 | ||
90 | @Value("${application.network}") | |
91 | private String network; | |
92 | ||
93 | @Value("${application.epoch.days}") | |
94 | public long epochDays; | |
95 | ||
96 | public static final String MIN_TIME = "1970-01-01 00:00:00"; | |
97 | ||
98 | private static final Integer DEFAULT_BATCH_SIZE = 2000; | |
99 | ||
100 | @Override | |
101 | public BaseFilterResponse<GovernanceActionResponse> getGovernanceActions( | |
102 | String voterHash, GovernanceActionFilter governanceActionFilter, Pageable pageable) { | |
103 | List<String> voterHashes = | |
104 | getActualVoterHashes(voterHash, governanceActionFilter.getVoterType()); | |
105 | Long slot = getSlotCheckpoint(voterHash, governanceActionFilter.getVoterType(), voterHashes); | |
106 | Boolean isVoteNone = Vote.NONE.equals(governanceActionFilter.getVoteType()); | |
107 | ||
108 | Vote vote = | |
109 |
1
1. getGovernanceActions : negated conditional → SURVIVED |
Vote.ANY.equals(governanceActionFilter.getVoteType()) |
110 | ? null | |
111 | : governanceActionFilter.getVoteType(); | |
112 | ||
113 | List<GovActionType> govActionTypeList = | |
114 | getGovActionTypeByVoterType( | |
115 | governanceActionFilter.getVoterType(), governanceActionFilter.getActionType()); | |
116 | ||
117 |
1
1. getGovernanceActions : Replaced long division with multiplication → SURVIVED |
long fromDate = Timestamp.valueOf(MIN_TIME).getTime() / 1000; |
118 | long toDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); | |
119 | ||
120 |
1
1. getGovernanceActions : negated conditional → KILLED |
if (Objects.nonNull(governanceActionFilter.getFromDate())) { |
121 | fromDate = governanceActionFilter.getFromDate().toEpochSecond(ZoneOffset.UTC); | |
122 | } | |
123 |
1
1. getGovernanceActions : negated conditional → KILLED |
if (Objects.nonNull(governanceActionFilter.getToDate())) { |
124 | long to = governanceActionFilter.getToDate().toEpochSecond(ZoneOffset.UTC); | |
125 | toDate = Math.min(to, toDate); | |
126 | } | |
127 | ||
128 | org.cardanofoundation.explorer.common.entity.enumeration.GovActionStatus govActionStatus = | |
129 |
1
1. getGovernanceActions : negated conditional → SURVIVED |
GovActionStatus.ANY.equals(governanceActionFilter.getActionStatus()) |
130 |
1
1. getGovernanceActions : negated conditional → NO_COVERAGE |
|| governanceActionFilter.getActionStatus() == null |
131 | ? null | |
132 | : org.cardanofoundation.explorer.common.entity.enumeration.GovActionStatus.valueOf( | |
133 | governanceActionFilter.getActionStatus().name()); | |
134 | ||
135 | String anchorText = | |
136 |
1
1. getGovernanceActions : negated conditional → KILLED |
governanceActionFilter.getAnchorText() == null |
137 | ? null | |
138 | : governanceActionFilter.getAnchorText().toLowerCase(); | |
139 | ||
140 | Page<GovernanceActionProjection> governanceActionProjectionPage; | |
141 | ||
142 | // get gov info include voter info | |
143 |
1
1. getGovernanceActions : negated conditional → KILLED |
if (!CollectionUtils.isEmpty(voterHashes)) { |
144 | governanceActionProjectionPage = | |
145 | governanceActionRepository.getAllByFilter( | |
146 | governanceActionFilter.getIsRepeatVote(), | |
147 | govActionStatus, | |
148 | vote, | |
149 | voterHashes, | |
150 | govActionTypeList, | |
151 | fromDate, | |
152 | toDate, | |
153 | slot, | |
154 | governanceActionFilter.getGovernanceActionTxHash(), | |
155 | anchorText, | |
156 | isVoteNone, | |
157 | pageable); | |
158 | } else { // get gov info only | |
159 | governanceActionProjectionPage = | |
160 | governanceActionRepository.getAllByFilter( | |
161 | govActionStatus, | |
162 | govActionTypeList, | |
163 | fromDate, | |
164 | toDate, | |
165 | governanceActionFilter.getGovernanceActionTxHash(), | |
166 | anchorText, | |
167 | pageable); | |
168 | } | |
169 | ||
170 | List<GovernanceActionResponse> governanceActionResponses = | |
171 | governanceActionProjectionPage.stream() | |
172 | .map(governanceActionMapper::fromGovernanceActionProjection) | |
173 | .collect(Collectors.toList()); | |
174 | ||
175 |
1
1. getGovernanceActions : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceActions → KILLED |
return new BaseFilterResponse<>(governanceActionProjectionPage, governanceActionResponses); |
176 | } | |
177 | ||
178 | private Long getSlotCheckpoint(String voterHash, VoterType voterType, List<String> voterHashes) { | |
179 | Long slot = null; | |
180 |
1
1. getSlotCheckpoint : negated conditional → KILLED |
if (voterType == null) { |
181 |
1
1. getSlotCheckpoint : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getSlotCheckpoint → NO_COVERAGE |
return slot; |
182 | } | |
183 | ||
184 |
2
1. getSlotCheckpoint : negated conditional → KILLED 2. getSlotCheckpoint : negated conditional → KILLED |
if (voterType.equals(VoterType.DREP_KEY_HASH) || voterType.equals(VoterType.DREP_SCRIPT_HASH)) { |
185 | slot = dRepRegistrationRepository.getSlotOfDRepRegistration(voterHashes.get(0)); | |
186 |
1
1. getSlotCheckpoint : negated conditional → KILLED |
} else if (voterType.equals(VoterType.STAKING_POOL_KEY_HASH)) { |
187 | slot = poolHashRepository.getSlotNoWhenFirstDelegationByPoolHash(voterHashes.get(0)); | |
188 |
1
1. getSlotCheckpoint : negated conditional → NO_COVERAGE |
} else if (voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH) |
189 |
1
1. getSlotCheckpoint : negated conditional → NO_COVERAGE |
|| voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH)) { |
190 |
1
1. getSlotCheckpoint : negated conditional → NO_COVERAGE |
if (StringUtils.isEmpty(voterHash)) { |
191 | slot = committeeMemberRepository.getMinSlotOfCommitteeMembers(); | |
192 | } else { | |
193 | slot = committeeMemberRepository.getSlotOfCommitteeMemberByHotKey(voterHash); | |
194 | } | |
195 | } | |
196 |
1
1. getSlotCheckpoint : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getSlotCheckpoint → SURVIVED |
return slot; |
197 | } | |
198 | ||
199 | private List<String> getActualVoterHashes(String voterHash, VoterType voterType) { | |
200 | List<String> voteHashes = new ArrayList<>(); | |
201 |
1
1. getActualVoterHashes : negated conditional → KILLED |
if (voterType == null) { |
202 |
1
1. getActualVoterHashes : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getActualVoterHashes → NO_COVERAGE |
return voteHashes; |
203 | } | |
204 |
1
1. getActualVoterHashes : negated conditional → SURVIVED |
if (StringUtils.isEmpty(voterHash) |
205 |
1
1. getActualVoterHashes : negated conditional → NO_COVERAGE |
&& (voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH) |
206 |
1
1. getActualVoterHashes : negated conditional → NO_COVERAGE |
|| voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH))) { |
207 |
1
1. getActualVoterHashes : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getActualVoterHashes → NO_COVERAGE |
return committeeMemberRepository.getHotKeyOfCommitteeMember(); |
208 | } | |
209 | ||
210 |
1
1. getActualVoterHashes : negated conditional → KILLED |
if (voterHash.toLowerCase().startsWith("pool")) { |
211 | voteHashes.add( | |
212 | poolHashRepository | |
213 | .getHashRawByView(voterHash) | |
214 |
1
1. lambda$getActualVoterHashes$0 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getActualVoterHashes$0 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.POOL_NOT_FOUND))); |
215 |
1
1. getActualVoterHashes : negated conditional → KILLED |
} else if (voterHash.toLowerCase().startsWith("drep")) { |
216 | DRepInfo dRepInfo = | |
217 | drepInfoRepository | |
218 | .findByDRepHashOrDRepId(voterHash) | |
219 |
1
1. lambda$getActualVoterHashes$1 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getActualVoterHashes$1 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.DREP_NOT_FOUND)); |
220 | voteHashes.add(dRepInfo.getDrepHash()); | |
221 | } else { | |
222 | voteHashes.add(voterHash); | |
223 | } | |
224 |
1
1. getActualVoterHashes : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getActualVoterHashes → KILLED |
return voteHashes; |
225 | } | |
226 | ||
227 | private List<GovActionType> getGovActionTypeByVoterType( | |
228 | VoterType voterType, GovActionType govActionType) { | |
229 | List<GovActionType> govActionTypeList = new ArrayList<>(Arrays.asList(GovActionType.values())); | |
230 | ||
231 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
if (voterType == null) { |
232 |
1
1. getGovActionTypeByVoterType : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovActionTypeByVoterType → NO_COVERAGE |
return govActionTypeList; |
233 | } | |
234 | ||
235 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
if (govActionType.equals(GovActionType.ALL)) { |
236 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
if (voterType.equals(VoterType.STAKING_POOL_KEY_HASH)) { |
237 | govActionTypeList.remove(GovActionType.NEW_CONSTITUTION); | |
238 | govActionTypeList.remove(GovActionType.PARAMETER_CHANGE_ACTION); | |
239 | govActionTypeList.remove(GovActionType.TREASURY_WITHDRAWALS_ACTION); | |
240 | } | |
241 | ||
242 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
if (voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH) |
243 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
|| voterType.equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH)) { |
244 | govActionTypeList.removeAll( | |
245 | List.of(GovActionType.NO_CONFIDENCE, GovActionType.UPDATE_COMMITTEE)); | |
246 | } | |
247 | } else { | |
248 | govActionTypeList = new ArrayList<>(); | |
249 | govActionTypeList.add(GovActionType.valueOf(govActionType.name())); | |
250 |
1
1. getGovActionTypeByVoterType : negated conditional → SURVIVED |
if (voterType.equals(VoterType.STAKING_POOL_KEY_HASH)) { |
251 | govActionTypeList.removeAll( | |
252 | List.of( | |
253 | GovActionType.NEW_CONSTITUTION, | |
254 | GovActionType.PARAMETER_CHANGE_ACTION, | |
255 | GovActionType.TREASURY_WITHDRAWALS_ACTION)); | |
256 | } | |
257 | } | |
258 |
1
1. getGovActionTypeByVoterType : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovActionTypeByVoterType → SURVIVED |
return govActionTypeList; |
259 | } | |
260 | ||
261 | @Override | |
262 | public GovernanceActionDetailsResponse getGovernanceActionDetails( | |
263 | String voterHash, GovernanceActionRequest governanceActionRequest) { | |
264 | Optional<GovActionDetailsProjection> govActionDetailsProjections = | |
265 | governanceActionRepository.getGovActionDetailsByTxHashAndIndex( | |
266 | governanceActionRequest.getTxHash(), governanceActionRequest.getIndex()); | |
267 | ||
268 |
1
1. getGovernanceActionDetails : negated conditional → KILLED |
if (govActionDetailsProjections.isEmpty()) { |
269 | throw new BusinessException(BusinessCode.GOVERNANCE_ACTION_NOT_FOUND); | |
270 | } | |
271 | GovActionType govActionType = govActionDetailsProjections.get().getType(); | |
272 | ||
273 | Boolean allowedVoteBySPO = isAllowedVoteBySPO(govActionType); | |
274 | Boolean allowedVoteByCC = isAllowedVoteByCC(govActionType); | |
275 |
1
1. getGovernanceActionDetails : negated conditional → KILLED |
if (voterHash.toLowerCase().startsWith("pool")) { |
276 | voterHash = | |
277 | poolHashRepository | |
278 | .getHashRawByView(voterHash) | |
279 |
1
1. lambda$getGovernanceActionDetails$2 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getGovernanceActionDetails$2 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.POOL_NOT_FOUND)); |
280 |
1
1. getGovernanceActionDetails : negated conditional → KILLED |
} else if (voterHash.toLowerCase().startsWith("drep")) { |
281 | DRepInfo dRepInfo = | |
282 | drepInfoRepository | |
283 | .findByDRepHashOrDRepId(voterHash) | |
284 |
1
1. lambda$getGovernanceActionDetails$3 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getGovernanceActionDetails$3 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.DREP_NOT_FOUND)); |
285 | voterHash = dRepInfo.getDrepHash(); | |
286 | } | |
287 | ||
288 |
1
1. getGovernanceActionDetails : negated conditional → SURVIVED |
if (governanceActionRequest.getVoterType().equals(VoterType.STAKING_POOL_KEY_HASH) |
289 |
1
1. getGovernanceActionDetails : negated conditional → NO_COVERAGE |
&& !allowedVoteBySPO) { |
290 |
1
1. getGovernanceActionDetails : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceActionDetails → NO_COVERAGE |
return GovernanceActionDetailsResponse.builder() |
291 | .allowedVoteBySPO(allowedVoteBySPO) | |
292 | .allowedVoteByCC(allowedVoteByCC) | |
293 | .build(); | |
294 | } | |
295 | GovernanceActionDetailsResponse response = | |
296 | governanceActionMapper.fromGovActionDetailsProjection(govActionDetailsProjections.get()); | |
297 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setAllowedVoteByCC → SURVIVED |
response.setAllowedVoteByCC(allowedVoteByCC); |
298 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setAllowedVoteBySPO → SURVIVED |
response.setAllowedVoteBySPO(allowedVoteBySPO); |
299 | // get pool name for SPO | |
300 |
1
1. getGovernanceActionDetails : negated conditional → SURVIVED |
if (governanceActionRequest.getVoterType().equals(VoterType.STAKING_POOL_KEY_HASH)) { |
301 | Optional<String> poolName = poolHashRepository.getPoolNameByPoolHashOrPoolView(voterHash); | |
302 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setPoolName → NO_COVERAGE |
response.setPoolName(poolName.orElse(null)); |
303 | } | |
304 | ||
305 | List<VoterType> voterTypes = new ArrayList<>(); | |
306 | ||
307 |
1
1. getGovernanceActionDetails : negated conditional → KILLED |
if (VoterType.DREP_KEY_HASH.equals(governanceActionRequest.getVoterType())) { |
308 | voterTypes.add(VoterType.DREP_KEY_HASH); | |
309 | voterTypes.add(VoterType.DREP_SCRIPT_HASH); | |
310 |
1
1. getGovernanceActionDetails : negated conditional → NO_COVERAGE |
} else if (VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH.equals( |
311 | governanceActionRequest.getVoterType())) { | |
312 | voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH); | |
313 | voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH); | |
314 |
1
1. getGovernanceActionDetails : negated conditional → NO_COVERAGE |
} else if (VoterType.STAKING_POOL_KEY_HASH.equals(governanceActionRequest.getVoterType())) { |
315 | voterTypes.add(VoterType.STAKING_POOL_KEY_HASH); | |
316 | } | |
317 | ||
318 | List<VotingProcedureProjection> votingProcedureProjections = | |
319 | votingProcedureRepository.getVotingProcedureByTxHashAndIndexAndVoterHash( | |
320 | governanceActionRequest.getTxHash(), | |
321 | governanceActionRequest.getIndex(), | |
322 | voterHash, | |
323 | voterTypes); | |
324 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::setExpiryDateOfGovAction → KILLED |
setExpiryDateOfGovAction(response); |
325 | // no vote procedure found = none vote | |
326 |
1
1. getGovernanceActionDetails : negated conditional → KILLED |
if (votingProcedureProjections.isEmpty()) { |
327 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setVoteType → NO_COVERAGE |
response.setVoteType(Vote.NONE); |
328 |
1
1. getGovernanceActionDetails : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceActionDetails → NO_COVERAGE |
return response; |
329 | } | |
330 | List<HistoryVote> historyVotes = | |
331 | votingProcedureProjections.stream() | |
332 | .map(votingProcedureMapper::fromVotingProcedureProjection) | |
333 | .toList(); | |
334 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setVoteType → KILLED |
response.setVoteType(votingProcedureProjections.get(0).getVote()); |
335 |
1
1. getGovernanceActionDetails : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setHistoryVotes → SURVIVED |
response.setHistoryVotes(historyVotes); |
336 |
1
1. getGovernanceActionDetails : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceActionDetails → KILLED |
return response; |
337 | } | |
338 | ||
339 | // STAKING POOL not allowed to vote on treasury withdrawals, parameter change and update | |
340 | private boolean isAllowedVoteBySPO(GovActionType govActionType) { | |
341 | List<GovActionType> govActionTypeListAllowedVoteBySPO = | |
342 | List.of( | |
343 | GovActionType.TREASURY_WITHDRAWALS_ACTION, | |
344 | GovActionType.PARAMETER_CHANGE_ACTION, | |
345 | GovActionType.NEW_CONSTITUTION); | |
346 |
2
1. isAllowedVoteBySPO : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::isAllowedVoteBySPO → SURVIVED 2. isAllowedVoteBySPO : negated conditional → KILLED |
return !govActionTypeListAllowedVoteBySPO.contains(govActionType); |
347 | } | |
348 | ||
349 | private boolean isAllowedVoteByCC(GovActionType govActionType) { | |
350 | List<GovActionType> govActionTypeListAllowedVoteByCc = | |
351 | List.of(GovActionType.NO_CONFIDENCE, GovActionType.UPDATE_COMMITTEE); | |
352 |
2
1. isAllowedVoteByCC : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::isAllowedVoteByCC → SURVIVED 2. isAllowedVoteByCC : negated conditional → KILLED |
return !govActionTypeListAllowedVoteByCc.contains(govActionType); |
353 | } | |
354 | ||
355 | void setExpiryDateOfGovAction(GovernanceActionDetailsResponse response) { | |
356 | Instant startTime = Instant.ofEpochSecond(response.getBlockTime()); | |
357 | EpochParam epochParam = epochParamRepository.findByEpochNo(response.getEpoch()); | |
358 | Instant expiryTime = | |
359 | startTime.plus( | |
360 |
1
1. setExpiryDateOfGovAction : Replaced long multiplication with division → SURVIVED |
epochDays * getLongValue(epochParam.getGovActionLifetime()), ChronoUnit.DAYS); |
361 |
1
1. setExpiryDateOfGovAction : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionDetailsResponse::setExpiryDate → SURVIVED |
response.setExpiryDate(Date.from(expiryTime)); |
362 | } | |
363 | ||
364 | private Long getLongValue(BigInteger bigInteger) { | |
365 |
2
1. getLongValue : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getLongValue → SURVIVED 2. getLongValue : negated conditional → SURVIVED |
return bigInteger == null ? 0L : bigInteger.longValue(); |
366 | } | |
367 | ||
368 | @Override | |
369 | public VotingChartResponse getVotingChartByGovActionTxHashAndIndex( | |
370 | String txHash, Integer index, VoterType voterType) { | |
371 | ||
372 | GovActionDetailsProjection govActionProjection = | |
373 | governanceActionRepository | |
374 | .getGovActionDetailsByTxHashAndIndex(txHash, index) | |
375 |
1
1. lambda$getVotingChartByGovActionTxHashAndIndex$4 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartByGovActionTxHashAndIndex$4 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.GOVERNANCE_ACTION_NOT_FOUND)); |
376 | ||
377 | EpochParam epochParam = epochParamRepository.findByEpochNo(govActionProjection.getEpoch()); | |
378 | EpochParam currentEpochParam = epochParamRepository.findCurrentEpochParam(); | |
379 | long activeMembers = | |
380 | committeeMemberRepository.countActiveMembersByExpiredEpochGreaterThan( | |
381 | currentEpochParam.getEpochNo()); | |
382 | ||
383 | CommitteeState committeeState = | |
384 |
1
1. getVotingChartByGovActionTxHashAndIndex : negated conditional → SURVIVED |
epochParam.getCommitteeMinSize() == null |
385 |
2
1. getVotingChartByGovActionTxHashAndIndex : changed conditional boundary → KILLED 2. getVotingChartByGovActionTxHashAndIndex : negated conditional → KILLED |
|| activeMembers >= epochParam.getCommitteeMinSize().intValue() |
386 | ? CommitteeState.CONFIDENCE | |
387 | : CommitteeState.NO_CONFIDENCE; | |
388 | ||
389 | VotingChartResponse votingChartResponse = | |
390 | VotingChartResponse.builder().txHash(txHash).index(index).build(); | |
391 | ||
392 | switch (voterType) { | |
393 | case DREP_KEY_HASH: | |
394 |
1
1. getVotingChartByGovActionTxHashAndIndex : removed call to org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartResponseForDRep → KILLED |
getVotingChartResponseForDRep( |
395 | votingChartResponse, epochParam, govActionProjection, committeeState); | |
396 |
1
1. getVotingChartByGovActionTxHashAndIndex : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartByGovActionTxHashAndIndex → KILLED |
return votingChartResponse; |
397 | case STAKING_POOL_KEY_HASH: | |
398 |
1
1. getVotingChartByGovActionTxHashAndIndex : removed call to org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartResponseForPool → KILLED |
getVotingChartResponseForPool( |
399 | votingChartResponse, epochParam, govActionProjection, committeeState); | |
400 |
1
1. getVotingChartByGovActionTxHashAndIndex : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartByGovActionTxHashAndIndex → KILLED |
return votingChartResponse; |
401 | case CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH: | |
402 |
1
1. getVotingChartByGovActionTxHashAndIndex : removed call to org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartResponseForCCType → KILLED |
getVotingChartResponseForCCType( |
403 | votingChartResponse, epochParam, govActionProjection, activeMembers); | |
404 |
1
1. getVotingChartByGovActionTxHashAndIndex : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartByGovActionTxHashAndIndex → KILLED |
return votingChartResponse; |
405 | default: | |
406 |
1
1. getVotingChartByGovActionTxHashAndIndex : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingChartByGovActionTxHashAndIndex → NO_COVERAGE |
return votingChartResponse; |
407 | } | |
408 | } | |
409 | ||
410 | @Override | |
411 | public BaseFilterResponse<GovernanceActionResponse> getGovCommitteeStatusHistory( | |
412 | GovCommitteeHistoryFilter govCommitteeHistoryFilter, Pageable pageable) { | |
413 | ||
414 | List<GovActionType> govActionTypeList = new ArrayList<>(); | |
415 |
1
1. getGovCommitteeStatusHistory : negated conditional → SURVIVED |
if (govCommitteeHistoryFilter.getActionType().equals(GovActionType.ALL)) { |
416 | govActionTypeList = List.of(GovActionType.NO_CONFIDENCE, GovActionType.UPDATE_COMMITTEE); | |
417 | } else { | |
418 | govActionTypeList = List.of(govCommitteeHistoryFilter.getActionType()); | |
419 | } | |
420 | ||
421 |
1
1. getGovCommitteeStatusHistory : Replaced long division with multiplication → SURVIVED |
long fromDate = Timestamp.valueOf(MIN_TIME).getTime() / 1000; |
422 | long toDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); | |
423 | ||
424 |
1
1. getGovCommitteeStatusHistory : negated conditional → KILLED |
if (Objects.nonNull(govCommitteeHistoryFilter.getFromDate())) { |
425 | fromDate = govCommitteeHistoryFilter.getFromDate().toEpochSecond(ZoneOffset.UTC); | |
426 | } | |
427 |
1
1. getGovCommitteeStatusHistory : negated conditional → KILLED |
if (Objects.nonNull(govCommitteeHistoryFilter.getToDate())) { |
428 | long to = govCommitteeHistoryFilter.getToDate().toEpochSecond(ZoneOffset.UTC); | |
429 | toDate = Math.min(to, toDate); | |
430 | } | |
431 | ||
432 | String anchorText = | |
433 |
1
1. getGovCommitteeStatusHistory : negated conditional → KILLED |
govCommitteeHistoryFilter.getAnchorText() == null |
434 | ? null | |
435 | : govCommitteeHistoryFilter.getAnchorText().toLowerCase(); | |
436 | ||
437 | Page<GovernanceActionResponse> governanceActionProjections = | |
438 | governanceActionRepository | |
439 | .getAllGovCommitteeHistory( | |
440 | govActionTypeList, | |
441 | fromDate, | |
442 | toDate, | |
443 | govCommitteeHistoryFilter.getGovernanceActionTxHash(), | |
444 | anchorText, | |
445 | pageable) | |
446 | .map(governanceActionMapper::fromGovernanceActionProjection); | |
447 | ||
448 |
1
1. getGovCommitteeStatusHistory : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovCommitteeStatusHistory → KILLED |
return new BaseFilterResponse<>(governanceActionProjections); |
449 | } | |
450 | ||
451 | @Override | |
452 | public GovernanceOverviewResponse getGovernanceOverview() { | |
453 | EpochParam currentEpochParam = epochParamRepository.findCurrentEpochParam(); | |
454 | ||
455 | Long activeDReps = drepInfoRepository.countByStatus(DRepStatus.ACTIVE); | |
456 | Long activeSPOs = | |
457 | Objects.requireNonNull( | |
458 | redisTemplate.opsForValue().get(CommonConstant.REDIS_POOL_ACTIVATE + network)) | |
459 | .longValue(); | |
460 | Long activeCommittees = | |
461 | committeeMemberRepository.countActiveMembersByExpiredEpochGreaterThan( | |
462 | currentEpochParam.getEpochNo()); | |
463 | ||
464 | Map<GovActionType, Long> govActionTypeMap = | |
465 | governanceActionRepository.getGovActionGroupByGovActionType().stream() | |
466 | .collect( | |
467 | Collectors.toMap( | |
468 | GovernanceActionProjection::getType, GovernanceActionProjection::getGovCount)); | |
469 | ||
470 | Map<GovActionStatus, Long> govActionStatusMap = | |
471 | governanceActionRepository.getGovActionGroupByGovActionStatus().stream() | |
472 | .collect( | |
473 | Collectors.toMap( | |
474 | GovernanceActionProjection::getStatus, | |
475 | GovernanceActionProjection::getGovCount)); | |
476 | ||
477 |
1
1. getGovernanceOverview : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceOverview → KILLED |
return GovernanceOverviewResponse.builder() |
478 | .activeDReps(activeDReps) | |
479 | .activeSPOs(activeSPOs) | |
480 | .activeCommittees(activeCommittees) | |
481 | .totalGovActions(govActionTypeMap.values().stream().reduce(0L, Long::sum)) | |
482 | .govCountMap(govActionTypeMap) | |
483 | .govStatusMap(govActionStatusMap) | |
484 | .build(); | |
485 | } | |
486 | ||
487 | @Override | |
488 | public GovernanceActionOverViewResponse getGovernanceActionOverviewResponse( | |
489 | String txHash, Integer index) { | |
490 | ||
491 | GovernanceActionOverviewProjection governanceActionOverviewProjection = | |
492 | governanceActionRepository.getGovernanceActionOverviewByTxHashAndIndex(txHash, index); | |
493 | GovernanceActionOverViewResponse response = | |
494 | governanceActionMapper.fromGovernanceActionOverviewProjection( | |
495 | governanceActionOverviewProjection); | |
496 | GovActionType type = response.getActionType(); | |
497 |
1
1. getGovernanceActionOverviewResponse : negated conditional → KILLED |
if (Objects.nonNull(governanceActionOverviewProjection.getRawData()) |
498 |
1
1. getGovernanceActionOverviewResponse : negated conditional → KILLED |
&& Objects.nonNull(governanceActionOverviewProjection.getAnchorHash())) { |
499 | String hash = | |
500 | HexUtil.encodeHexString( | |
501 | Blake2bUtil.blake2bHash256( | |
502 | governanceActionOverviewProjection.getRawData().getBytes())); | |
503 | ||
504 |
1
1. getGovernanceActionOverviewResponse : negated conditional → KILLED |
if (!hash.equals(governanceActionOverviewProjection.getAnchorHash())) { |
505 |
1
1. getGovernanceActionOverviewResponse : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionOverViewResponse::setIsValidHash → KILLED |
response.setIsValidHash(false); |
506 | } else { | |
507 |
1
1. getGovernanceActionOverviewResponse : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionOverViewResponse::setIsValidHash → KILLED |
response.setIsValidHash(true); |
508 | } | |
509 | } else { | |
510 |
1
1. getGovernanceActionOverviewResponse : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionOverViewResponse::setIsValidHash → NO_COVERAGE |
response.setIsValidHash(false); |
511 | } | |
512 |
1
1. getGovernanceActionOverviewResponse : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionOverViewResponse::setAllowedVoteByCC → KILLED |
response.setAllowedVoteByCC(isAllowedVoteByCC(type)); |
513 |
1
1. getGovernanceActionOverviewResponse : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/GovernanceActionOverViewResponse::setAllowedVoteBySPO → KILLED |
response.setAllowedVoteBySPO(isAllowedVoteBySPO(type)); |
514 |
1
1. getGovernanceActionOverviewResponse : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getGovernanceActionOverviewResponse → KILLED |
return response; |
515 | } | |
516 | ||
517 | @Override | |
518 | public BaseFilterResponse<AuthorResponse> getAuthorsByAnchor( | |
519 | String anchorUrl, String anchorHash, Pageable pageable) { | |
520 | String rawData = | |
521 | offChainVoteGovActionDataRepository.getRawDataByAnchorUrlAndAnchorHash( | |
522 | anchorUrl, anchorHash); | |
523 |
1
1. getAuthorsByAnchor : negated conditional → KILLED |
if (Objects.isNull(rawData)) { |
524 |
1
1. getAuthorsByAnchor : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getAuthorsByAnchor → KILLED |
return new BaseFilterResponse<>(Page.empty(pageable)); |
525 | } | |
526 | ObjectMapper mapper = new ObjectMapper(); | |
527 | // ensure that: the field which missing in the json string will not throw exception | |
528 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
529 | try { | |
530 | GovActionMetaData govActionMetaData = mapper.readValue(rawData, GovActionMetaData.class); | |
531 |
2
1. getAuthorsByAnchor : negated conditional → KILLED 2. getAuthorsByAnchor : negated conditional → KILLED |
if (govActionMetaData.getAuthors() == null || govActionMetaData.getAuthors().isEmpty()) { |
532 |
1
1. getAuthorsByAnchor : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getAuthorsByAnchor → KILLED |
return new BaseFilterResponse<>(Page.empty(pageable)); |
533 | } | |
534 | List<AuthorResponse> authorResponses = | |
535 | govActionMetaData.getAuthors().stream() | |
536 | .map( | |
537 | author -> | |
538 |
1
1. lambda$getAuthorsByAnchor$5 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getAuthorsByAnchor$5 → KILLED |
AuthorResponse.builder() |
539 |
1
1. lambda$getAuthorsByAnchor$5 : negated conditional → KILLED |
.name(Objects.nonNull(author.getName()) ? author.getName() : null) |
540 | .publicKey( | |
541 |
1
1. lambda$getAuthorsByAnchor$5 : negated conditional → KILLED |
Objects.nonNull(author.getWitness()) |
542 | ? author.getWitness().getPublicKey() | |
543 | : null) | |
544 | .witnessAlgorithm( | |
545 |
1
1. lambda$getAuthorsByAnchor$5 : negated conditional → KILLED |
Objects.nonNull(author.getWitness()) |
546 | ? author.getWitness().getWitnessAlgorithm() | |
547 | : null) | |
548 | .signature( | |
549 |
1
1. lambda$getAuthorsByAnchor$5 : negated conditional → KILLED |
Objects.nonNull(author.getWitness()) |
550 | ? author.getWitness().getSignature() | |
551 | : null) | |
552 | .build()) | |
553 | .collect(Collectors.toList()); | |
554 |
1
1. getAuthorsByAnchor : removed call to java/util/List::sort → SURVIVED |
authorResponses.sort(Comparator.comparing(AuthorResponse::getName)); |
555 |
1
1. getAuthorsByAnchor : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getAuthorsByAnchor → KILLED |
return new BaseFilterResponse<>(BaseFilterResponse.getPageImpl(authorResponses, pageable)); |
556 | } catch (JsonProcessingException e) { | |
557 | log.error("Error when parsing raw data to GovActionMetaData: {}", e.getMessage()); | |
558 |
1
1. getAuthorsByAnchor : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getAuthorsByAnchor → KILLED |
return new BaseFilterResponse<>(Page.empty(pageable)); |
559 | } | |
560 | } | |
561 | ||
562 | @Override | |
563 | public BaseFilterResponse<VotingOnGovActionResponse> getVotingOnGovAction( | |
564 | VoteFilter voteFilter, Pageable pageable) { | |
565 | // if voter type is null, get all type of voter | |
566 |
1
1. getVotingOnGovAction : negated conditional → KILLED |
if (voteFilter.getVoterType() == null) { |
567 |
1
1. getVotingOnGovAction : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingOnGovAction → KILLED |
return getDataWithAnyTypeOrCCTypeOrSPOType(voteFilter, pageable); |
568 |
1
1. getVotingOnGovAction : negated conditional → KILLED |
} else if (voteFilter.getVoterType().equals(VoterType.DREP_KEY_HASH) |
569 |
1
1. getVotingOnGovAction : negated conditional → NO_COVERAGE |
|| voteFilter.getVoterType().equals(VoterType.DREP_SCRIPT_HASH)) { |
570 |
1
1. getVotingOnGovAction : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingOnGovAction → KILLED |
return getDataWithDRepType(voteFilter, pageable); |
571 | } else { | |
572 |
1
1. getVotingOnGovAction : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getVotingOnGovAction → NO_COVERAGE |
return getDataWithAnyTypeOrCCTypeOrSPOType(voteFilter, pageable); |
573 | } | |
574 | } | |
575 | ||
576 | @Override | |
577 | public RangeFilterVoteResponse getRangeFilterVoteResponse(String txHash, Integer index) { | |
578 | DRepRangeProjection dRepRangeProjection = | |
579 | latestVotingProcedureRepository.getDRepRangeValuesForVotesFilter(txHash, index); | |
580 |
1
1. getRangeFilterVoteResponse : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getRangeFilterVoteResponse → KILLED |
return RangeFilterVoteResponse.builder() |
581 | .maxActiveStake(dRepRangeProjection.getMaxActiveVoteStake()) | |
582 | .minActiveStake(dRepRangeProjection.getMinActiveVoteStake()) | |
583 | .build(); | |
584 | } | |
585 | ||
586 | private BaseFilterResponse<VotingOnGovActionResponse> getDataWithAnyTypeOrCCTypeOrSPOType( | |
587 | VoteFilter voteFilter, Pageable pageable) { | |
588 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : Replaced long division with multiplication → SURVIVED |
long fromDate = Timestamp.valueOf(MIN_TIME).getTime() / 1000; |
589 | long toDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); | |
590 | ||
591 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : negated conditional → KILLED |
if (Objects.nonNull(voteFilter.getFromDate())) { |
592 | fromDate = voteFilter.getFromDate().toEpochSecond(ZoneOffset.UTC); | |
593 | } | |
594 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : negated conditional → KILLED |
if (Objects.nonNull(voteFilter.getToDate())) { |
595 | long to = voteFilter.getToDate().toEpochSecond(ZoneOffset.UTC); | |
596 | toDate = Math.min(to, toDate); | |
597 | } | |
598 | ||
599 | List<VoterType> voterTypes = new ArrayList<>(); | |
600 | ||
601 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : negated conditional → KILLED |
if (voteFilter.getVoterType() == null) { |
602 | voterTypes.addAll(Arrays.stream(VoterType.values()).toList()); | |
603 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : negated conditional → NO_COVERAGE |
} else if (voteFilter.getVoterType().equals(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH)) { |
604 | voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH); | |
605 | voterTypes.add(VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH); | |
606 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : negated conditional → NO_COVERAGE |
} else if (voteFilter.getVoterType().equals(VoterType.STAKING_POOL_KEY_HASH)) { |
607 | voterTypes.add(VoterType.STAKING_POOL_KEY_HASH); | |
608 | } | |
609 | ||
610 | Page<LatestVotingProcedureProjection> latestVotingProcedureProjections = | |
611 | latestVotingProcedureRepository.getVoteOnGovActionByTypeIn( | |
612 | voteFilter.getTxHash(), | |
613 | voteFilter.getIndex(), | |
614 | voteFilter.getVoterHash(), | |
615 | fromDate, | |
616 | toDate, | |
617 | voterTypes, | |
618 | pageable); | |
619 | ||
620 | List<VotingOnGovActionResponse> votingOnGovActionResponses = | |
621 | latestVotingProcedureProjections.stream() | |
622 | .map(latestVotingProcedureMapper::fromLatestVotingProcedureProjection) | |
623 | .toList(); | |
624 | ||
625 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : removed call to org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getActiveStakeForDRep → KILLED |
getActiveStakeForDRep(votingOnGovActionResponses); |
626 | ||
627 |
1
1. getDataWithAnyTypeOrCCTypeOrSPOType : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getDataWithAnyTypeOrCCTypeOrSPOType → KILLED |
return new BaseFilterResponse<>(latestVotingProcedureProjections, votingOnGovActionResponses); |
628 | } | |
629 | ||
630 | private void getActiveStakeForDRep(List<VotingOnGovActionResponse> votingOnGovActionResponses) { | |
631 | List<String> drepHashes = | |
632 | votingOnGovActionResponses.stream() | |
633 | .filter( | |
634 | votingOnGovActionResponse -> | |
635 |
2
1. lambda$getActiveStakeForDRep$6 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getActiveStakeForDRep$6 → SURVIVED 2. lambda$getActiveStakeForDRep$6 : negated conditional → SURVIVED |
votingOnGovActionResponse.getVoterType().equals(VoterType.DREP_KEY_HASH) |
636 | || votingOnGovActionResponse | |
637 | .getVoterType() | |
638 |
1
1. lambda$getActiveStakeForDRep$6 : negated conditional → SURVIVED |
.equals(VoterType.DREP_SCRIPT_HASH)) |
639 | .map(VotingOnGovActionResponse::getVoterHash) | |
640 | .collect(Collectors.toList()); | |
641 | List<DRepInfoProjection> dRepInfoProjections = | |
642 | drepInfoRepository.findDRepActiveStakeInHashList(drepHashes); | |
643 | Map<String, BigInteger> activeVoteStakeMap = | |
644 | dRepInfoProjections.stream() | |
645 | .collect( | |
646 | Collectors.toMap( | |
647 | DRepInfoProjection::getDrepHash, DRepInfoProjection::getActiveVoteStake)); | |
648 |
1
1. getActiveStakeForDRep : removed call to java/util/List::forEach → SURVIVED |
votingOnGovActionResponses.forEach( |
649 | votingOnGovActionResponse -> { | |
650 |
1
1. lambda$getActiveStakeForDRep$7 : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingOnGovActionResponse::setVotingStake → SURVIVED |
votingOnGovActionResponse.setVotingStake( |
651 | activeVoteStakeMap.getOrDefault(votingOnGovActionResponse.getVoterHash(), null)); | |
652 | }); | |
653 | } | |
654 | ||
655 | private BaseFilterResponse<VotingOnGovActionResponse> getDataWithDRepType( | |
656 | VoteFilter voteFilter, Pageable pageable) { | |
657 | ||
658 |
1
1. getDataWithDRepType : Replaced long division with multiplication → SURVIVED |
long fromDate = Timestamp.valueOf(MIN_TIME).getTime() / 1000; |
659 | long toDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); | |
660 | ||
661 |
1
1. getDataWithDRepType : negated conditional → KILLED |
if (Objects.nonNull(voteFilter.getFromDate())) { |
662 | fromDate = voteFilter.getFromDate().toEpochSecond(ZoneOffset.UTC); | |
663 | } | |
664 |
1
1. getDataWithDRepType : negated conditional → KILLED |
if (Objects.nonNull(voteFilter.getToDate())) { |
665 | long to = voteFilter.getToDate().toEpochSecond(ZoneOffset.UTC); | |
666 | toDate = Math.min(to, toDate); | |
667 | } | |
668 | ||
669 |
1
1. getDataWithDRepType : negated conditional → SURVIVED |
if (voteFilter.getActiveStakeFrom() == null) { |
670 |
1
1. getDataWithDRepType : removed call to org/cardanofoundation/explorer/api/model/request/governanceAction/VoteFilter::setActiveStakeFrom → SURVIVED |
voteFilter.setActiveStakeFrom(BigInteger.ZERO); |
671 | } | |
672 | ||
673 |
1
1. getDataWithDRepType : negated conditional → SURVIVED |
if (voteFilter.getActiveStakeTo() == null) { |
674 |
1
1. getDataWithDRepType : removed call to org/cardanofoundation/explorer/api/model/request/governanceAction/VoteFilter::setActiveStakeTo → SURVIVED |
voteFilter.setActiveStakeTo(BigInteger.valueOf(Long.MAX_VALUE)); |
675 | } | |
676 | ||
677 | List<VoterType> voterTypes = | |
678 | new ArrayList<>(List.of(VoterType.DREP_KEY_HASH, VoterType.DREP_SCRIPT_HASH)); | |
679 | ||
680 | Page<LatestVotingProcedureProjection> latestVotingProcedureProjections = | |
681 | latestVotingProcedureRepository.getVoteOnGovActionByDRepType( | |
682 | voteFilter.getTxHash(), | |
683 | voteFilter.getIndex(), | |
684 | voteFilter.getVoterHash(), | |
685 | fromDate, | |
686 | toDate, | |
687 | voterTypes, | |
688 | voteFilter.getActiveStakeFrom(), | |
689 | voteFilter.getActiveStakeTo(), | |
690 | pageable); | |
691 | ||
692 | List<VotingOnGovActionResponse> votingOnGovActionResponses = | |
693 | latestVotingProcedureProjections.stream() | |
694 | .map(latestVotingProcedureMapper::fromLatestVotingProcedureProjection) | |
695 | .toList(); | |
696 | ||
697 |
1
1. getDataWithDRepType : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getDataWithDRepType → KILLED |
return new BaseFilterResponse<>(latestVotingProcedureProjections, votingOnGovActionResponses); |
698 | } | |
699 | ||
700 | // TODO: Active vote stake of Pool type is not available. | |
701 | private void getVotingChartResponseForPool( | |
702 | VotingChartResponse votingChartResponse, | |
703 | EpochParam epochParam, | |
704 | GovActionDetailsProjection govActionDetailsProjection, | |
705 | CommitteeState committeeState) { | |
706 | ||
707 | switch (govActionDetailsProjection.getType()) { | |
708 | case NO_CONFIDENCE: | |
709 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getPvtMotionNoConfidence()); |
710 | break; | |
711 | case UPDATE_COMMITTEE: | |
712 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold( |
713 |
1
1. getVotingChartResponseForPool : negated conditional → NO_COVERAGE |
CommitteeState.CONFIDENCE.equals(committeeState) |
714 | ? epochParam.getPvtCommitteeNormal() | |
715 | : epochParam.getPvtCommitteeNoConfidence()); | |
716 | break; | |
717 | case HARD_FORK_INITIATION_ACTION: | |
718 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getPvtHardForkInitiation()); |
719 | break; | |
720 | case INFO_ACTION: | |
721 | /* CIP 1694 | |
722 | * The two thresholds for the Info action are set to 100% since setting it any lower would result in not being able to poll above the threshold. */ | |
723 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → KILLED |
votingChartResponse.setThreshold(1.0); |
724 | break; | |
725 | default: | |
726 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(null); |
727 | } | |
728 | List<PoolOverviewProjection> poolCanVoteList = | |
729 | poolHashRepository.getSlotCreatedAtGroupByPoolHash(govActionDetailsProjection.getSlot()); | |
730 | ||
731 | Map<String, Long> poolHashByPoolIdMap = | |
732 | poolCanVoteList.stream() | |
733 | .collect( | |
734 | Collectors.toMap( | |
735 | PoolOverviewProjection::getPoolHash, PoolOverviewProjection::getPoolId)); | |
736 | ||
737 | BigInteger totalActiveVoteStake = | |
738 | getTotalActiveStakeByPoolHashesIn( | |
739 | poolHashByPoolIdMap.keySet().stream().toList(), govActionDetailsProjection.getEpoch()); | |
740 | ||
741 | List<CompletableFuture<List<LatestVotingProcedureProjection>>> futures = new ArrayList<>(); | |
742 | List<String> poolHashes = new ArrayList<>(poolHashByPoolIdMap.keySet()); | |
743 | int COLLECTION_SIZE = poolHashes.size(); | |
744 | for (int startBatchIdx = 0; | |
745 |
2
1. getVotingChartResponseForPool : changed conditional boundary → SURVIVED 2. getVotingChartResponseForPool : negated conditional → KILLED |
startBatchIdx < COLLECTION_SIZE; |
746 |
1
1. getVotingChartResponseForPool : Replaced integer addition with subtraction → KILLED |
startBatchIdx += DEFAULT_BATCH_SIZE) { |
747 |
1
1. getVotingChartResponseForPool : Replaced integer addition with subtraction → KILLED |
int endBatchIdx = Math.min(startBatchIdx + DEFAULT_BATCH_SIZE, COLLECTION_SIZE); |
748 | List<String> batchList = poolHashes.subList(startBatchIdx, endBatchIdx); | |
749 | futures.add( | |
750 | getLatestVotingProcedureProjection( | |
751 | govActionDetailsProjection.getTxHash(), | |
752 | govActionDetailsProjection.getIndex(), | |
753 | batchList, | |
754 | List.of(VoterType.STAKING_POOL_KEY_HASH))); | |
755 | } | |
756 | ||
757 | CompletableFuture<List<LatestVotingProcedureProjection>> allFutures = | |
758 | CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) | |
759 | .thenApply( | |
760 | v -> | |
761 |
1
1. lambda$getVotingChartResponseForPool$8 : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartResponseForPool$8 → KILLED |
futures.stream() |
762 | .map(CompletableFuture::join) | |
763 | .filter(Objects::nonNull) | |
764 | .flatMap(List::stream) | |
765 | .toList()); | |
766 | ||
767 | List<LatestVotingProcedureProjection> latestVotingProcedureProjections = allFutures.join(); | |
768 | ||
769 | Map<Vote, List<LatestVotingProcedureProjection>> voteCount = | |
770 | latestVotingProcedureProjections.stream() | |
771 | .collect(Collectors.groupingBy(LatestVotingProcedureProjection::getVote)); | |
772 | ||
773 | Map<Vote, BigInteger> voteStake = | |
774 | voteCount.entrySet().stream() | |
775 | .collect( | |
776 | Collectors.toMap( | |
777 | Map.Entry::getKey, | |
778 | entry -> | |
779 |
1
1. lambda$getVotingChartResponseForPool$9 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartResponseForPool$9 → KILLED |
getTotalActiveStakeByPoolHashesIn( |
780 | entry.getValue().stream() | |
781 | .map(LatestVotingProcedureProjection::getVoterHash) | |
782 | .collect(Collectors.toList()), | |
783 | govActionDetailsProjection.getEpoch()))); | |
784 | ||
785 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setActiveVoteStake → KILLED |
votingChartResponse.setActiveVoteStake(totalActiveVoteStake); |
786 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setTotalYesVoteStake → KILLED |
votingChartResponse.setTotalYesVoteStake(voteStake.getOrDefault(Vote.YES, BigInteger.ZERO)); |
787 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setTotalNoVoteStake → KILLED |
votingChartResponse.setTotalNoVoteStake(voteStake.getOrDefault(Vote.NO, BigInteger.ZERO)); |
788 |
1
1. getVotingChartResponseForPool : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setAbstainVoteStake → KILLED |
votingChartResponse.setAbstainVoteStake(voteStake.getOrDefault(Vote.ABSTAIN, BigInteger.ZERO)); |
789 | } | |
790 | ||
791 | private CompletableFuture<List<LatestVotingProcedureProjection>> | |
792 | getLatestVotingProcedureProjection( | |
793 | String txHash, Integer index, List<String> voterHash, List<VoterType> voterType) { | |
794 |
1
1. getLatestVotingProcedureProjection : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getLatestVotingProcedureProjection → KILLED |
return CompletableFuture.supplyAsync( |
795 | () -> | |
796 |
1
1. lambda$getLatestVotingProcedureProjection$10 : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getLatestVotingProcedureProjection$10 → KILLED |
latestVotingProcedureRepository.findByGovActionTxHashAndGovActionIndex( |
797 | txHash, index, voterHash, voterType)); | |
798 | } | |
799 | ||
800 | private BigInteger getTotalActiveStakeByPoolHashesIn(List<String> poolIds, Integer epochNo) { | |
801 | ||
802 |
1
1. getTotalActiveStakeByPoolHashesIn : negated conditional → KILLED |
if (fetchRewardDataService.useKoios()) { |
803 |
1
1. getTotalActiveStakeByPoolHashesIn : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getTotalActiveStakeByPoolHashesIn → NO_COVERAGE |
return BatchUtils.processInBatches( |
804 | DEFAULT_BATCH_SIZE, | |
805 | poolIds, | |
806 |
1
1. lambda$getTotalActiveStakeByPoolHashesIn$11 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getTotalActiveStakeByPoolHashesIn$11 → NO_COVERAGE |
poolIdList -> sumBalanceByPoolIdInWithKoi0s(poolIdList, epochNo)); |
807 | } | |
808 | // without using koios profile | |
809 | List<String> stakeView = delegationRepository.getStakeAddressDelegatorsByPoolIds(poolIds); | |
810 |
1
1. getTotalActiveStakeByPoolHashesIn : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getTotalActiveStakeByPoolHashesIn → KILLED |
return BatchUtils.processInBatches( |
811 | DEFAULT_BATCH_SIZE, stakeView, this::sumBalanceByStakeAddressIn); | |
812 | } | |
813 | ||
814 | private CompletableFuture<BigInteger> sumBalanceByPoolIdInWithKoi0s( | |
815 | Collection<String> poolHashes, Integer epochNo) { | |
816 |
1
1. sumBalanceByPoolIdInWithKoi0s : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::sumBalanceByPoolIdInWithKoi0s → NO_COVERAGE |
return CompletableFuture.supplyAsync( |
817 |
1
1. lambda$sumBalanceByPoolIdInWithKoi0s$12 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$sumBalanceByPoolIdInWithKoi0s$12 → NO_COVERAGE |
() -> poolInfoRepository.getTotalActiveStakeByPoolIdIn(poolHashes, epochNo)); |
818 | } | |
819 | ||
820 | private CompletableFuture<BigInteger> sumBalanceByStakeAddressIn(Collection<String> stakeView) { | |
821 |
1
1. sumBalanceByStakeAddressIn : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::sumBalanceByStakeAddressIn → KILLED |
return CompletableFuture.supplyAsync( |
822 |
1
1. lambda$sumBalanceByStakeAddressIn$13 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$sumBalanceByStakeAddressIn$13 → KILLED |
() -> stakeAddressBalanceRepository.sumBalanceByStakeAddressIn(stakeView)); |
823 | } | |
824 | ||
825 | // TODO: Active vote stake of DRep type is not available. | |
826 | private void getVotingChartResponseForDRep( | |
827 | VotingChartResponse votingChartResponse, | |
828 | EpochParam epochParam, | |
829 | GovActionDetailsProjection govActionDetailsProjection, | |
830 | CommitteeState committeeState) { | |
831 | switch (govActionDetailsProjection.getType()) { | |
832 | case NO_CONFIDENCE: | |
833 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getDvtMotionNoConfidence()); |
834 | break; | |
835 | case UPDATE_COMMITTEE: | |
836 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → KILLED |
votingChartResponse.setThreshold( |
837 |
1
1. getVotingChartResponseForDRep : negated conditional → KILLED |
CommitteeState.CONFIDENCE.equals(committeeState) |
838 | ? epochParam.getDvtCommitteeNormal() | |
839 | : epochParam.getDvtCommitteeNoConfidence()); | |
840 | break; | |
841 | case NEW_CONSTITUTION: | |
842 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getDvtUpdateToConstitution()); |
843 | break; | |
844 | case HARD_FORK_INITIATION_ACTION: | |
845 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getDvtHardForkInitiation()); |
846 | break; | |
847 | case PARAMETER_CHANGE_ACTION: | |
848 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → KILLED |
votingChartResponse.setThreshold( |
849 | getParameterChangeActionThreshold(epochParam, govActionDetailsProjection.getDetails())); | |
850 | break; | |
851 | case TREASURY_WITHDRAWALS_ACTION: | |
852 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(epochParam.getDvtTreasuryWithdrawal()); |
853 | break; | |
854 | case INFO_ACTION: | |
855 | /* CIP 1694 | |
856 | * The two thresholds for the Info action are set to 100% since setting it any lower would result in not being able to poll above the threshold. */ | |
857 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(1.0); |
858 | break; | |
859 | default: | |
860 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(null); |
861 | } | |
862 | ||
863 | List<DRepInfoProjection> dRepInfoProjections = | |
864 | drepInfoRepository.findDRepByCreatedAt(govActionDetailsProjection.getBlockTime()); | |
865 | Map<String, BigInteger> activeVoteStakeByDRepMap = | |
866 | dRepInfoProjections.stream() | |
867 | .collect( | |
868 | Collectors.toMap( | |
869 | DRepInfoProjection::getDrepHash, DRepInfoProjection::getActiveVoteStake)); | |
870 | BigInteger totalActiveVoteStake = | |
871 | dRepInfoProjections.stream() | |
872 | .map(DRepInfoProjection::getActiveVoteStake) | |
873 | .filter(Objects::nonNull) | |
874 | .reduce(BigInteger::add) | |
875 | .orElse(BigInteger.ZERO); | |
876 | ||
877 | List<String> dRepHashes = | |
878 | dRepInfoProjections.stream().map(DRepInfoProjection::getDrepHash).toList(); | |
879 | ||
880 | List<CompletableFuture<List<LatestVotingProcedureProjection>>> futures = new ArrayList<>(); | |
881 | int COLLECTION_SIZE = dRepHashes.size(); | |
882 | for (int startBatchIdx = 0; | |
883 |
2
1. getVotingChartResponseForDRep : changed conditional boundary → SURVIVED 2. getVotingChartResponseForDRep : negated conditional → KILLED |
startBatchIdx < COLLECTION_SIZE; |
884 |
1
1. getVotingChartResponseForDRep : Replaced integer addition with subtraction → KILLED |
startBatchIdx += DEFAULT_BATCH_SIZE) { |
885 |
1
1. getVotingChartResponseForDRep : Replaced integer addition with subtraction → KILLED |
int endBatchIdx = Math.min(startBatchIdx + DEFAULT_BATCH_SIZE, COLLECTION_SIZE); |
886 | List<String> batchList = dRepHashes.subList(startBatchIdx, endBatchIdx); | |
887 | futures.add( | |
888 | getLatestVotingProcedureProjection( | |
889 | govActionDetailsProjection.getTxHash(), | |
890 | govActionDetailsProjection.getIndex(), | |
891 | batchList, | |
892 | List.of(VoterType.DREP_KEY_HASH, VoterType.DREP_SCRIPT_HASH))); | |
893 | } | |
894 | ||
895 | CompletableFuture<List<LatestVotingProcedureProjection>> allFutures = | |
896 | CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) | |
897 | .thenApply( | |
898 | v -> | |
899 |
1
1. lambda$getVotingChartResponseForDRep$14 : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartResponseForDRep$14 → KILLED |
futures.stream() |
900 | .map(CompletableFuture::join) | |
901 | .filter(Objects::nonNull) | |
902 | .flatMap(List::stream) | |
903 | .toList()); | |
904 | ||
905 | List<LatestVotingProcedureProjection> latestVotingProcedureProjections = allFutures.join(); | |
906 | ||
907 | Map<Vote, List<LatestVotingProcedureProjection>> voteCount = | |
908 | latestVotingProcedureProjections.stream() | |
909 | .collect(Collectors.groupingBy(LatestVotingProcedureProjection::getVote)); | |
910 | ||
911 | Map<Vote, BigInteger> voteStake = | |
912 | voteCount.entrySet().stream() | |
913 | .collect( | |
914 | Collectors.toMap( | |
915 | Map.Entry::getKey, | |
916 | entry -> | |
917 | entry.getValue().stream() | |
918 | .map( // get active vote stake of DRep | |
919 | latestVotingProcedureProjection -> | |
920 |
1
1. lambda$getVotingChartResponseForDRep$15 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartResponseForDRep$15 → KILLED |
activeVoteStakeByDRepMap.getOrDefault( |
921 | latestVotingProcedureProjection.getVoterHash(), | |
922 | BigInteger.ZERO)) | |
923 | .filter(Objects::nonNull) | |
924 | .reduce(BigInteger::add) | |
925 |
1
1. lambda$getVotingChartResponseForDRep$16 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::lambda$getVotingChartResponseForDRep$16 → KILLED |
.orElse(BigInteger.ZERO))); |
926 | ||
927 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setActiveVoteStake → KILLED |
votingChartResponse.setActiveVoteStake(totalActiveVoteStake); |
928 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setTotalYesVoteStake → KILLED |
votingChartResponse.setTotalYesVoteStake(voteStake.getOrDefault(Vote.YES, BigInteger.ZERO)); |
929 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setTotalNoVoteStake → KILLED |
votingChartResponse.setTotalNoVoteStake(voteStake.getOrDefault(Vote.NO, BigInteger.ZERO)); |
930 |
1
1. getVotingChartResponseForDRep : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setAbstainVoteStake → SURVIVED |
votingChartResponse.setAbstainVoteStake(voteStake.getOrDefault(Vote.ABSTAIN, BigInteger.ZERO)); |
931 | } | |
932 | ||
933 | // TODO: Threshold for CC type is not available. It must be null for now. | |
934 | private void getVotingChartResponseForCCType( | |
935 | VotingChartResponse votingChartResponse, | |
936 | EpochParam epochParam, | |
937 | GovActionDetailsProjection govActionDetailsProjection, | |
938 | Long activeMembers) { | |
939 | List<GovActionType> govActionTypesThatNotAllowedVoteByCC = | |
940 | List.of(GovActionType.NO_CONFIDENCE, GovActionType.UPDATE_COMMITTEE); | |
941 |
1
1. getVotingChartResponseForCCType : negated conditional → KILLED |
if (govActionTypesThatNotAllowedVoteByCC.contains(govActionDetailsProjection.getType())) { |
942 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → NO_COVERAGE |
votingChartResponse.setThreshold(null); |
943 | } else { | |
944 | Double threshold = | |
945 | committeeRepository | |
946 | .getLatestCCThreshold() | |
947 | .orElseGet(protocolParamService::getCCThresholdFromConwayGenesis); | |
948 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setThreshold → SURVIVED |
votingChartResponse.setThreshold(threshold); |
949 | } | |
950 | ||
951 | List<LatestVotingProcedureProjection> latestVotingProcedureProjections = | |
952 | latestVotingProcedureRepository.getLatestVotingProcedureByGovActionTxHashAndGovActionIndex( | |
953 | govActionDetailsProjection.getTxHash(), | |
954 | govActionDetailsProjection.getIndex(), | |
955 | List.of( | |
956 | VoterType.CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH, | |
957 | VoterType.CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH), | |
958 | govActionDetailsProjection.getBlockTime()); | |
959 | ||
960 | Map<Vote, Long> voteCount = | |
961 | latestVotingProcedureProjections.stream() | |
962 | .collect( | |
963 | Collectors.groupingBy( | |
964 | LatestVotingProcedureProjection::getVote, Collectors.counting())); | |
965 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setYesCcMembers → KILLED |
votingChartResponse.setYesCcMembers(voteCount.getOrDefault(Vote.YES, 0L)); |
966 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setNoCcMembers → KILLED |
votingChartResponse.setNoCcMembers(voteCount.getOrDefault(Vote.NO, 0L)); |
967 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setAbstainCcMembers → KILLED |
votingChartResponse.setAbstainCcMembers(voteCount.getOrDefault(Vote.ABSTAIN, 0L)); |
968 |
1
1. getVotingChartResponseForCCType : removed call to org/cardanofoundation/explorer/api/model/response/governanceAction/VotingChartResponse::setCcMembers → KILLED |
votingChartResponse.setCcMembers(activeMembers); |
969 | } | |
970 | ||
971 | private Double getParameterChangeActionThreshold(EpochParam epochParam, JsonNode description) { | |
972 | ObjectMapper objectMapper = new ObjectMapper(); | |
973 | JsonNode protocolParamUpdateJsonNode = description.get("protocolParamUpdate"); | |
974 | try { | |
975 | ProtocolParamUpdate protocolParamUpdate = | |
976 | objectMapper.treeToValue(protocolParamUpdateJsonNode, ProtocolParamUpdate.class); | |
977 | List<ProtocolParamGroup> protocolParamGroups = | |
978 | ProtocolParamUtil.getGroupsWithNonNullField(protocolParamUpdate); | |
979 | ||
980 | Set<Double> doubleSet = new HashSet<>(); | |
981 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
if (protocolParamGroups.contains(ProtocolParamGroup.ECONOMIC)) { |
982 | doubleSet.add( | |
983 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
Objects.isNull(epochParam.getDvtPPEconomicGroup()) |
984 | ? -1 | |
985 | : epochParam.getDvtPPEconomicGroup()); | |
986 | } | |
987 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
if (protocolParamGroups.contains(ProtocolParamGroup.NETWORK)) { |
988 | doubleSet.add( | |
989 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
Objects.isNull(epochParam.getDvtPPNetworkGroup()) |
990 | ? -1 | |
991 | : epochParam.getDvtPPNetworkGroup()); | |
992 | } | |
993 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
if (protocolParamGroups.contains(ProtocolParamGroup.TECHNICAL)) { |
994 | doubleSet.add( | |
995 |
1
1. getParameterChangeActionThreshold : negated conditional → SURVIVED |
Objects.isNull(epochParam.getDvtPPTechnicalGroup()) |
996 | ? -1 | |
997 | : epochParam.getDvtPPTechnicalGroup()); | |
998 | } | |
999 |
1
1. getParameterChangeActionThreshold : negated conditional → KILLED |
if (protocolParamGroups.contains(ProtocolParamGroup.GOVERNANCE)) { |
1000 | doubleSet.add( | |
1001 |
1
1. getParameterChangeActionThreshold : negated conditional → KILLED |
Objects.isNull(epochParam.getDvtPPGovGroup()) ? -1 : epochParam.getDvtPPGovGroup()); |
1002 | } | |
1003 |
1
1. getParameterChangeActionThreshold : negated conditional → KILLED |
if (doubleSet.isEmpty()) { |
1004 |
1
1. getParameterChangeActionThreshold : replaced Double return value with 0 for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getParameterChangeActionThreshold → NO_COVERAGE |
return null; |
1005 | } else { | |
1006 | Double threshold = doubleSet.stream().max(Double::compare).orElse(null); | |
1007 |
2
1. getParameterChangeActionThreshold : negated conditional → KILLED 2. getParameterChangeActionThreshold : replaced Double return value with 0 for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getParameterChangeActionThreshold → KILLED |
return threshold.equals(-1.0) ? null : threshold; |
1008 | } | |
1009 | } catch (JsonProcessingException e) { | |
1010 | log.error("Error while parsing protocolParamUpdate from description: {}", description); | |
1011 | } | |
1012 |
1
1. getParameterChangeActionThreshold : replaced Double return value with 0 for org/cardanofoundation/explorer/api/service/impl/GovernanceActionServiceImpl::getParameterChangeActionThreshold → NO_COVERAGE |
return null; |
1013 | } | |
1014 | } | |
Mutations | ||
109 |
1.1 |
|
117 |
1.1 |
|
120 |
1.1 |
|
123 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
136 |
1.1 |
|
143 |
1.1 |
|
175 |
1.1 |
|
180 |
1.1 |
|
181 |
1.1 |
|
184 |
1.1 2.2 |
|
186 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
196 |
1.1 |
|
201 |
1.1 |
|
202 |
1.1 |
|
204 |
1.1 |
|
205 |
1.1 |
|
206 |
1.1 |
|
207 |
1.1 |
|
210 |
1.1 |
|
214 |
1.1 |
|
215 |
1.1 |
|
219 |
1.1 |
|
224 |
1.1 |
|
231 |
1.1 |
|
232 |
1.1 |
|
235 |
1.1 |
|
236 |
1.1 |
|
242 |
1.1 |
|
243 |
1.1 |
|
250 |
1.1 |
|
258 |
1.1 |
|
268 |
1.1 |
|
275 |
1.1 |
|
279 |
1.1 |
|
280 |
1.1 |
|
284 |
1.1 |
|
288 |
1.1 |
|
289 |
1.1 |
|
290 |
1.1 |
|
297 |
1.1 |
|
298 |
1.1 |
|
300 |
1.1 |
|
302 |
1.1 |
|
307 |
1.1 |
|
310 |
1.1 |
|
314 |
1.1 |
|
324 |
1.1 |
|
326 |
1.1 |
|
327 |
1.1 |
|
328 |
1.1 |
|
334 |
1.1 |
|
335 |
1.1 |
|
336 |
1.1 |
|
346 |
1.1 2.2 |
|
352 |
1.1 2.2 |
|
360 |
1.1 |
|
361 |
1.1 |
|
365 |
1.1 2.2 |
|
375 |
1.1 |
|
384 |
1.1 |
|
385 |
1.1 2.2 |
|
394 |
1.1 |
|
396 |
1.1 |
|
398 |
1.1 |
|
400 |
1.1 |
|
402 |
1.1 |
|
404 |
1.1 |
|
406 |
1.1 |
|
415 |
1.1 |
|
421 |
1.1 |
|
424 |
1.1 |
|
427 |
1.1 |
|
433 |
1.1 |
|
448 |
1.1 |
|
477 |
1.1 |
|
497 |
1.1 |
|
498 |
1.1 |
|
504 |
1.1 |
|
505 |
1.1 |
|
507 |
1.1 |
|
510 |
1.1 |
|
512 |
1.1 |
|
513 |
1.1 |
|
514 |
1.1 |
|
523 |
1.1 |
|
524 |
1.1 |
|
531 |
1.1 2.2 |
|
532 |
1.1 |
|
538 |
1.1 |
|
539 |
1.1 |
|
541 |
1.1 |
|
545 |
1.1 |
|
549 |
1.1 |
|
554 |
1.1 |
|
555 |
1.1 |
|
558 |
1.1 |
|
566 |
1.1 |
|
567 |
1.1 |
|
568 |
1.1 |
|
569 |
1.1 |
|
570 |
1.1 |
|
572 |
1.1 |
|
580 |
1.1 |
|
588 |
1.1 |
|
591 |
1.1 |
|
594 |
1.1 |
|
601 |
1.1 |
|
603 |
1.1 |
|
606 |
1.1 |
|
625 |
1.1 |
|
627 |
1.1 |
|
635 |
1.1 2.2 |
|
638 |
1.1 |
|
648 |
1.1 |
|
650 |
1.1 |
|
658 |
1.1 |
|
661 |
1.1 |
|
664 |
1.1 |
|
669 |
1.1 |
|
670 |
1.1 |
|
673 |
1.1 |
|
674 |
1.1 |
|
697 |
1.1 |
|
709 |
1.1 |
|
712 |
1.1 |
|
713 |
1.1 |
|
718 |
1.1 |
|
723 |
1.1 |
|
726 |
1.1 |
|
745 |
1.1 2.2 |
|
746 |
1.1 |
|
747 |
1.1 |
|
761 |
1.1 |
|
779 |
1.1 |
|
785 |
1.1 |
|
786 |
1.1 |
|
787 |
1.1 |
|
788 |
1.1 |
|
794 |
1.1 |
|
796 |
1.1 |
|
802 |
1.1 |
|
803 |
1.1 |
|
806 |
1.1 |
|
810 |
1.1 |
|
816 |
1.1 |
|
817 |
1.1 |
|
821 |
1.1 |
|
822 |
1.1 |
|
833 |
1.1 |
|
836 |
1.1 |
|
837 |
1.1 |
|
842 |
1.1 |
|
845 |
1.1 |
|
848 |
1.1 |
|
852 |
1.1 |
|
857 |
1.1 |
|
860 |
1.1 |
|
883 |
1.1 2.2 |
|
884 |
1.1 |
|
885 |
1.1 |
|
899 |
1.1 |
|
920 |
1.1 |
|
925 |
1.1 |
|
927 |
1.1 |
|
928 |
1.1 |
|
929 |
1.1 |
|
930 |
1.1 |
|
941 |
1.1 |
|
942 |
1.1 |
|
948 |
1.1 |
|
965 |
1.1 |
|
966 |
1.1 |
|
967 |
1.1 |
|
968 |
1.1 |
|
981 |
1.1 |
|
983 |
1.1 |
|
987 |
1.1 |
|
989 |
1.1 |
|
993 |
1.1 |
|
995 |
1.1 |
|
999 |
1.1 |
|
1001 |
1.1 |
|
1003 |
1.1 |
|
1004 |
1.1 |
|
1007 |
1.1 2.2 |
|
1012 |
1.1 |