1 | package org.cardanofoundation.explorer.api.service.impl; | |
2 | ||
3 | import java.math.BigInteger; | |
4 | import java.sql.Timestamp; | |
5 | import java.util.ArrayList; | |
6 | import java.util.Date; | |
7 | import java.util.HashMap; | |
8 | import java.util.HashSet; | |
9 | import java.util.List; | |
10 | import java.util.Map; | |
11 | import java.util.Objects; | |
12 | import java.util.Set; | |
13 | import java.util.stream.Collectors; | |
14 | ||
15 | import lombok.RequiredArgsConstructor; | |
16 | import lombok.extern.log4j.Log4j2; | |
17 | ||
18 | import org.springframework.beans.factory.annotation.Value; | |
19 | import org.springframework.data.domain.Page; | |
20 | import org.springframework.data.domain.Pageable; | |
21 | import org.springframework.data.redis.core.RedisTemplate; | |
22 | import org.springframework.stereotype.Service; | |
23 | ||
24 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
25 | import org.cardanofoundation.explorer.api.common.enumeration.PoolActionType; | |
26 | import org.cardanofoundation.explorer.api.exception.BusinessCode; | |
27 | import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse; | |
28 | import org.cardanofoundation.explorer.api.model.response.pool.PoolCertificateHistory; | |
29 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.DeRegistrationResponse; | |
30 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.PoolInfoResponse; | |
31 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.PoolUpdateDetailResponse; | |
32 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.PoolUpdateResponse; | |
33 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.RegistrationResponse; | |
34 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.RewardResponse; | |
35 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.SPOStatusResponse; | |
36 | import org.cardanofoundation.explorer.api.model.response.pool.lifecycle.TabularRegisResponse; | |
37 | import org.cardanofoundation.explorer.api.model.response.pool.projection.EpochRewardProjection; | |
38 | import org.cardanofoundation.explorer.api.model.response.pool.projection.LifeCycleRewardProjection; | |
39 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolDeRegistrationProjection; | |
40 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolInfoProjection; | |
41 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolRegistrationProjection; | |
42 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolUpdateDetailProjection; | |
43 | import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolUpdateProjection; | |
44 | import org.cardanofoundation.explorer.api.model.response.pool.projection.StakeKeyProjection; | |
45 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository; | |
46 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolHashRepository; | |
47 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolInfoRepository; | |
48 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolRetireRepository; | |
49 | import org.cardanofoundation.explorer.api.repository.ledgersync.PoolUpdateRepository; | |
50 | import org.cardanofoundation.explorer.api.repository.ledgersync.RewardRepository; | |
51 | import org.cardanofoundation.explorer.api.repository.ledgersync.StakeAddressRepository; | |
52 | import org.cardanofoundation.explorer.api.service.FetchRewardDataService; | |
53 | import org.cardanofoundation.explorer.api.service.PoolCertificateService; | |
54 | import org.cardanofoundation.explorer.api.service.PoolLifecycleService; | |
55 | import org.cardanofoundation.explorer.common.entity.enumeration.RewardType; | |
56 | import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; | |
57 | import org.cardanofoundation.explorer.common.entity.ledgersync.PoolUpdate; | |
58 | import org.cardanofoundation.explorer.common.exception.BusinessException; | |
59 | ||
60 | @Service | |
61 | @RequiredArgsConstructor | |
62 | @Log4j2 | |
63 | public class PoolLifecycleServiceImpl implements PoolLifecycleService { | |
64 | ||
65 | private final StakeAddressRepository stakeAddressRepository; | |
66 | ||
67 | private final PoolHashRepository poolHashRepository; | |
68 | ||
69 | private final PoolUpdateRepository poolUpdateRepository; | |
70 | ||
71 | private final RewardRepository rewardRepository; | |
72 | ||
73 | private final PoolRetireRepository poolRetireRepository; | |
74 | ||
75 | private final EpochRepository epochRepository; | |
76 | ||
77 | private final FetchRewardDataService fetchRewardDataService; | |
78 | ||
79 | private final PoolInfoRepository poolInfoRepository; | |
80 | ||
81 | private final RedisTemplate<String, Object> redisTemplate; | |
82 | ||
83 | private final PoolCertificateService poolCertificateService; | |
84 | ||
85 | @Value("${application.network}") | |
86 | private String network; | |
87 | ||
88 | @Override | |
89 | public BaseFilterResponse<String> getPoolViewByStakeKey(String stakeKey, Pageable pageable) { | |
90 | BaseFilterResponse<String> res = new BaseFilterResponse<>(); | |
91 | Page<String> poolViews = stakeAddressRepository.getPoolViewByStakeKey(stakeKey, pageable); | |
92 |
1
1. getPoolViewByStakeKey : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
res.setData(poolViews.getContent()); |
93 |
1
1. getPoolViewByStakeKey : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(poolViews.getTotalElements()); |
94 |
1
1. getPoolViewByStakeKey : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::getPoolViewByStakeKey → KILLED |
return res; |
95 | } | |
96 | ||
97 | @Override | |
98 | public BaseFilterResponse<PoolUpdateResponse> registration( | |
99 | String poolViewOrHash, String txHash, Date fromDate, Date toDate, Pageable pageable) { | |
100 |
1
1. registration : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::registration → KILLED |
return getDataForPoolUpdate(poolViewOrHash, txHash, fromDate, toDate, pageable, 0); |
101 | } | |
102 | ||
103 | @Override | |
104 | public RegistrationResponse registrationDetail(String poolView, Long id) { | |
105 | RegistrationResponse res = new RegistrationResponse(); | |
106 | PoolInfoProjection poolInfo = poolHashRepository.getPoolInfo(poolView); | |
107 | PoolRegistrationProjection projection = poolHashRepository.getPoolRegistration(id); | |
108 |
1
1. registrationDetail : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
109 | res = new RegistrationResponse(projection); | |
110 | } | |
111 |
1
1. registrationDetail : negated conditional → KILLED |
if (Objects.nonNull(poolInfo)) { |
112 |
1
1. registrationDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/RegistrationResponse::setPoolId → KILLED |
res.setPoolId(poolInfo.getPoolId()); |
113 |
1
1. registrationDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/RegistrationResponse::setPoolName → KILLED |
res.setPoolName(poolInfo.getPoolName()); |
114 |
1
1. registrationDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/RegistrationResponse::setPoolView → KILLED |
res.setPoolView(poolInfo.getPoolView()); |
115 | } | |
116 |
1
1. registrationDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/RegistrationResponse::setStakeKeys → KILLED |
res.setStakeKeys(poolUpdateRepository.findOwnerAccountByPoolUpdate(id)); |
117 |
1
1. registrationDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::registrationDetail → KILLED |
return res; |
118 | } | |
119 | ||
120 | @Override | |
121 | public BaseFilterResponse<PoolUpdateResponse> poolUpdate( | |
122 | String poolView, String txHash, Date fromDate, Date toDate, Pageable pageable) { | |
123 |
1
1. poolUpdate : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::poolUpdate → KILLED |
return getDataForPoolUpdate(poolView, txHash, fromDate, toDate, pageable, 1); |
124 | } | |
125 | ||
126 | @Override | |
127 | public PoolUpdateDetailResponse poolUpdateDetail(Long id) { | |
128 | PoolUpdateDetailResponse res = null; | |
129 | PoolUpdateDetailProjection projection = poolUpdateRepository.findPoolUpdateDetailById(id); | |
130 |
1
1. poolUpdateDetail : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
131 | res = new PoolUpdateDetailResponse(projection); | |
132 |
1
1. poolUpdateDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setStakeKeys → SURVIVED |
res.setStakeKeys(poolUpdateRepository.findOwnerAccountByPoolUpdate(id)); |
133 | PoolUpdate poolUpdatePrevious = | |
134 | poolUpdateRepository.findTopByIdLessThanAndPoolHashIdOrderByIdDesc( | |
135 | id, projection.getHashId()); | |
136 |
1
1. poolUpdateDetail : negated conditional → KILLED |
if (Objects.nonNull(poolUpdatePrevious)) { |
137 |
1
1. poolUpdateDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setPreviousPledge → KILLED |
res.setPreviousPledge(poolUpdatePrevious.getPledge()); |
138 |
1
1. poolUpdateDetail : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setPreviousMargin → KILLED |
res.setPreviousMargin(poolUpdatePrevious.getMargin()); |
139 | } | |
140 | } | |
141 |
1
1. poolUpdateDetail : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::poolUpdateDetail → KILLED |
return res; |
142 | } | |
143 | ||
144 | @Override | |
145 | public BaseFilterResponse<RewardResponse> listReward(String poolViewOrHash, Pageable pageable) { | |
146 | BaseFilterResponse<RewardResponse> res = new BaseFilterResponse<>(); | |
147 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
148 |
1
1. listReward : negated conditional → KILLED |
if (!useKoiOs) { |
149 |
1
1. listReward : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
res.setData(null); |
150 |
1
1. listReward : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listReward → KILLED |
return res; |
151 | } | |
152 | List<String> rewardAccounts = poolUpdateRepository.findRewardAccountByPoolView(poolViewOrHash); | |
153 |
1
1. listReward : negated conditional → KILLED |
if (Boolean.FALSE.equals(fetchRewardDataService.checkRewardForPool(rewardAccounts)) |
154 |
1
1. listReward : negated conditional → KILLED |
&& Boolean.FALSE.equals(fetchRewardDataService.fetchRewardForPool(rewardAccounts))) { |
155 |
1
1. listReward : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listReward → KILLED |
return res; |
156 | } | |
157 | List<RewardResponse> rewardRes = new ArrayList<>(); | |
158 | Page<LifeCycleRewardProjection> projections = | |
159 | rewardRepository.getRewardInfoByPool(poolViewOrHash, pageable); | |
160 |
1
1. listReward : negated conditional → KILLED |
if (Objects.nonNull(projections)) { |
161 | projections.stream() | |
162 |
1
1. listReward : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
163 | projection -> { | |
164 | RewardResponse reward = new RewardResponse(projection); | |
165 | rewardRes.add(reward); | |
166 | }); | |
167 |
1
1. listReward : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(projections.getTotalElements()); |
168 | } | |
169 |
1
1. listReward : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
res.setData(rewardRes); |
170 |
1
1. listReward : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listReward → KILLED |
return res; |
171 | } | |
172 | ||
173 | @Override | |
174 | public PoolInfoResponse poolInfo(String poolView) { | |
175 | PoolInfoResponse res = new PoolInfoResponse(); | |
176 | PoolInfoProjection projection = poolHashRepository.getPoolInfo(poolView); | |
177 | Long poolId = 0L; | |
178 |
1
1. poolInfo : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
179 | poolId = projection.getId(); | |
180 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setPoolId → KILLED |
res.setPoolId(projection.getPoolId()); |
181 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setPoolName → KILLED |
res.setPoolName(projection.getPoolName()); |
182 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setPoolView → SURVIVED |
res.setPoolView(projection.getPoolView()); |
183 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setRewardAccounts → KILLED |
res.setRewardAccounts(poolUpdateRepository.findRewardAccountByPoolId(projection.getId())); |
184 | Integer epochNo = epochRepository.findCurrentEpochNo().orElse(null); | |
185 |
1
1. poolInfo : negated conditional → KILLED |
if (Boolean.TRUE.equals(fetchRewardDataService.useKoios())) { |
186 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setPoolSize → SURVIVED |
res.setPoolSize( |
187 | poolInfoRepository.getActiveStakeByPoolAndEpoch(projection.getPoolView(), epochNo)); | |
188 | Boolean isReward = fetchRewardDataService.checkRewardForPool(res.getRewardAccounts()); | |
189 |
1
1. poolInfo : negated conditional → KILLED |
if (Boolean.FALSE.equals(isReward)) { |
190 | fetchRewardDataService.fetchRewardForPool(res.getRewardAccounts()); | |
191 | } | |
192 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setRewardAvailable → SURVIVED |
res.setRewardAvailable(rewardRepository.getTotalRewardByPool(poolView)); |
193 | } | |
194 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setStakeKeys → SURVIVED |
res.setStakeKeys(poolUpdateRepository.findOwnerAccountByPoolView(poolView)); |
195 | } | |
196 | String status = getPoolStatusFromCacheByPoolId(poolId); | |
197 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setStatus → SURVIVED |
res.setStatus(status); |
198 |
1
1. poolInfo : negated conditional → KILLED |
if (CommonConstant.POOL_STATUS_ACTIVE.equals(status)) { |
199 |
1
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setEpochNo → SURVIVED |
res.setEpochNo(epochRepository.findCurrentEpochNo().orElse(0)); |
200 | } else { | |
201 | List<Integer> retireEpochs = poolRetireRepository.findByPoolView(poolView); | |
202 |
2
1. poolInfo : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolInfoResponse::setEpochNo → NO_COVERAGE 2. poolInfo : negated conditional → NO_COVERAGE |
res.setEpochNo(retireEpochs.isEmpty() ? CommonConstant.ZERO : retireEpochs.get(0)); |
203 | } | |
204 |
1
1. poolInfo : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::poolInfo → KILLED |
return res; |
205 | } | |
206 | ||
207 | @Override | |
208 | public BaseFilterResponse<DeRegistrationResponse> deRegistration( | |
209 | String poolView, String txHash, Date fromDate, Date toDate, Pageable pageable) { | |
210 | BaseFilterResponse<DeRegistrationResponse> res = new BaseFilterResponse<>(); | |
211 | PoolInfoProjection poolInfo = poolHashRepository.getPoolInfo(poolView); | |
212 | Timestamp fromTimestamp = null; | |
213 | Timestamp toTimestamp = null; | |
214 |
1
1. deRegistration : negated conditional → KILLED |
if (Objects.nonNull(fromDate)) { |
215 | fromTimestamp = new Timestamp(fromDate.getTime()); | |
216 | } | |
217 |
1
1. deRegistration : negated conditional → KILLED |
if (Objects.nonNull(toDate)) { |
218 | toTimestamp = new Timestamp(toDate.getTime()); | |
219 | } | |
220 |
2
1. deRegistration : negated conditional → NO_COVERAGE 2. deRegistration : negated conditional → KILLED |
if (Objects.nonNull(txHash) && txHash.isBlank()) { |
221 | txHash = null; | |
222 | } | |
223 | List<PoolCertificateHistory> poolRetire = | |
224 | poolCertificateService.getPoolCertificateByAction( | |
225 | poolView, PoolActionType.POOL_DEREGISTRATION); | |
226 | Page<PoolDeRegistrationProjection> projections = | |
227 | poolRetireRepository.getPoolDeRegistration( | |
228 |
1
1. deRegistration : negated conditional → KILLED |
poolRetire.isEmpty() |
229 | ? Set.of(-1L) | |
230 | : poolRetire.stream() | |
231 | .map(PoolCertificateHistory::getPoolRetireId) | |
232 | .collect(Collectors.toSet()), | |
233 | txHash, | |
234 | fromTimestamp, | |
235 | toTimestamp, | |
236 | pageable); | |
237 | List<DeRegistrationResponse> deRegistrations = new ArrayList<>(); | |
238 |
1
1. deRegistration : negated conditional → KILLED |
if (Objects.nonNull(projections)) { |
239 | Set<Integer> epochNos = new HashSet<>(); | |
240 | projections.stream() | |
241 |
1
1. deRegistration : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
242 | projection -> { | |
243 | DeRegistrationResponse deRegistrationRes = new DeRegistrationResponse(projection); | |
244 | deRegistrations.add(deRegistrationRes); | |
245 | epochNos.add(projection.getRetiringEpoch()); | |
246 | }); | |
247 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
248 | Map<Integer, BigInteger> refundAmountMap = new HashMap<>(); | |
249 |
1
1. deRegistration : negated conditional → KILLED |
if (useKoiOs) { |
250 | List<String> rewardAccounts = | |
251 | poolUpdateRepository.findRewardAccountByPoolId(poolInfo.getId()); | |
252 | boolean isReward = fetchRewardDataService.checkRewardForPool(rewardAccounts); | |
253 |
1
1. deRegistration : negated conditional → KILLED |
if (!isReward) { |
254 | fetchRewardDataService.fetchRewardForPool(rewardAccounts); | |
255 | } | |
256 | List<EpochRewardProjection> epochRewardProjections = | |
257 | rewardRepository.getRewardRefundByEpoch(poolView, epochNos); | |
258 |
1
1. deRegistration : removed call to java/util/List::forEach → KILLED |
epochRewardProjections.forEach( |
259 | refund -> refundAmountMap.put(refund.getEpochNo(), refund.getAmount())); | |
260 | } | |
261 | List<String> stakeKeys = poolUpdateRepository.findOwnerAccountByPoolView(poolView); | |
262 |
1
1. deRegistration : removed call to java/util/List::forEach → KILLED |
deRegistrations.forEach( |
263 | deRegistration -> { | |
264 |
1
1. lambda$deRegistration$3 : negated conditional → SURVIVED |
if (deRegistration.isRefundFlag()) { |
265 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setPoolHold → NO_COVERAGE |
deRegistration.setPoolHold(refundAmountMap.get(deRegistration.getRetiringEpoch())); |
266 | } | |
267 | BigInteger totalFee = BigInteger.ZERO; | |
268 |
1
1. lambda$deRegistration$3 : negated conditional → KILLED |
if (Objects.nonNull(deRegistration.getPoolHold())) { |
269 | totalFee = totalFee.add(deRegistration.getPoolHold()); | |
270 | } | |
271 |
1
1. lambda$deRegistration$3 : negated conditional → SURVIVED |
if (Objects.nonNull(deRegistration.getFee())) { |
272 | totalFee = totalFee.add(deRegistration.getFee()); | |
273 | } | |
274 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setTotalFee → SURVIVED |
deRegistration.setTotalFee(totalFee); |
275 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setPoolId → SURVIVED |
deRegistration.setPoolId(poolInfo.getPoolId()); |
276 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setPoolName → SURVIVED |
deRegistration.setPoolName(poolInfo.getPoolName()); |
277 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setPoolView → SURVIVED |
deRegistration.setPoolView(poolInfo.getPoolView()); |
278 |
1
1. lambda$deRegistration$3 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/DeRegistrationResponse::setStakeKeys → SURVIVED |
deRegistration.setStakeKeys(stakeKeys); |
279 | }); | |
280 |
1
1. deRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(projections.getTotalElements()); |
281 |
1
1. deRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setCurrentPage → SURVIVED |
res.setCurrentPage(projections.getNumber()); |
282 |
1
1. deRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalPages → SURVIVED |
res.setTotalPages(projections.getTotalPages()); |
283 | } | |
284 |
1
1. deRegistration : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
res.setData(deRegistrations); |
285 |
1
1. deRegistration : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::deRegistration → KILLED |
return res; |
286 | } | |
287 | ||
288 | @Override | |
289 | public BaseFilterResponse<TabularRegisResponse> registrationList( | |
290 | String poolViewOrHash, Pageable pageable) { | |
291 | BaseFilterResponse<TabularRegisResponse> res = new BaseFilterResponse<>(); | |
292 | List<TabularRegisResponse> tabularRegisList = new ArrayList<>(); | |
293 | List<PoolCertificateHistory> poolRegistration = | |
294 | poolCertificateService.getPoolCertificateByAction( | |
295 | poolViewOrHash, PoolActionType.POOL_REGISTRATION); | |
296 | Page<PoolRegistrationProjection> projection = | |
297 | poolHashRepository.getPoolRegistrationByPool( | |
298 |
1
1. registrationList : negated conditional → KILLED |
poolRegistration.isEmpty() |
299 | ? Set.of(-1L) | |
300 | : poolRegistration.stream() | |
301 | .map(PoolCertificateHistory::getPoolUpdateId) | |
302 | .collect(Collectors.toSet()), | |
303 | pageable); | |
304 |
1
1. registrationList : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
305 | Set<Long> poolUpdateIds = new HashSet<>(); | |
306 | projection.stream() | |
307 |
1
1. registrationList : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
308 | tabularRegis -> { | |
309 | tabularRegisList.add(new TabularRegisResponse(tabularRegis)); | |
310 | poolUpdateIds.add(tabularRegis.getPoolUpdateId()); | |
311 | }); | |
312 | List<StakeKeyProjection> stakeKeyProjections = | |
313 | poolUpdateRepository.findOwnerAccountByPoolUpdate(poolUpdateIds); | |
314 | Map<Long, List<StakeKeyProjection>> stakeKeyProjectionMap = | |
315 | stakeKeyProjections.stream() | |
316 | .collect(Collectors.groupingBy(StakeKeyProjection::getPoolUpdateId)); | |
317 | Map<Long, List<String>> stakeKeyStrMap = new HashMap<>(); | |
318 |
1
1. registrationList : removed call to java/util/Map::forEach → KILLED |
stakeKeyProjectionMap.forEach( |
319 | (k, v) -> stakeKeyStrMap.put(k, v.stream().map(StakeKeyProjection::getView).toList())); | |
320 |
1
1. registrationList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(projection.getTotalElements()); |
321 |
1
1. registrationList : removed call to java/util/List::forEach → SURVIVED |
tabularRegisList.forEach( |
322 | tabularRegis -> | |
323 |
1
1. lambda$registrationList$6 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/TabularRegisResponse::setStakeKeys → SURVIVED |
tabularRegis.setStakeKeys(stakeKeyStrMap.get(tabularRegis.getPoolUpdateId()))); |
324 | } | |
325 |
1
1. registrationList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
res.setData(tabularRegisList); |
326 |
1
1. registrationList : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::registrationList → KILLED |
return res; |
327 | } | |
328 | ||
329 | @Override | |
330 | public BaseFilterResponse<PoolUpdateDetailResponse> poolUpdateList( | |
331 | String poolViewOrHash, Pageable pageable) { | |
332 | BaseFilterResponse<PoolUpdateDetailResponse> res = new BaseFilterResponse<>(); | |
333 | List<PoolUpdateDetailResponse> poolUpdateList = new ArrayList<>(); | |
334 | List<PoolCertificateHistory> poolUpdateCert = | |
335 | poolCertificateService.getPoolCertificateByAction( | |
336 | poolViewOrHash, PoolActionType.POOL_UPDATE); | |
337 | Page<PoolUpdateDetailProjection> projection = | |
338 | poolUpdateRepository.findPoolUpdateByPool( | |
339 |
1
1. poolUpdateList : negated conditional → KILLED |
poolUpdateCert.isEmpty() |
340 | ? Set.of(-1L) | |
341 | : poolUpdateCert.stream() | |
342 | .map(PoolCertificateHistory::getPoolUpdateId) | |
343 | .collect(Collectors.toSet()), | |
344 | pageable); | |
345 |
1
1. poolUpdateList : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
346 | projection.stream() | |
347 |
1
1. poolUpdateList : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
348 | poolUpdate -> { | |
349 | PoolUpdateDetailResponse poolUpdateRes = new PoolUpdateDetailResponse(poolUpdate); | |
350 |
1
1. lambda$poolUpdateList$7 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setStakeKeys → SURVIVED |
poolUpdateRes.setStakeKeys( |
351 | poolUpdateRepository.findOwnerAccountByPoolUpdate( | |
352 | poolUpdate.getPoolUpdateId())); | |
353 | PoolUpdate poolUpdatePrevious = | |
354 | poolUpdateRepository.findTopByIdLessThanAndPoolHashIdOrderByIdDesc( | |
355 | poolUpdate.getPoolUpdateId(), poolUpdate.getHashId()); | |
356 |
1
1. lambda$poolUpdateList$7 : negated conditional → KILLED |
if (Objects.nonNull(poolUpdatePrevious)) { |
357 |
1
1. lambda$poolUpdateList$7 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setPreviousPledge → SURVIVED |
poolUpdateRes.setPreviousPledge(poolUpdatePrevious.getPledge()); |
358 |
1
1. lambda$poolUpdateList$7 : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/PoolUpdateDetailResponse::setPreviousMargin → SURVIVED |
poolUpdateRes.setPreviousMargin(poolUpdatePrevious.getMargin()); |
359 | } | |
360 | poolUpdateList.add(poolUpdateRes); | |
361 |
1
1. lambda$poolUpdateList$7 : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(projection.getTotalElements()); |
362 | }); | |
363 | } | |
364 |
1
1. poolUpdateList : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → KILLED |
res.setData(poolUpdateList); |
365 |
1
1. poolUpdateList : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::poolUpdateList → KILLED |
return res; |
366 | } | |
367 | ||
368 | @Override | |
369 | public SPOStatusResponse poolLifecycleStatus(String poolViewOrHash) { | |
370 | SPOStatusResponse response = new SPOStatusResponse(); | |
371 | Integer countPoolUpdate = poolUpdateRepository.countPoolUpdateByPool(poolViewOrHash); | |
372 |
2
1. poolLifecycleStatus : negated conditional → KILLED 2. poolLifecycleStatus : negated conditional → KILLED |
if (Objects.isNull(countPoolUpdate) || countPoolUpdate == 0) { |
373 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsRegistration → SURVIVED |
response.setIsRegistration(false); |
374 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsUpdate → SURVIVED |
response.setIsUpdate(false); |
375 |
1
1. poolLifecycleStatus : negated conditional → KILLED |
} else if (countPoolUpdate == 1) { |
376 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsRegistration → SURVIVED |
response.setIsRegistration(true); |
377 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsUpdate → KILLED |
response.setIsUpdate(false); |
378 | } else { | |
379 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsRegistration → KILLED |
response.setIsRegistration(true); |
380 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsUpdate → SURVIVED |
response.setIsUpdate(true); |
381 | } | |
382 | PoolHash pool = | |
383 | poolHashRepository | |
384 | .findByViewOrHashRaw(poolViewOrHash) | |
385 |
1
1. lambda$poolLifecycleStatus$8 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::lambda$poolLifecycleStatus$8 → KILLED |
.orElseThrow(() -> new BusinessException(BusinessCode.POOL_NOT_FOUND)); |
386 | String poolView = pool.getView(); | |
387 |
1
1. poolLifecycleStatus : negated conditional → KILLED |
if (fetchRewardDataService.useKoios()) { |
388 | List<String> rewardAccounts = poolUpdateRepository.findRewardAccountByPoolView(poolView); | |
389 |
1
1. poolLifecycleStatus : negated conditional → SURVIVED |
if (!fetchRewardDataService.checkRewardForPool(rewardAccounts)) { |
390 | fetchRewardDataService.fetchRewardForPool(rewardAccounts); | |
391 | } | |
392 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsReward → KILLED |
response.setIsReward(rewardRepository.existsByPoolAndType(pool, RewardType.LEADER)); |
393 | } | |
394 |
1
1. poolLifecycleStatus : removed call to org/cardanofoundation/explorer/api/model/response/pool/lifecycle/SPOStatusResponse::setIsDeRegistration → KILLED |
response.setIsDeRegistration(poolRetireRepository.existsByPoolHash(pool)); |
395 |
1
1. poolLifecycleStatus : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::poolLifecycleStatus → KILLED |
return response; |
396 | } | |
397 | ||
398 | @Override | |
399 | public BaseFilterResponse<RewardResponse> listRewardFilter( | |
400 | String poolViewOrHash, Integer beginEpoch, Integer endEpoch, Pageable pageable) { | |
401 | BaseFilterResponse<RewardResponse> res = new BaseFilterResponse<>(); | |
402 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
403 |
1
1. listRewardFilter : negated conditional → NO_COVERAGE |
if (!useKoiOs) { |
404 |
1
1. listRewardFilter : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → NO_COVERAGE |
res.setData(null); |
405 |
1
1. listRewardFilter : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listRewardFilter → NO_COVERAGE |
return res; |
406 | } | |
407 | List<String> rewardAccounts = poolUpdateRepository.findRewardAccountByPoolView(poolViewOrHash); | |
408 |
1
1. listRewardFilter : negated conditional → NO_COVERAGE |
if (Boolean.FALSE.equals(fetchRewardDataService.checkRewardForPool(rewardAccounts)) |
409 |
1
1. listRewardFilter : negated conditional → NO_COVERAGE |
&& Boolean.FALSE.equals(fetchRewardDataService.fetchRewardForPool(rewardAccounts))) { |
410 |
1
1. listRewardFilter : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listRewardFilter → NO_COVERAGE |
return res; |
411 | } | |
412 | List<RewardResponse> rewardRes = new ArrayList<>(); | |
413 | Page<LifeCycleRewardProjection> projections = | |
414 | rewardRepository.getRewardInfoByPoolFiler(poolViewOrHash, beginEpoch, endEpoch, pageable); | |
415 |
1
1. listRewardFilter : negated conditional → NO_COVERAGE |
if (Objects.nonNull(projections)) { |
416 | projections.stream() | |
417 |
1
1. listRewardFilter : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
.forEach( |
418 | projection -> { | |
419 | RewardResponse reward = new RewardResponse(projection); | |
420 | rewardRes.add(reward); | |
421 | }); | |
422 |
1
1. listRewardFilter : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → NO_COVERAGE |
res.setTotalItems(projections.getTotalElements()); |
423 | } | |
424 |
1
1. listRewardFilter : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → NO_COVERAGE |
res.setData(rewardRes); |
425 |
1
1. listRewardFilter : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::listRewardFilter → NO_COVERAGE |
return res; |
426 | } | |
427 | ||
428 | private BaseFilterResponse<PoolUpdateResponse> getDataForPoolUpdate( | |
429 | String poolViewOrHash, | |
430 | String txHash, | |
431 | Date fromDate, | |
432 | Date toDate, | |
433 | Pageable pageable, | |
434 | Integer type) { | |
435 | BaseFilterResponse<PoolUpdateResponse> res = new BaseFilterResponse<>(); | |
436 | Timestamp fromTimestamp = null; | |
437 | Timestamp toTimestamp = null; | |
438 |
1
1. getDataForPoolUpdate : negated conditional → KILLED |
if (Objects.nonNull(fromDate)) { |
439 | fromTimestamp = new Timestamp(fromDate.getTime()); | |
440 | } | |
441 |
1
1. getDataForPoolUpdate : negated conditional → KILLED |
if (Objects.nonNull(toDate)) { |
442 | toTimestamp = new Timestamp(toDate.getTime()); | |
443 | } | |
444 |
2
1. getDataForPoolUpdate : negated conditional → KILLED 2. getDataForPoolUpdate : negated conditional → KILLED |
if (Objects.nonNull(txHash) && txHash.isBlank()) { |
445 | txHash = null; | |
446 | } | |
447 | Page<PoolUpdateProjection> projection; | |
448 |
1
1. getDataForPoolUpdate : negated conditional → SURVIVED |
if (type == 0) { |
449 | List<PoolCertificateHistory> poolRegistration = | |
450 | poolCertificateService.getPoolCertificateByAction( | |
451 | poolViewOrHash, PoolActionType.POOL_REGISTRATION); | |
452 | projection = | |
453 | poolUpdateRepository.findPoolRegistrationByPool( | |
454 |
1
1. getDataForPoolUpdate : negated conditional → KILLED |
poolRegistration.isEmpty() |
455 | ? Set.of(-1L) | |
456 | : poolRegistration.stream() | |
457 | .map(PoolCertificateHistory::getPoolUpdateId) | |
458 | .collect(Collectors.toSet()), | |
459 | txHash, | |
460 | fromTimestamp, | |
461 | toTimestamp, | |
462 | pageable); | |
463 | } else { | |
464 | List<PoolCertificateHistory> poolUpdate = | |
465 | poolCertificateService.getPoolCertificateByAction( | |
466 | poolViewOrHash, PoolActionType.POOL_UPDATE); | |
467 | projection = | |
468 | poolUpdateRepository.findPoolUpdateByPool( | |
469 |
1
1. getDataForPoolUpdate : negated conditional → KILLED |
poolUpdate.isEmpty() |
470 | ? Set.of(-1L) | |
471 | : poolUpdate.stream() | |
472 | .map(PoolCertificateHistory::getPoolUpdateId) | |
473 | .collect(Collectors.toSet()), | |
474 | txHash, | |
475 | fromTimestamp, | |
476 | toTimestamp, | |
477 | pageable); | |
478 | } | |
479 | List<PoolUpdateResponse> poolUpdateResList = new ArrayList<>(); | |
480 |
1
1. getDataForPoolUpdate : negated conditional → KILLED |
if (Objects.nonNull(projection)) { |
481 | projection.stream() | |
482 |
1
1. getDataForPoolUpdate : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
483 | poolUpdate -> { | |
484 | PoolUpdateResponse poolUpdateRes = new PoolUpdateResponse(poolUpdate); | |
485 | poolUpdateResList.add(poolUpdateRes); | |
486 | }); | |
487 |
1
1. getDataForPoolUpdate : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setTotalItems → KILLED |
res.setTotalItems(projection.getTotalElements()); |
488 | } | |
489 |
1
1. getDataForPoolUpdate : removed call to org/cardanofoundation/explorer/api/model/response/BaseFilterResponse::setData → SURVIVED |
res.setData(poolUpdateResList); |
490 |
1
1. getDataForPoolUpdate : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::getDataForPoolUpdate → KILLED |
return res; |
491 | } | |
492 | ||
493 | private String getPoolStatusFromCacheByPoolId(Long poolId) { | |
494 | String key = CommonConstant.POOL_IDS_INACTIVATE + network; | |
495 | Object obj = null; | |
496 | try { | |
497 | List<Object> objList = redisTemplate.opsForHash().multiGet(key, List.of(poolId)); | |
498 | obj = objList.get(0); | |
499 | } catch (Exception e) { | |
500 | log.error("Error: " + e.getMessage()); | |
501 | } | |
502 |
1
1. getPoolStatusFromCacheByPoolId : negated conditional → KILLED |
if (Objects.isNull(obj)) { |
503 |
1
1. getPoolStatusFromCacheByPoolId : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::getPoolStatusFromCacheByPoolId → KILLED |
return CommonConstant.POOL_STATUS_ACTIVE; |
504 | } | |
505 |
1
1. getPoolStatusFromCacheByPoolId : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/PoolLifecycleServiceImpl::getPoolStatusFromCacheByPoolId → NO_COVERAGE |
return CommonConstant.POOL_STATUS_RETIRED; |
506 | } | |
507 | } | |
Mutations | ||
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
100 |
1.1 |
|
108 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
123 |
1.1 |
|
130 |
1.1 |
|
132 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
138 |
1.1 |
|
141 |
1.1 |
|
148 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
160 |
1.1 |
|
162 |
1.1 |
|
167 |
1.1 |
|
169 |
1.1 |
|
170 |
1.1 |
|
178 |
1.1 |
|
180 |
1.1 |
|
181 |
1.1 |
|
182 |
1.1 |
|
183 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
189 |
1.1 |
|
192 |
1.1 |
|
194 |
1.1 |
|
197 |
1.1 |
|
198 |
1.1 |
|
199 |
1.1 |
|
202 |
1.1 2.2 |
|
204 |
1.1 |
|
214 |
1.1 |
|
217 |
1.1 |
|
220 |
1.1 2.2 |
|
228 |
1.1 |
|
238 |
1.1 |
|
241 |
1.1 |
|
249 |
1.1 |
|
253 |
1.1 |
|
258 |
1.1 |
|
262 |
1.1 |
|
264 |
1.1 |
|
265 |
1.1 |
|
268 |
1.1 |
|
271 |
1.1 |
|
274 |
1.1 |
|
275 |
1.1 |
|
276 |
1.1 |
|
277 |
1.1 |
|
278 |
1.1 |
|
280 |
1.1 |
|
281 |
1.1 |
|
282 |
1.1 |
|
284 |
1.1 |
|
285 |
1.1 |
|
298 |
1.1 |
|
304 |
1.1 |
|
307 |
1.1 |
|
318 |
1.1 |
|
320 |
1.1 |
|
321 |
1.1 |
|
323 |
1.1 |
|
325 |
1.1 |
|
326 |
1.1 |
|
339 |
1.1 |
|
345 |
1.1 |
|
347 |
1.1 |
|
350 |
1.1 |
|
356 |
1.1 |
|
357 |
1.1 |
|
358 |
1.1 |
|
361 |
1.1 |
|
364 |
1.1 |
|
365 |
1.1 |
|
372 |
1.1 2.2 |
|
373 |
1.1 |
|
374 |
1.1 |
|
375 |
1.1 |
|
376 |
1.1 |
|
377 |
1.1 |
|
379 |
1.1 |
|
380 |
1.1 |
|
385 |
1.1 |
|
387 |
1.1 |
|
389 |
1.1 |
|
392 |
1.1 |
|
394 |
1.1 |
|
395 |
1.1 |
|
403 |
1.1 |
|
404 |
1.1 |
|
405 |
1.1 |
|
408 |
1.1 |
|
409 |
1.1 |
|
410 |
1.1 |
|
415 |
1.1 |
|
417 |
1.1 |
|
422 |
1.1 |
|
424 |
1.1 |
|
425 |
1.1 |
|
438 |
1.1 |
|
441 |
1.1 |
|
444 |
1.1 2.2 |
|
448 |
1.1 |
|
454 |
1.1 |
|
469 |
1.1 |
|
480 |
1.1 |
|
482 |
1.1 |
|
487 |
1.1 |
|
489 |
1.1 |
|
490 |
1.1 |
|
502 |
1.1 |
|
503 |
1.1 |
|
505 |
1.1 |