1 | package org.cardanofoundation.explorer.api.service.impl; | |
2 | ||
3 | import static org.cardanofoundation.explorer.api.common.constant.CommonConstant.isWithinRange; | |
4 | ||
5 | import java.lang.reflect.Field; | |
6 | import java.lang.reflect.InvocationTargetException; | |
7 | import java.lang.reflect.Method; | |
8 | import java.math.BigInteger; | |
9 | import java.sql.Timestamp; | |
10 | import java.text.SimpleDateFormat; | |
11 | import java.time.Duration; | |
12 | import java.time.LocalDateTime; | |
13 | import java.time.ZoneOffset; | |
14 | import java.time.temporal.ChronoUnit; | |
15 | import java.util.ArrayList; | |
16 | import java.util.Arrays; | |
17 | import java.util.Collections; | |
18 | import java.util.Comparator; | |
19 | import java.util.Date; | |
20 | import java.util.EnumMap; | |
21 | import java.util.HashMap; | |
22 | import java.util.List; | |
23 | import java.util.Map; | |
24 | import java.util.Map.Entry; | |
25 | import java.util.Objects; | |
26 | import java.util.Optional; | |
27 | import java.util.TimeZone; | |
28 | import java.util.concurrent.atomic.AtomicReference; | |
29 | import java.util.function.Function; | |
30 | import java.util.stream.Collectors; | |
31 | import java.util.stream.IntStream; | |
32 | ||
33 | import jakarta.annotation.PostConstruct; | |
34 | ||
35 | import lombok.AccessLevel; | |
36 | import lombok.RequiredArgsConstructor; | |
37 | import lombok.experimental.FieldDefaults; | |
38 | import lombok.extern.log4j.Log4j2; | |
39 | ||
40 | import org.springframework.beans.factory.annotation.Value; | |
41 | import org.springframework.data.redis.core.RedisTemplate; | |
42 | import org.springframework.data.util.Pair; | |
43 | import org.springframework.stereotype.Service; | |
44 | import org.springframework.transaction.annotation.Transactional; | |
45 | import org.springframework.util.ObjectUtils; | |
46 | ||
47 | import com.fasterxml.jackson.databind.JsonNode; | |
48 | import com.fasterxml.jackson.databind.ObjectMapper; | |
49 | import com.google.gson.JsonElement; | |
50 | import com.google.gson.JsonObject; | |
51 | import com.google.gson.JsonParser; | |
52 | ||
53 | import org.cardanofoundation.explorer.api.common.enumeration.ProtocolStatus; | |
54 | import org.cardanofoundation.explorer.api.common.enumeration.ProtocolType; | |
55 | import org.cardanofoundation.explorer.api.exception.BusinessCode; | |
56 | import org.cardanofoundation.explorer.api.mapper.ProtocolMapper; | |
57 | import org.cardanofoundation.explorer.api.model.response.protocol.EpochChange; | |
58 | import org.cardanofoundation.explorer.api.model.response.protocol.FixedProtocol; | |
59 | import org.cardanofoundation.explorer.api.model.response.protocol.HistoriesProtocol; | |
60 | import org.cardanofoundation.explorer.api.model.response.protocol.ProtocolHistory; | |
61 | import org.cardanofoundation.explorer.api.model.response.protocol.Protocols; | |
62 | import org.cardanofoundation.explorer.api.projection.EpochTimeProjection; | |
63 | import org.cardanofoundation.explorer.api.projection.LatestParamHistory; | |
64 | import org.cardanofoundation.explorer.api.projection.ParamHistory; | |
65 | import org.cardanofoundation.explorer.api.repository.ledgersync.CostModelRepository; | |
66 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochParamRepository; | |
67 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository; | |
68 | import org.cardanofoundation.explorer.api.repository.ledgersync.ParamProposalRepository; | |
69 | import org.cardanofoundation.explorer.api.repository.ledgersync.TxRepository; | |
70 | import org.cardanofoundation.explorer.api.service.GenesisService; | |
71 | import org.cardanofoundation.explorer.api.service.ProtocolParamService; | |
72 | import org.cardanofoundation.explorer.common.entity.ledgersync.CostModel; | |
73 | import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; | |
74 | import org.cardanofoundation.explorer.common.entity.ledgersync.EpochParam; | |
75 | import org.cardanofoundation.explorer.common.entity.ledgersync.EpochParam_; | |
76 | import org.cardanofoundation.explorer.common.entity.ledgersync.Tx; | |
77 | import org.cardanofoundation.explorer.common.exception.BusinessException; | |
78 | import org.cardanofoundation.explorer.common.model.ByronGenesis; | |
79 | import org.cardanofoundation.explorer.common.model.ConwayGenesis; | |
80 | import org.cardanofoundation.explorer.common.model.ShelleyGenesis; | |
81 | ||
82 | @Service | |
83 | @Log4j2 | |
84 | @FieldDefaults(level = AccessLevel.PRIVATE) | |
85 | @RequiredArgsConstructor | |
86 | public class ProtocolParamServiceImpl implements ProtocolParamService { | |
87 | ||
88 | public static final String SET = "set"; | |
89 | public static final String PROPOSAL = "Proposal"; | |
90 | public static final String PROTOCOL_HISTORY = "PROTOCOL_HISTORY_ALL"; | |
91 | private static final String DELEGATE_KEY = "delegate"; | |
92 | private static final String GENESIS_DELEG_KEYS = "GENESIS_DELEG_KEYS"; | |
93 | public static final String FIXED_PROTOCOL = "FIXED_PROTOCOL"; | |
94 | ||
95 | final ParamProposalRepository paramProposalRepository; | |
96 | final EpochParamRepository epochParamRepository; | |
97 | final EpochRepository epochRepository; | |
98 | final TxRepository txRepository; | |
99 | final CostModelRepository costModelRepository; | |
100 | final ProtocolMapper protocolMapper; | |
101 | final RedisTemplate<String, Object> redisTemplate; | |
102 | final GenesisService genesisService; | |
103 | ||
104 | @Value("${application.network}") | |
105 | String network; | |
106 | ||
107 | @Value("${application.epoch.days}") | |
108 | public int epochDays; | |
109 | ||
110 | public static final String GET = "get"; | |
111 | ||
112 | @Value("${genesis.shelley}") | |
113 | String shelleyUrl; | |
114 | ||
115 | @Value("${genesis.byron}") | |
116 | String byronUrl; | |
117 | ||
118 | @Value("${genesis.conway}") | |
119 | String conwayUrl; | |
120 | // key::ProtocolType, value::getter> | |
121 | Map<ProtocolType, Method> epochParamMethods; | |
122 | ||
123 | // key::ProtocolType, value::Pair<setter,getter> | |
124 | Map<ProtocolType, Pair<Method, Method>> protocolsMethods; | |
125 | ||
126 | // key::ProtocolType, value::getter | |
127 | Map<ProtocolType, Method> paramHistoryMethods; | |
128 | ||
129 | // key::ProtocolType, value::Pair<setter,getter> | |
130 | Map<ProtocolType, Pair<Method, Method>> historiesProtocolMethods; | |
131 | ||
132 | // key::ProtocolType, value::Pair<getter, getterProposal> | |
133 | Map<ProtocolType, Pair<Method, Method>> latestParamHistoryMethods; | |
134 | ||
135 | private String getHistoryProtocolParametersKey() { | |
136 |
1
1. getHistoryProtocolParametersKey : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getHistoryProtocolParametersKey → KILLED |
return String.format("%s_%s", network, PROTOCOL_HISTORY).toUpperCase(); |
137 | } | |
138 | ||
139 | @Override | |
140 | public HistoriesProtocol getHistoryProtocolParameters( | |
141 | List<ProtocolType> protocolTypesInput, BigInteger startTime, BigInteger endTime) { | |
142 | final String redisKey = getHistoryProtocolParametersKey(); | |
143 | ||
144 | boolean isGetAll = Boolean.FALSE; | |
145 | ||
146 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if (ObjectUtils.isEmpty(protocolTypesInput) || protocolTypesInput.contains(ProtocolType.ALL)) { |
147 | protocolTypesInput = ProtocolType.getAll(); | |
148 | isGetAll = Boolean.TRUE; | |
149 |
1
1. getHistoryProtocolParameters : negated conditional → SURVIVED |
if (Objects.nonNull(redisTemplate.opsForValue().get(redisKey)) |
150 |
2
1. getHistoryProtocolParameters : negated conditional → SURVIVED 2. getHistoryProtocolParameters : negated conditional → SURVIVED |
&& (Objects.isNull(startTime) || Objects.isNull(endTime))) { |
151 |
1
1. getHistoryProtocolParameters : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getHistoryProtocolParameters → NO_COVERAGE |
return (HistoriesProtocol) redisTemplate.opsForValue().get(redisKey); |
152 | } | |
153 | } | |
154 | ||
155 | final List<ProtocolType> protocolTypes = protocolTypesInput; | |
156 | ||
157 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if ((Objects.isNull(startTime) && Objects.nonNull(endTime)) |
158 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
|| (Objects.isNull(endTime) && Objects.nonNull(startTime))) { |
159 | throw new BusinessException(BusinessCode.TIME_RANGE_ILLEGAL); | |
160 | } | |
161 | ||
162 | Timestamp startFilterTime = null; | |
163 | Timestamp endFilterTime = null; | |
164 | ||
165 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if (Objects.nonNull(startTime) && Objects.nonNull(endTime)) { |
166 |
2
1. getHistoryProtocolParameters : changed conditional boundary → SURVIVED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if (endTime.subtract(startTime).compareTo(BigInteger.ZERO) < BigInteger.ZERO.intValue()) { |
167 | throw new BusinessException(BusinessCode.TIME_RANGE_ILLEGAL); | |
168 | } | |
169 | ||
170 | startFilterTime = | |
171 | Timestamp.valueOf( | |
172 | LocalDateTime.ofEpochSecond( | |
173 | startTime.longValue(), BigInteger.ZERO.intValue(), ZoneOffset.UTC)); | |
174 | endFilterTime = | |
175 | Timestamp.valueOf( | |
176 | LocalDateTime.ofEpochSecond( | |
177 | endTime.longValue(), BigInteger.ZERO.intValue(), ZoneOffset.UTC)); | |
178 | } | |
179 | ||
180 | // find all param proposal change, and take the last change | |
181 | List<ParamHistory> historiesChange; | |
182 | // find all epoch param group there in to map of key:epoch value:epoch_param | |
183 | Map<Integer, EpochParam> epochParams; | |
184 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if (Objects.isNull(startFilterTime) && Objects.isNull(endFilterTime)) { |
185 | historiesChange = paramProposalRepository.findProtocolsChange(); | |
186 | epochParams = | |
187 | epochParamRepository.findAll().stream() | |
188 |
1
1. lambda$getHistoryProtocolParameters$0 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$0 → NO_COVERAGE |
.collect(Collectors.toMap(EpochParam::getEpochNo, Function.identity(), (a, b) -> a)); |
189 | } else { | |
190 | isGetAll = Boolean.FALSE; | |
191 | historiesChange = paramProposalRepository.findProtocolsChange(endFilterTime); | |
192 | epochParams = | |
193 | epochParamRepository.findEpochParamInTime(endFilterTime).stream() | |
194 |
1
1. lambda$getHistoryProtocolParameters$1 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$1 → NO_COVERAGE |
.collect(Collectors.toMap(EpochParam::getEpochNo, Function.identity(), (a, b) -> a)); |
195 | } | |
196 | ||
197 | // find all transaction update protocol param | |
198 | Map<Long, Tx> txs = | |
199 | txRepository | |
200 | .findByIdIn(historiesChange.stream().map(ParamHistory::getTx).toList()) | |
201 | .parallelStream() | |
202 | .collect(Collectors.toMap(Tx::getId, Function.identity())); | |
203 | // group by epoch | |
204 | Map<Integer, List<ParamHistory>> historiesChangeByEpoch = | |
205 | historiesChange.parallelStream() | |
206 | .collect(Collectors.groupingBy(ParamHistory::getEpochNo, Collectors.toList())); | |
207 | ||
208 | // group the un process to map | |
209 | Map<Integer, Protocols> unprocessedProtocols = | |
210 | epochParams.keySet().stream() | |
211 | .sorted(Integer::compareTo) | |
212 | .map( | |
213 | epoch -> { | |
214 | Protocols protocols = getEpochProtocol(epoch); | |
215 | List<ParamHistory> protocolHistories = | |
216 |
1
1. lambda$getHistoryProtocolParameters$2 : Replaced integer subtraction with addition → KILLED |
historiesChangeByEpoch.get(epoch - BigInteger.ONE.intValue()); |
217 | ||
218 |
1
1. lambda$getHistoryProtocolParameters$2 : negated conditional → KILLED |
if (ObjectUtils.isEmpty(protocolHistories)) { |
219 |
1
1. lambda$getHistoryProtocolParameters$2 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$2 → KILLED |
return protocols; |
220 | } | |
221 | ||
222 | Protocols protocolsChange = | |
223 | getEpochProtocol( | |
224 | protocolHistories.get(BigInteger.ZERO.intValue()).getEpochNo() | |
225 |
1
1. lambda$getHistoryProtocolParameters$2 : Replaced integer addition with subtraction → KILLED |
+ BigInteger.ONE.intValue()); |
226 |
1
1. lambda$getHistoryProtocolParameters$2 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getProtocolChangeInOneEpoch → KILLED |
getProtocolChangeInOneEpoch( |
227 | protocolHistories, txs, protocolsChange, protocolTypes); | |
228 | ||
229 |
1
1. lambda$getHistoryProtocolParameters$2 : negated conditional → KILLED |
if (Objects.equals(protocols, protocolsChange)) { |
230 |
1
1. lambda$getHistoryProtocolParameters$2 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$2 → NO_COVERAGE |
return protocols; |
231 | } | |
232 |
1
1. lambda$getHistoryProtocolParameters$2 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$2 → KILLED |
return protocolsChange; |
233 | }) | |
234 | .collect( | |
235 | Collectors.toMap( | |
236 |
1
1. lambda$getHistoryProtocolParameters$3 : replaced Integer return value with 0 for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$3 → KILLED |
protocols -> protocols.getEpochChange().getStartEpoch(), Function.identity())); |
237 | ||
238 | List<Protocols> processProtocols = new ArrayList<>(); | |
239 | ||
240 |
1
1. getHistoryProtocolParameters : negated conditional → KILLED |
if (ObjectUtils.isEmpty(epochParams.keySet())) { |
241 |
1
1. getHistoryProtocolParameters : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getHistoryProtocolParameters → KILLED |
return new HistoriesProtocol(); // return empty if epoch param is empty |
242 | } | |
243 | ||
244 | final Integer min = | |
245 | epochParams.keySet().stream().min(Integer::compareTo).orElse(BigInteger.ZERO.intValue()); | |
246 | final Integer max = | |
247 | historiesChangeByEpoch.keySet().stream() | |
248 | .max(Integer::compareTo) | |
249 | .orElse(BigInteger.ZERO.intValue()) | |
250 |
1
1. getHistoryProtocolParameters : Replaced integer addition with subtraction → KILLED |
+ BigInteger.TWO.intValue(); |
251 | ||
252 | final Map<Integer, EpochTimeProjection> epochTime = new HashMap<>(); | |
253 |
2
1. getHistoryProtocolParameters : negated conditional → KILLED 2. getHistoryProtocolParameters : negated conditional → KILLED |
if (Objects.nonNull(startFilterTime) && Objects.nonNull(endFilterTime)) { |
254 |
1
1. getHistoryProtocolParameters : removed call to java/util/Map::putAll → KILLED |
epochTime.putAll( |
255 | epochRepository.findEpochTime(min, max).stream() | |
256 | .collect(Collectors.toMap(EpochTimeProjection::getEpochNo, Function.identity()))); | |
257 | } | |
258 | ||
259 | // check protocol change upcoming | |
260 | var currentEpoch = | |
261 | epochRepository | |
262 | .findByCurrentEpochNo() | |
263 |
1
1. lambda$getHistoryProtocolParameters$4 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getHistoryProtocolParameters$4 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.EPOCH_NOT_FOUND)); |
264 | ||
265 |
1
1. getHistoryProtocolParameters : negated conditional → SURVIVED |
if (historiesChangeByEpoch.containsKey(currentEpoch.getNo()) |
266 |
1
1. getHistoryProtocolParameters : negated conditional → NO_COVERAGE |
&& isConfirmedProtocolParameterUpdate(currentEpoch.getNo())) { |
267 |
1
1. getHistoryProtocolParameters : Replaced integer addition with subtraction → NO_COVERAGE |
Protocols protocols = getEpochProtocol(currentEpoch.getNo() + BigInteger.ONE.intValue()); |
268 |
1
1. getHistoryProtocolParameters : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getProtocolChangeInOneEpoch → NO_COVERAGE |
getProtocolChangeInOneEpoch( |
269 | historiesChangeByEpoch.get(currentEpoch.getNo()), txs, protocols, protocolTypes); | |
270 |
1
1. getHistoryProtocolParameters : negated conditional → NO_COVERAGE |
if (Objects.nonNull(startFilterTime)) { |
271 |
1
1. getHistoryProtocolParameters : Replaced integer addition with subtraction → NO_COVERAGE |
Integer epochNo = currentEpoch.getNo() + BigInteger.ONE.intValue(); |
272 | Timestamp startEpochUpcomingTime = currentEpoch.getEndTime(); | |
273 | Timestamp endEpochUpcomingTime = | |
274 | Timestamp.valueOf(currentEpoch.getEndTime().toLocalDateTime().plusDays(epochDays)); | |
275 | epochTime.put( | |
276 | epochNo, | |
277 | new EpochTimeProjection(epochNo, startEpochUpcomingTime, endEpochUpcomingTime)); | |
278 | } | |
279 |
1
1. getHistoryProtocolParameters : Replaced integer addition with subtraction → NO_COVERAGE |
unprocessedProtocols.put(currentEpoch.getNo() + BigInteger.ONE.intValue(), protocols); |
280 |
1
1. getHistoryProtocolParameters : Replaced integer addition with subtraction → NO_COVERAGE |
epochParams.put(currentEpoch.getNo() + BigInteger.ONE.intValue(), null); |
281 | } | |
282 | ||
283 | AtomicReference<Protocols> currentMarkProtocols = new AtomicReference<>(); | |
284 | ||
285 | // check unprocessedProtocols data | |
286 | IntStream.range(min, max) | |
287 | .boxed() | |
288 | .sorted(Collections.reverseOrder()) | |
289 | .filter(epochParams::containsKey) | |
290 |
1
1. getHistoryProtocolParameters : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
291 | epoch -> { | |
292 | ||
293 | // fill markProtocol when it empties | |
294 |
1
1. lambda$getHistoryProtocolParameters$5 : negated conditional → KILLED |
if (Objects.isNull(currentMarkProtocols.get())) { |
295 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
currentMarkProtocols.set(unprocessedProtocols.get(epoch)); |
296 | } | |
297 | ||
298 | Protocols markProtocol = currentMarkProtocols.get(); | |
299 | Protocols currentProtocol = unprocessedProtocols.get(epoch); | |
300 | ||
301 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::fillMissingProtocolField → KILLED |
fillMissingProtocolField(currentProtocol, epochParams.get(epoch), protocolTypes); |
302 | ||
303 |
1
1. lambda$getHistoryProtocolParameters$5 : negated conditional → KILLED |
if (markProtocol.equals(currentProtocol, protocolsMethods, protocolTypes)) { |
304 | currentProtocol | |
305 | .getEpochChange() | |
306 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/EpochChange::setStartEpoch → KILLED |
.setStartEpoch(markProtocol.getEpochChange().getStartEpoch()); |
307 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/EpochChange::setEndEpoch → SURVIVED |
currentProtocol.getEpochChange().setEndEpoch(epoch); |
308 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
currentMarkProtocols.set(currentProtocol); |
309 | ||
310 |
1
1. lambda$getHistoryProtocolParameters$5 : negated conditional → KILLED |
if (min.equals(epoch)) { |
311 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::fillMissingProtocolField → SURVIVED |
fillMissingProtocolField(currentProtocol, epochParams.get(epoch), protocolTypes); |
312 | processProtocols.add(currentProtocol); | |
313 | } | |
314 | return; | |
315 | } | |
316 | ||
317 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::fillMissingProtocolField → SURVIVED |
fillMissingProtocolField(markProtocol, epochParams.get(epoch), protocolTypes); |
318 | ||
319 | processProtocols.add(markProtocol); | |
320 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
currentMarkProtocols.set(currentProtocol); |
321 | ||
322 |
1
1. lambda$getHistoryProtocolParameters$5 : negated conditional → KILLED |
if (min.equals(epoch)) { |
323 |
1
1. lambda$getHistoryProtocolParameters$5 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::fillMissingProtocolField → NO_COVERAGE |
fillMissingProtocolField(currentProtocol, epochParams.get(epoch), protocolTypes); |
324 | processProtocols.add(currentProtocol); | |
325 | } | |
326 | }); | |
327 | ||
328 | HistoriesProtocol historiesProtocol = | |
329 | protocolMapper.mapProtocolsToHistoriesProtocol( | |
330 | processProtocols, protocolsMethods, historiesProtocolMethods, protocolTypes); | |
331 |
1
1. getHistoryProtocolParameters : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::handleHistoriesChange → KILLED |
handleHistoriesChange(historiesProtocol, protocolTypes); |
332 | ||
333 |
1
1. getHistoryProtocolParameters : negated conditional → KILLED |
if (!ObjectUtils.isEmpty(epochTime)) { |
334 |
1
1. getHistoryProtocolParameters : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::filterProtocolTime → KILLED |
filterProtocolTime( |
335 | startFilterTime, endFilterTime, historiesProtocol, protocolTypes, epochTime); | |
336 | } | |
337 | ||
338 |
1
1. getHistoryProtocolParameters : negated conditional → KILLED |
if (!ObjectUtils.isEmpty(historiesProtocol.getEpochChanges())) { |
339 | EpochChange epochChange = historiesProtocol.getEpochChanges().get(0); | |
340 |
1
1. getHistoryProtocolParameters : negated conditional → KILLED |
if (!epochChange.getStartEpoch().equals(epochChange.getEndEpoch())) { |
341 |
1
1. getHistoryProtocolParameters : removed call to org/cardanofoundation/explorer/api/model/response/protocol/EpochChange::setStartEpoch → KILLED |
epochChange.setStartEpoch(epochChange.getEndEpoch()); |
342 | } | |
343 | } | |
344 | ||
345 |
1
1. getHistoryProtocolParameters : negated conditional → KILLED |
if (isGetAll) { |
346 | var redisKeyExpireTime = currentEpoch.getStartTime().toLocalDateTime().plusDays(epochDays); | |
347 | final var seconds = | |
348 | ChronoUnit.SECONDS.between(LocalDateTime.now(ZoneOffset.UTC), redisKeyExpireTime); | |
349 |
1
1. getHistoryProtocolParameters : removed call to org/springframework/data/redis/core/ValueOperations::set → NO_COVERAGE |
redisTemplate.opsForValue().set(redisKey, historiesProtocol); |
350 | redisTemplate.expire(redisKey, Duration.ofSeconds(seconds)); | |
351 | } | |
352 | ||
353 |
1
1. getHistoryProtocolParameters : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getHistoryProtocolParameters → KILLED |
return historiesProtocol; |
354 | } | |
355 | ||
356 | /** | |
357 | * Check if protocol proposal is confirmed | |
358 | * | |
359 | * @param epochNo epoch number | |
360 | * @return true if protocol proposal have enough quorum to update | |
361 | */ | |
362 | private boolean isConfirmedProtocolParameterUpdate(Integer epochNo) { | |
363 | try { | |
364 | FixedProtocol fixedProtocol = getFixedProtocols(); | |
365 | Map<String, Object> genDelegs = (Map<String, Object>) fixedProtocol.getGenDelegs(); | |
366 | var keyList = paramProposalRepository.findKeysByEpochNo(epochNo); | |
367 | int countKey = 0; | |
368 | for (var key : keyList) { | |
369 |
1
1. isConfirmedProtocolParameterUpdate : negated conditional → NO_COVERAGE |
if (genDelegs.containsKey(key)) { |
370 |
1
1. isConfirmedProtocolParameterUpdate : Changed increment from 1 to -1 → NO_COVERAGE |
countKey++; |
371 | } | |
372 | } | |
373 |
3
1. isConfirmedProtocolParameterUpdate : changed conditional boundary → NO_COVERAGE 2. isConfirmedProtocolParameterUpdate : negated conditional → NO_COVERAGE 3. isConfirmedProtocolParameterUpdate : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::isConfirmedProtocolParameterUpdate → NO_COVERAGE |
return fixedProtocol.getUpdateQuorum().compareTo(countKey) <= BigInteger.ZERO.intValue(); |
374 | } catch (Exception e) { | |
375 | log.error(e.getMessage()); | |
376 |
1
1. isConfirmedProtocolParameterUpdate : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::isConfirmedProtocolParameterUpdate → NO_COVERAGE |
return false; |
377 | } | |
378 | } | |
379 | ||
380 | private void deleteProtocolHistoryCache() { | |
381 | redisTemplate.delete(getHistoryProtocolParametersKey()); | |
382 | redisTemplate.delete(getGenesisDelegRedisKeys()); | |
383 | } | |
384 | ||
385 | @Override | |
386 | public Protocols getLatestChange() { | |
387 | ||
388 | Epoch firstEpoch = | |
389 | epochRepository | |
390 | .findFirstByNo(BigInteger.ZERO.intValue()) | |
391 |
1
1. lambda$getLatestChange$6 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getLatestChange$6 → NO_COVERAGE |
.orElseThrow(() -> new BusinessException(BusinessCode.EPOCH_NOT_FOUND)); |
392 | ||
393 | List<LatestParamHistory> changeHistories = getParamHistories(); | |
394 | final Protocols protocols = new Protocols(); | |
395 | Map<Long, String> costModelMap = | |
396 | costModelRepository.findAll().stream() | |
397 | .collect(Collectors.toMap(CostModel::getId, CostModel::getCosts)); | |
398 | ||
399 | changeHistories.stream() | |
400 | .sorted(Comparator.comparing(LatestParamHistory::getEpochNo)) | |
401 |
1
1. getLatestChange : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
402 | changeHistory -> | |
403 | ProtocolType.getAll().parallelStream() | |
404 |
1
1. lambda$getLatestChange$8 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
405 | protocolType -> { | |
406 | try { | |
407 | final var protocolSetter = | |
408 | protocolsMethods.get(protocolType).getFirst(); | |
409 | final var protocolGetter = | |
410 | protocolsMethods.get(protocolType).getSecond(); | |
411 | ||
412 | var changeValue = | |
413 | latestParamHistoryMethods | |
414 | .get(protocolType) | |
415 | .getFirst() | |
416 | .invoke(changeHistory); | |
417 | final var oldValue = (ProtocolHistory) protocolGetter.invoke(protocols); | |
418 | ||
419 | final var epochTime = changeHistory.getEpochTime(); | |
420 | LocalDateTime firstEpochStartTime = | |
421 | firstEpoch.getStartTime().toLocalDateTime(); | |
422 | LocalDateTime time = | |
423 | LocalDateTime.of( | |
424 | epochTime.getYear(), | |
425 | epochTime.getMonth(), | |
426 | epochTime.getDayOfMonth(), | |
427 | firstEpochStartTime.getHour(), | |
428 | firstEpochStartTime.getMinute(), | |
429 | firstEpochStartTime.getSecond()); | |
430 | Timestamp timestamp = Timestamp.valueOf(time); | |
431 | final var changeTime = new Date(timestamp.getTime()); | |
432 |
1
1. lambda$getLatestChange$7 : negated conditional → SURVIVED |
if (protocolType.equals(ProtocolType.COST_MODEL)) { |
433 | changeValue = costModelMap.get(changeValue); | |
434 | } | |
435 | ||
436 |
1
1. lambda$getLatestChange$7 : negated conditional → KILLED |
if (Objects.isNull(oldValue)) { |
437 | ProtocolHistory protocolHistory = | |
438 | ProtocolHistory.builder() | |
439 | .time(changeTime) | |
440 | .epochNo(changeHistory.getEpochNo()) | |
441 | .value(changeValue) | |
442 | .build(); | |
443 | protocolSetter.invoke(protocols, protocolHistory); | |
444 | return; | |
445 | } | |
446 | ||
447 | if (!String.valueOf(oldValue.getValue()) | |
448 |
1
1. lambda$getLatestChange$7 : negated conditional → NO_COVERAGE |
.equals(String.valueOf(changeValue))) { |
449 |
1
1. lambda$getLatestChange$7 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setTime → NO_COVERAGE |
oldValue.setTime(changeTime); |
450 |
1
1. lambda$getLatestChange$7 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setValue → NO_COVERAGE |
oldValue.setValue(changeValue); |
451 |
1
1. lambda$getLatestChange$7 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setEpochNo → NO_COVERAGE |
oldValue.setEpochNo(changeHistory.getEpochNo()); |
452 | } | |
453 | ||
454 | } catch (IllegalAccessException | InvocationTargetException e) { | |
455 | log.error(e.getMessage()); | |
456 | } | |
457 | })); | |
458 |
1
1. getLatestChange : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getLatestChange → KILLED |
return protocols; |
459 | } | |
460 | ||
461 | @Override | |
462 | public FixedProtocol getFixedProtocols() { | |
463 | FixedProtocol fixedProtocol = | |
464 | (FixedProtocol) redisTemplate.opsForValue().get(getFixedProtocolsKey()); | |
465 |
1
1. getFixedProtocols : negated conditional → NO_COVERAGE |
if (Objects.isNull(fixedProtocol)) { |
466 | fixedProtocol = loadFixedProtocols(); | |
467 | } | |
468 |
1
1. getFixedProtocols : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getFixedProtocols → NO_COVERAGE |
return fixedProtocol; |
469 | } | |
470 | ||
471 | @Override | |
472 | @Transactional | |
473 | public Map<String, String> getGenesisDelegateKeysMap() { | |
474 | Object genDelegsRedisMap = redisTemplate.opsForValue().get(getGenesisDelegRedisKeys()); | |
475 | ||
476 |
1
1. getGenesisDelegateKeysMap : negated conditional → NO_COVERAGE |
if (Objects.isNull(genDelegsRedisMap)) { |
477 | Map<String, String> dKeyHash224Map = new HashMap<>(); | |
478 | ObjectMapper objectMapper = new ObjectMapper(); | |
479 | ||
480 | // get genesis delegate key from genesis file | |
481 | JsonNode genDelegsNode = objectMapper.valueToTree(getFixedProtocols().getGenDelegs()); | |
482 | genDelegsNode | |
483 | .fields() | |
484 |
1
1. getGenesisDelegateKeysMap : removed call to java/util/Iterator::forEachRemaining → NO_COVERAGE |
.forEachRemaining( |
485 | entry -> { | |
486 | String key = entry.getKey(); | |
487 | String value = entry.getValue().get(DELEGATE_KEY).asText(); | |
488 | dKeyHash224Map.put(value, key); | |
489 | }); | |
490 | ||
491 |
1
1. getGenesisDelegateKeysMap : removed call to org/springframework/data/redis/core/ValueOperations::set → NO_COVERAGE |
redisTemplate.opsForValue().set(getGenesisDelegRedisKeys(), dKeyHash224Map); |
492 |
1
1. getGenesisDelegateKeysMap : replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getGenesisDelegateKeysMap → NO_COVERAGE |
return dKeyHash224Map; |
493 | } else { | |
494 |
1
1. getGenesisDelegateKeysMap : replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getGenesisDelegateKeysMap → NO_COVERAGE |
return (Map<String, String>) genDelegsRedisMap; |
495 | } | |
496 | } | |
497 | ||
498 | private String getFixedProtocolsKey() { | |
499 |
1
1. getFixedProtocolsKey : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getFixedProtocolsKey → SURVIVED |
return String.format("%s_%s", network, FIXED_PROTOCOL).toUpperCase(); |
500 | } | |
501 | ||
502 | private String getGenesisDelegRedisKeys() { | |
503 |
1
1. getGenesisDelegRedisKeys : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getGenesisDelegRedisKeys → SURVIVED |
return String.format("%s_%s", network, GENESIS_DELEG_KEYS).toUpperCase(); |
504 | } | |
505 | ||
506 | private FixedProtocol loadFixedProtocols() { | |
507 | FixedProtocol fixedProtocol = getFixedProtocolFromShelleyGenesis(shelleyUrl); | |
508 | getFixedProtocolFromByronGenesis(byronUrl, fixedProtocol); | |
509 |
1
1. loadFixedProtocols : removed call to org/springframework/data/redis/core/ValueOperations::set → SURVIVED |
redisTemplate.opsForValue().set(getFixedProtocolsKey(), fixedProtocol); |
510 |
1
1. loadFixedProtocols : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::loadFixedProtocols → SURVIVED |
return fixedProtocol; |
511 | } | |
512 | ||
513 | /** | |
514 | * histories changes of protocols in network | |
515 | * | |
516 | * @return | |
517 | */ | |
518 | private List<LatestParamHistory> getParamHistories() { | |
519 | var maxEpochChange = paramProposalRepository.findMaxEpochChange(); | |
520 | ||
521 |
1
1. getParamHistories : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getParamHistories → KILLED |
return paramProposalRepository.findProtocolsChange(maxEpochChange); |
522 | } | |
523 | ||
524 | /** | |
525 | * Mapping ProtocolHistory that change | |
526 | * | |
527 | * @param currentProtocol value of protocol param | |
528 | * @param txs transactions proposal change | |
529 | * @param timeChange time proposal change | |
530 | * @return | |
531 | */ | |
532 | public static ProtocolHistory getChangeProtocol( | |
533 | Object currentProtocol, List<Tx> txs, AtomicReference<LocalDateTime> timeChange) { | |
534 |
1
1. getChangeProtocol : Replaced integer subtraction with addition → KILLED |
Tx latestTx = txs.get(txs.size() - 1); |
535 | ||
536 |
1
1. getChangeProtocol : removed call to java/util/concurrent/atomic/AtomicReference::set → SURVIVED |
timeChange.set( |
537 | LocalDateTime.ofInstant(latestTx.getBlock().getTime().toInstant(), ZoneOffset.UTC)); | |
538 |
1
1. getChangeProtocol : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getChangeProtocol → KILLED |
return ProtocolHistory.builder() |
539 | .value(currentProtocol) | |
540 | .time(latestTx.getBlock().getTime()) | |
541 | .transactionHashs(txs.stream().map(Tx::getHash).collect(Collectors.toSet())) | |
542 | .build(); | |
543 | } | |
544 | ||
545 | /** | |
546 | * Mapping not change protocol parameters | |
547 | * | |
548 | * @param object | |
549 | * @return | |
550 | */ | |
551 | public static ProtocolHistory getChangeProtocol(Object object) { | |
552 | ||
553 |
1
1. getChangeProtocol : negated conditional → KILLED |
if (object instanceof CostModel costModel) { |
554 | object = costModel.getCosts(); | |
555 | } | |
556 | ||
557 |
1
1. getChangeProtocol : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getChangeProtocol → KILLED |
return ProtocolHistory.builder().value(object).time(null).transactionHashs(null).build(); |
558 | } | |
559 | ||
560 | /** | |
561 | * @param epochParam epoch param | |
562 | * @return | |
563 | */ | |
564 | public static Protocols mapProtocols(EpochParam epochParam) { | |
565 | var protocols = | |
566 | Protocols.builder() | |
567 | .minFeeA(getChangeProtocol(epochParam.getMinFeeA())) | |
568 | .minFeeB(getChangeProtocol(epochParam.getMinFeeB())) | |
569 | .maxBlockSize(getChangeProtocol(epochParam.getMaxBlockSize())) | |
570 | .maxTxSize(getChangeProtocol(epochParam.getMaxTxSize())) | |
571 | .maxBhSize(getChangeProtocol(epochParam.getMaxBhSize())) | |
572 | .keyDeposit(getChangeProtocol(epochParam.getKeyDeposit())) | |
573 | .poolDeposit(getChangeProtocol(epochParam.getPoolDeposit())) | |
574 | .maxEpoch(getChangeProtocol(epochParam.getMaxEpoch())) | |
575 | .optimalPoolCount(getChangeProtocol(epochParam.getOptimalPoolCount())) | |
576 | .influence(getChangeProtocol(epochParam.getInfluence())) | |
577 | .monetaryExpandRate(getChangeProtocol(epochParam.getMonetaryExpandRate())) | |
578 | .treasuryGrowthRate(getChangeProtocol(epochParam.getTreasuryGrowthRate())) | |
579 | .decentralisation(getChangeProtocol(epochParam.getDecentralisation())) | |
580 | .entropy(getChangeProtocol(epochParam.getExtraEntropy())) | |
581 | .protocolMajor(getChangeProtocol(epochParam.getProtocolMajor())) | |
582 | .protocolMinor(getChangeProtocol(epochParam.getProtocolMinor())) | |
583 | .minUtxoValue(getChangeProtocol(epochParam.getMinUtxoValue())) | |
584 | .minPoolCost(getChangeProtocol(epochParam.getMinPoolCost())) | |
585 | .priceMem(getChangeProtocol(epochParam.getPriceMem())) | |
586 | .priceStep(getChangeProtocol(epochParam.getPriceStep())) | |
587 | .maxTxExMem(getChangeProtocol(epochParam.getMaxTxExMem())) | |
588 | .maxTxExSteps(getChangeProtocol(epochParam.getMaxTxExSteps())) | |
589 | .maxBlockExMem(getChangeProtocol(epochParam.getMaxBlockExMem())) | |
590 | .maxBlockExSteps(getChangeProtocol(epochParam.getMaxBlockExSteps())) | |
591 | .maxValSize(getChangeProtocol(epochParam.getMaxValSize())) | |
592 | .collateralPercent(getChangeProtocol(epochParam.getCollateralPercent())) | |
593 | .maxCollateralInputs(getChangeProtocol(epochParam.getMaxCollateralInputs())) | |
594 | .coinsPerUtxoSize(getChangeProtocol(epochParam.getCoinsPerUtxoSize())) | |
595 | .epochChange( | |
596 | EpochChange.builder() | |
597 | .endEpoch(epochParam.getEpochNo()) | |
598 | .startEpoch(epochParam.getEpochNo()) | |
599 | .build()) | |
600 | .build(); | |
601 |
1
1. mapProtocols : negated conditional → KILLED |
if (Objects.nonNull(epochParam.getCostModel())) { |
602 |
1
1. mapProtocols : removed call to org/cardanofoundation/explorer/api/model/response/protocol/Protocols::setCostModel → KILLED |
protocols.setCostModel(getChangeProtocol(epochParam.getCostModel().getCosts())); |
603 | } else { | |
604 |
1
1. mapProtocols : removed call to org/cardanofoundation/explorer/api/model/response/protocol/Protocols::setCostModel → KILLED |
protocols.setCostModel(ProtocolHistory.builder().build()); |
605 | } | |
606 | ||
607 |
1
1. mapProtocols : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::mapProtocols → KILLED |
return protocols; |
608 | } | |
609 | ||
610 | /** | |
611 | * Map epoch change | |
612 | * | |
613 | * @param epochNo | |
614 | * @return | |
615 | */ | |
616 | private Protocols getEpochProtocol(Integer epochNo) { | |
617 |
1
1. getEpochProtocol : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getEpochProtocol → KILLED |
return Protocols.builder() |
618 | .epochChange(EpochChange.builder().startEpoch(epochNo).endEpoch(epochNo).build()) | |
619 | .build(); | |
620 | } | |
621 | ||
622 | /** | |
623 | * @param paramHistories proposal change | |
624 | * @param txs transaction change | |
625 | * @param protocols protocol | |
626 | * @param protocolTypes list protocol type must filter | |
627 | */ | |
628 | private void getProtocolChangeInOneEpoch( | |
629 | List<ParamHistory> paramHistories, | |
630 | Map<Long, Tx> txs, | |
631 | Protocols protocols, | |
632 | List<ProtocolType> protocolTypes) { | |
633 |
1
1. getProtocolChangeInOneEpoch : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::mapProtocols → KILLED |
mapProtocols(paramHistories, protocols, txs, protocolTypes); |
634 | } | |
635 | ||
636 | private void mapProtocols( | |
637 | List<ParamHistory> paramProposals, | |
638 | Protocols protocols, | |
639 | Map<Long, Tx> txs, | |
640 | List<ProtocolType> protocolTypes) { | |
641 | ||
642 | List<Tx> txsUpdatePP = | |
643 | paramProposals.stream() | |
644 |
1
1. lambda$mapProtocols$10 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$mapProtocols$10 → KILLED |
.map(paramProposal -> txs.get(paramProposal.getTx())) |
645 | .collect(Collectors.toList()); | |
646 | ||
647 | paramProposals.stream() | |
648 | .sorted( | |
649 | Comparator.comparing(ParamHistory::getEpochNo) | |
650 | .reversed() | |
651 | .thenComparing(ParamHistory::getTx)) | |
652 |
1
1. mapProtocols : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
653 | paramProposal -> { | |
654 | AtomicReference<LocalDateTime> timeChange = new AtomicReference<>(null); | |
655 | // set value for protocols field | |
656 | paramHistoryMethods.entrySet().stream() | |
657 |
2
1. lambda$mapProtocols$11 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$mapProtocols$11 → SURVIVED 2. lambda$mapProtocols$11 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$mapProtocols$11 → KILLED |
.filter(entry -> protocolTypes.contains(entry.getKey())) |
658 |
1
1. lambda$mapProtocols$13 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
659 | entry -> { | |
660 | try { | |
661 | // get protocol | |
662 | var protocolMethods = protocolsMethods.get(entry.getKey()); | |
663 | var protocolSet = protocolMethods.getFirst(); | |
664 | var protocolGet = protocolMethods.getSecond(); | |
665 | var protocolValue = (ProtocolHistory) protocolGet.invoke(protocols); | |
666 | ||
667 | var paramProposalValue = entry.getValue().invoke(paramProposal); | |
668 | // if value proposal not null | |
669 |
1
1. lambda$mapProtocols$12 : negated conditional → KILLED |
if (Objects.nonNull(paramProposalValue)) { |
670 | // insert if protocols is null or value change | |
671 |
1
1. lambda$mapProtocols$12 : negated conditional → KILLED |
if (Objects.requireNonNull(entry.getKey()) == ProtocolType.COST_MODEL) { |
672 |
1
1. lambda$mapProtocols$12 : negated conditional → KILLED |
if (Objects.isNull(protocolValue) |
673 |
1
1. lambda$mapProtocols$12 : negated conditional → SURVIVED |
|| !protocolValue.getCostModelId().equals(paramProposalValue)) { |
674 |
1
1. lambda$mapProtocols$12 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/Protocols::setCostModel → KILLED |
protocols.setCostModel( |
675 | getChangeCostModelProtocol( | |
676 | paramProposal.getCostModel(), txsUpdatePP, timeChange)); | |
677 | } | |
678 | } else { | |
679 |
1
1. lambda$mapProtocols$12 : negated conditional → KILLED |
if (Objects.isNull(protocolValue) |
680 |
1
1. lambda$mapProtocols$12 : negated conditional → KILLED |
|| !protocolValue.getValue().equals(paramProposalValue)) { |
681 | protocolSet.invoke( | |
682 | protocols, | |
683 | getChangeProtocol(paramProposalValue, txsUpdatePP, timeChange)); | |
684 | } | |
685 | } | |
686 | } | |
687 | } catch (Exception e) { | |
688 | log.error(e.getMessage()); | |
689 | log.error(e.getLocalizedMessage()); | |
690 | } | |
691 | }); | |
692 | ||
693 | // update time change | |
694 |
1
1. lambda$mapProtocols$13 : negated conditional → SURVIVED |
if (Objects.nonNull(timeChange.get())) { |
695 |
1
1. lambda$mapProtocols$13 : negated conditional → KILLED |
if (Objects.isNull(protocols.getTimestamp())) { |
696 |
1
1. lambda$mapProtocols$13 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/Protocols::setTimestamp → SURVIVED |
protocols.setTimestamp(timeChange.get()); |
697 | return; | |
698 | } | |
699 | if (protocols.getTimestamp().compareTo(timeChange.get()) | |
700 |
2
1. lambda$mapProtocols$13 : negated conditional → SURVIVED 2. lambda$mapProtocols$13 : changed conditional boundary → SURVIVED |
< BigInteger.ZERO.intValue()) { |
701 |
1
1. lambda$mapProtocols$13 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/Protocols::setTimestamp → NO_COVERAGE |
protocols.setTimestamp(timeChange.get()); |
702 | } | |
703 | } | |
704 | }); | |
705 | } | |
706 | ||
707 | /** | |
708 | * Mapping ProtocolHistory that cost model propose to change | |
709 | * | |
710 | * @param costModelId cost model id | |
711 | * @param txs transactions proposal change | |
712 | * @param timeChange time proposal change | |
713 | * @return | |
714 | */ | |
715 | private ProtocolHistory getChangeCostModelProtocol( | |
716 | Long costModelId, List<Tx> txs, AtomicReference<LocalDateTime> timeChange) { | |
717 | ||
718 |
1
1. getChangeCostModelProtocol : Replaced integer subtraction with addition → KILLED |
Tx lastTx = txs.get(txs.size() - 1); |
719 | Optional<CostModel> costModel = costModelRepository.findById(costModelId); | |
720 |
1
1. getChangeCostModelProtocol : removed call to java/util/concurrent/atomic/AtomicReference::set → SURVIVED |
timeChange.set( |
721 | LocalDateTime.ofInstant(lastTx.getBlock().getTime().toInstant(), ZoneOffset.UTC)); | |
722 |
1
1. getChangeCostModelProtocol : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getChangeCostModelProtocol → KILLED |
return costModel |
723 | .map( | |
724 | model -> | |
725 |
1
1. lambda$getChangeCostModelProtocol$14 : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getChangeCostModelProtocol$14 → KILLED |
ProtocolHistory.builder() |
726 | .value(model.getCosts()) | |
727 | .time(lastTx.getBlock().getTime()) | |
728 | .transactionHashs(txs.stream().map(Tx::getHash).collect(Collectors.toSet())) | |
729 | .costModelId(costModelId) | |
730 | .build()) | |
731 | .orElse(null); | |
732 | } | |
733 | ||
734 | /** | |
735 | * Fill missing protocol parameters that not change in epoch with filter condition | |
736 | * | |
737 | * @param protocols protocol | |
738 | * @param epochParam epoch param | |
739 | * @param protocolTypes protocol type must filter | |
740 | */ | |
741 | private void fillMissingProtocolField( | |
742 | Protocols protocols, EpochParam epochParam, List<ProtocolType> protocolTypes) { | |
743 | protocolsMethods.entrySet().stream() | |
744 |
2
1. lambda$fillMissingProtocolField$15 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$fillMissingProtocolField$15 → SURVIVED 2. lambda$fillMissingProtocolField$15 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$fillMissingProtocolField$15 → KILLED |
.filter(entry -> protocolTypes.contains(entry.getKey())) |
745 |
1
1. fillMissingProtocolField : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
746 | entry -> { | |
747 | var methods = protocolsMethods.get(entry.getKey()); | |
748 | try { | |
749 |
1
1. lambda$fillMissingProtocolField$16 : negated conditional → KILLED |
if (Objects.isNull(entry.getValue().getSecond().invoke(protocols)) |
750 |
1
1. lambda$fillMissingProtocolField$16 : negated conditional → KILLED |
&& Objects.nonNull(epochParam)) { |
751 | methods | |
752 | .getFirst() | |
753 | .invoke( | |
754 | protocols, | |
755 | getChangeProtocol( | |
756 | epochParamMethods.get(entry.getKey()).invoke(epochParam))); | |
757 | } | |
758 | } catch (Exception e) { | |
759 | log.error(e.getMessage()); | |
760 | log.error(e.getLocalizedMessage()); | |
761 | } | |
762 | }); | |
763 | } | |
764 | ||
765 | /** | |
766 | * This function is a loop of prototype | |
767 | * | |
768 | * @param historiesProtocol | |
769 | * @param protocolTypes | |
770 | */ | |
771 | private void handleHistoriesChange( | |
772 | HistoriesProtocol historiesProtocol, List<ProtocolType> protocolTypes) { | |
773 | historiesProtocolMethods.entrySet().stream() | |
774 |
2
1. lambda$handleHistoriesChange$17 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$handleHistoriesChange$17 → SURVIVED 2. lambda$handleHistoriesChange$17 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$handleHistoriesChange$17 → KILLED |
.filter(entry -> protocolTypes.contains(entry.getKey())) |
775 | .parallel() | |
776 |
1
1. handleHistoriesChange : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
777 | method -> { | |
778 | try { | |
779 | var historyProtocolGet = method.getValue().getSecond(); | |
780 | log.debug("method {}", method.getValue().getSecond().getName()); | |
781 |
1
1. lambda$handleHistoriesChange$18 : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::handleHistoryStatus → KILLED |
handleHistoryStatus( |
782 | (List<ProtocolHistory>) historyProtocolGet.invoke(historiesProtocol)); | |
783 | } catch (Exception e) { | |
784 | log.error(e.getMessage()); | |
785 | log.error(e.getLocalizedMessage()); | |
786 | } | |
787 | }); | |
788 | } | |
789 | ||
790 | /** | |
791 | * This function fill {@link ProtocolStatus } base on change of input list {@link ProtocolHistory} | |
792 | * | |
793 | * @param protocolHistories | |
794 | */ | |
795 | private void handleHistoryStatus(List<ProtocolHistory> protocolHistories) { | |
796 | ||
797 |
1
1. handleHistoryStatus : Replaced integer subtraction with addition → KILLED |
int size = protocolHistories.size() - BigInteger.ONE.intValue(); |
798 | ||
799 | IntStream.range(BigInteger.ZERO.intValue(), size) | |
800 |
1
1. handleHistoryStatus : removed call to java/util/stream/IntStream::forEach → KILLED |
.forEach( |
801 | index -> { | |
802 | final ProtocolHistory nextProtocolHistory = | |
803 |
1
1. lambda$handleHistoryStatus$19 : Replaced integer addition with subtraction → KILLED |
protocolHistories.get(index + BigInteger.ONE.intValue()); |
804 | ||
805 | final ProtocolHistory currentProtocolHistory = protocolHistories.get(index); | |
806 | ||
807 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → KILLED |
if (Objects.isNull(currentProtocolHistory)) { |
808 | return; | |
809 | } | |
810 | ||
811 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → KILLED |
if (Objects.isNull(nextProtocolHistory)) { |
812 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → NO_COVERAGE |
if (Objects.nonNull(currentProtocolHistory.getValue())) { |
813 |
1
1. lambda$handleHistoryStatus$19 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → NO_COVERAGE |
currentProtocolHistory.setStatus(ProtocolStatus.ADDED); |
814 | } | |
815 | return; | |
816 | } | |
817 | ||
818 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → KILLED |
if (Objects.isNull(currentProtocolHistory.getValue())) { |
819 |
1
1. lambda$handleHistoryStatus$19 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → NO_COVERAGE |
currentProtocolHistory.setStatus(ProtocolStatus.NOT_EXIST); |
820 | return; | |
821 | } | |
822 | ||
823 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → KILLED |
if (Objects.isNull(nextProtocolHistory.getValue())) { |
824 |
1
1. lambda$handleHistoryStatus$19 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → NO_COVERAGE |
currentProtocolHistory.setStatus(ProtocolStatus.ADDED); |
825 | return; | |
826 | } | |
827 | ||
828 | if (currentProtocolHistory.getValue().hashCode() | |
829 |
1
1. lambda$handleHistoryStatus$19 : negated conditional → KILLED |
!= nextProtocolHistory.getValue().hashCode()) { |
830 |
1
1. lambda$handleHistoryStatus$19 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → KILLED |
currentProtocolHistory.setStatus(ProtocolStatus.UPDATED); |
831 | return; | |
832 | } | |
833 |
1
1. lambda$handleHistoryStatus$19 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → NO_COVERAGE |
currentProtocolHistory.setStatus(ProtocolStatus.NOT_CHANGE); |
834 | }); | |
835 | ||
836 | ProtocolHistory lastProtocol = protocolHistories.get(size); | |
837 | ||
838 |
1
1. handleHistoryStatus : negated conditional → KILLED |
if (Objects.nonNull(lastProtocol)) { |
839 |
1
1. handleHistoryStatus : negated conditional → KILLED |
if (Objects.isNull(lastProtocol.getValue())) { |
840 |
1
1. handleHistoryStatus : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → NO_COVERAGE |
lastProtocol.setStatus(ProtocolStatus.NOT_EXIST); |
841 | return; | |
842 | } | |
843 |
1
1. handleHistoryStatus : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → KILLED |
lastProtocol.setStatus(ProtocolStatus.ADDED); |
844 | } | |
845 | } | |
846 | ||
847 | /** User java refection to mapping {@link EpochParam} Get method */ | |
848 | private void setMapEpochParamMethods() { | |
849 | epochParamMethods = new EnumMap<>(ProtocolType.class); | |
850 | Field[] fields = EpochParam.class.getDeclaredFields(); | |
851 | Method[] methods = EpochParam.class.getDeclaredMethods(); | |
852 | List<String> fieldNames = | |
853 | Arrays.stream(ProtocolType.values()).map(ProtocolType::getFieldName).toList(); | |
854 | ||
855 | for (Field field : fields) { | |
856 | Method methodUsed = | |
857 | Arrays.stream(methods) | |
858 | .filter( | |
859 | method -> { | |
860 | var methodLowerCase = method.getName().toLowerCase(); | |
861 | var fieldLowerCase = field.getName().toLowerCase(); | |
862 |
2
1. lambda$setMapEpochParamMethods$20 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setMapEpochParamMethods$20 → KILLED 2. lambda$setMapEpochParamMethods$20 : negated conditional → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
863 |
1
1. lambda$setMapEpochParamMethods$20 : negated conditional → KILLED |
&& methodLowerCase.contains(GET); |
864 | }) | |
865 | .findFirst() | |
866 | .orElse(null); // Method null is ok, because we not use it anyway | |
867 | ||
868 |
1
1. setMapEpochParamMethods : negated conditional → KILLED |
if (Objects.nonNull(methodUsed) |
869 |
1
1. setMapEpochParamMethods : negated conditional → KILLED |
&& (fieldNames.contains(field.getName()) |
870 |
1
1. setMapEpochParamMethods : negated conditional → KILLED |
|| field.getName().equals(EpochParam_.EXTRA_ENTROPY))) { |
871 | epochParamMethods.put(ProtocolType.valueStringOf(field.getName()), methodUsed); | |
872 | } | |
873 | } | |
874 | } | |
875 | ||
876 | /** User java refection to mapping {@link Protocols} Pair of <Set,Get> method */ | |
877 | private void setProtocolMethodMap() { | |
878 | this.protocolsMethods = new EnumMap<>(ProtocolType.class); | |
879 | Method[] methods = Protocols.class.getDeclaredMethods(); | |
880 | List<String> fieldNames = | |
881 | Arrays.stream(ProtocolType.values()).map(ProtocolType::getFieldName).toList(); | |
882 | ||
883 | for (String field : fieldNames) { | |
884 | ||
885 | Method methodGet = | |
886 | Arrays.stream(methods) | |
887 | .filter( | |
888 | method -> { | |
889 | var methodLowerCase = method.getName().toLowerCase(); | |
890 | var fieldLowerCase = field.toLowerCase(); | |
891 |
2
1. lambda$setProtocolMethodMap$21 : negated conditional → KILLED 2. lambda$setProtocolMethodMap$21 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setProtocolMethodMap$21 → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
892 |
1
1. lambda$setProtocolMethodMap$21 : negated conditional → KILLED |
&& methodLowerCase.contains(GET); |
893 | }) | |
894 | .findFirst() | |
895 | .orElse(null); | |
896 | ||
897 | Method methodSet = | |
898 | Arrays.stream(methods) | |
899 | .filter( | |
900 | method -> { | |
901 | var methodLowerCase = method.getName().toLowerCase(); | |
902 | var fieldLowerCase = field.toLowerCase(); | |
903 |
2
1. lambda$setProtocolMethodMap$22 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setProtocolMethodMap$22 → KILLED 2. lambda$setProtocolMethodMap$22 : negated conditional → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
904 |
1
1. lambda$setProtocolMethodMap$22 : negated conditional → KILLED |
&& methodLowerCase.contains(SET); |
905 | }) | |
906 | .findFirst() | |
907 | .orElse(null); | |
908 | ||
909 |
2
1. setProtocolMethodMap : negated conditional → KILLED 2. setProtocolMethodMap : negated conditional → KILLED |
if (Objects.nonNull(methodGet) && Objects.nonNull(methodSet)) { |
910 | protocolsMethods.put(ProtocolType.valueStringOf(field), Pair.of(methodSet, methodGet)); | |
911 | } | |
912 | } | |
913 | } | |
914 | ||
915 | /** User java refection to mapping {@link HistoriesProtocol} Pair of <Set,Get> method */ | |
916 | private void setHistoriesProtocolMethods() { | |
917 | ||
918 | this.historiesProtocolMethods = new EnumMap<>(ProtocolType.class); | |
919 | ||
920 | Method[] methods = HistoriesProtocol.class.getDeclaredMethods(); | |
921 | List<String> fieldNames = | |
922 | Arrays.stream(ProtocolType.values()).map(ProtocolType::getFieldName).toList(); | |
923 | ||
924 | for (String field : fieldNames) { | |
925 | ||
926 | Method methodGet = | |
927 | Arrays.stream(methods) | |
928 | .filter( | |
929 | method -> { | |
930 | var methodLowerCase = method.getName().toLowerCase(); | |
931 | var fieldLowerCase = field.toLowerCase(); | |
932 |
2
1. lambda$setHistoriesProtocolMethods$23 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setHistoriesProtocolMethods$23 → KILLED 2. lambda$setHistoriesProtocolMethods$23 : negated conditional → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
933 |
1
1. lambda$setHistoriesProtocolMethods$23 : negated conditional → KILLED |
&& methodLowerCase.contains(GET); |
934 | }) | |
935 | .findFirst() | |
936 | .orElse(null); | |
937 | ||
938 | Method methodSet = | |
939 | Arrays.stream(methods) | |
940 | .filter( | |
941 | method -> { | |
942 | var methodLowerCase = method.getName().toLowerCase(); | |
943 | var fieldLowerCase = field.toLowerCase(); | |
944 |
2
1. lambda$setHistoriesProtocolMethods$24 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setHistoriesProtocolMethods$24 → KILLED 2. lambda$setHistoriesProtocolMethods$24 : negated conditional → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
945 |
1
1. lambda$setHistoriesProtocolMethods$24 : negated conditional → KILLED |
&& methodLowerCase.contains(SET); |
946 | }) | |
947 | .findFirst() | |
948 | .orElse(null); | |
949 | ||
950 |
2
1. setHistoriesProtocolMethods : negated conditional → KILLED 2. setHistoriesProtocolMethods : negated conditional → KILLED |
if (Objects.nonNull(methodGet) && Objects.nonNull(methodSet)) { |
951 | historiesProtocolMethods.put( | |
952 | ProtocolType.valueStringOf(field), Pair.of(methodSet, methodGet)); | |
953 | } | |
954 | } | |
955 | } | |
956 | ||
957 | /** User java refection to mapping {@link ParamHistory} get method */ | |
958 | private void setParamHistoryMethods() { | |
959 | paramHistoryMethods = new EnumMap<>(ProtocolType.class); | |
960 | Method[] methods = ParamHistory.class.getDeclaredMethods(); | |
961 | ||
962 | List<String> fieldNames = | |
963 | Arrays.stream(ProtocolType.values()).map(ProtocolType::getFieldName).toList(); | |
964 | ||
965 | for (String field : fieldNames) { | |
966 | ||
967 | Method methodGet = | |
968 | Arrays.stream(methods) | |
969 | .filter( | |
970 | method -> { | |
971 | var methodLowerCase = method.getName().toLowerCase(); | |
972 | var fieldLowerCase = field.toLowerCase(); | |
973 |
2
1. lambda$setParamHistoryMethods$25 : negated conditional → KILLED 2. lambda$setParamHistoryMethods$25 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setParamHistoryMethods$25 → KILLED |
return methodLowerCase.contains(fieldLowerCase) |
974 |
1
1. lambda$setParamHistoryMethods$25 : negated conditional → KILLED |
&& methodLowerCase.contains(GET); |
975 | }) | |
976 | .findFirst() | |
977 | .orElse(null); | |
978 | ||
979 |
1
1. setParamHistoryMethods : negated conditional → KILLED |
if (Objects.nonNull(methodGet)) { |
980 | paramHistoryMethods.put(ProtocolType.valueStringOf(field), methodGet); | |
981 | } | |
982 | } | |
983 | } | |
984 | ||
985 | /** | |
986 | * Remove index out of range compare to filter time in {@link HistoriesProtocol}. Change Protocol | |
987 | * status if necessary. | |
988 | * | |
989 | * @param startFilterTime start time to filter | |
990 | * @param endFilterTime end time to filter | |
991 | * @param historiesProtocol list of merged epoch | |
992 | * @param protocolTypes list of selected protocol type | |
993 | * @param epochTime map epoch time key::epoch no,value::EpochTimeProjection | |
994 | */ | |
995 | private void filterProtocolTime( | |
996 | Timestamp startFilterTime, | |
997 | Timestamp endFilterTime, | |
998 | HistoriesProtocol historiesProtocol, | |
999 | List<ProtocolType> protocolTypes, | |
1000 | Map<Integer, EpochTimeProjection> epochTime) { | |
1001 | ||
1002 | List<Entry<ProtocolType, Pair<Method, Method>>> methods = | |
1003 | historiesProtocolMethods.entrySet().stream() | |
1004 |
2
1. lambda$filterProtocolTime$26 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$filterProtocolTime$26 → SURVIVED 2. lambda$filterProtocolTime$26 : replaced boolean return with false for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$filterProtocolTime$26 → KILLED |
.filter(entry -> protocolTypes.contains(entry.getKey())) |
1005 | .toList(); | |
1006 | ||
1007 | List<EpochChange> epochChanges = | |
1008 | historiesProtocol.getEpochChanges().stream().map(EpochChange::clone).toList(); | |
1009 | ||
1010 | // filter epoch out of range from startTime and endTime | |
1011 | List<Integer> removeIndex = | |
1012 | getOutRangeIndex(epochChanges, startFilterTime, endFilterTime, epochTime); | |
1013 | ||
1014 | // change protocol status from ADDED to NOT_CHANGE | |
1015 |
3
1. filterProtocolTime : Replaced integer addition with subtraction → KILLED 2. filterProtocolTime : negated conditional → KILLED 3. filterProtocolTime : changed conditional boundary → KILLED |
for (int index = BigInteger.ZERO.intValue(); index < epochChanges.size(); index = index + 1) { |
1016 | var historiesEpochChange = historiesProtocol.getEpochChanges().get(index); | |
1017 | var epochChange = epochChanges.get(index); | |
1018 |
1
1. filterProtocolTime : negated conditional → KILLED |
if (epochChange.equals(historiesEpochChange)) { |
1019 | continue; | |
1020 | } | |
1021 | ||
1022 | final var checkedIndex = index; | |
1023 | methods.parallelStream() | |
1024 |
1
1. filterProtocolTime : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
1025 | entry -> { | |
1026 | var historyProtocolsGet = entry.getValue().getSecond(); | |
1027 | try { | |
1028 | ProtocolHistory protocolHistory = | |
1029 | ((List<ProtocolHistory>) historyProtocolsGet.invoke(historiesProtocol)) | |
1030 | .get(checkedIndex); | |
1031 |
1
1. lambda$filterProtocolTime$27 : negated conditional → KILLED |
if (protocolHistory.getStatus().equals(ProtocolStatus.ADDED) |
1032 |
1
1. lambda$filterProtocolTime$27 : negated conditional → KILLED |
&& !historiesEpochChange.getEndEpoch().equals(epochChange.getEndEpoch())) { |
1033 |
1
1. lambda$filterProtocolTime$27 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/ProtocolHistory::setStatus → KILLED |
protocolHistory.setStatus(ProtocolStatus.NOT_CHANGE); |
1034 | } | |
1035 | } catch (Exception e) { | |
1036 | log.error(e.getMessage()); | |
1037 | log.error(e.getLocalizedMessage()); | |
1038 | } | |
1039 | }); | |
1040 | } | |
1041 | ||
1042 | var removeIndexInOrder = removeIndex.stream().sorted(Collections.reverseOrder()).toList(); | |
1043 | ||
1044 |
1
1. filterProtocolTime : removed call to org/cardanofoundation/explorer/api/model/response/protocol/HistoriesProtocol::setEpochChanges → KILLED |
historiesProtocol.setEpochChanges(new ArrayList<>(epochChanges)); |
1045 |
1
1. filterProtocolTime : removed call to java/util/List::forEach → KILLED |
removeIndexInOrder.forEach( |
1046 | index -> { | |
1047 | historiesProtocol.getEpochChanges().remove(index.intValue()); | |
1048 | methods.parallelStream() | |
1049 |
1
1. lambda$filterProtocolTime$29 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
1050 | entry -> { | |
1051 | var historyProtocolsGet = entry.getValue().getSecond(); | |
1052 | try { | |
1053 | ((List<ProtocolHistory>) historyProtocolsGet.invoke(historiesProtocol)) | |
1054 | .remove(index.intValue()); | |
1055 | } catch (Exception e) { | |
1056 | log.error(e.getMessage()); | |
1057 | log.error(e.getLocalizedMessage()); | |
1058 | } | |
1059 | }); | |
1060 | }); | |
1061 | } | |
1062 | ||
1063 | /** | |
1064 | * this function compare merged epoch start time and end time to decide which epoch would be | |
1065 | * removed from epoch change list | |
1066 | * | |
1067 | * @param list list of merged epoch | |
1068 | * @param startFilter time start filter | |
1069 | * @param endFilter time end filter | |
1070 | * @param epochTime map start and end time of epoch | |
1071 | * @return | |
1072 | */ | |
1073 | List<Integer> getOutRangeIndex( | |
1074 | List<EpochChange> list, | |
1075 | Timestamp startFilter, | |
1076 | Timestamp endFilter, | |
1077 | Map<Integer, EpochTimeProjection> epochTime) { | |
1078 | ||
1079 |
1
1. getOutRangeIndex : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getOutRangeIndex → KILLED |
return IntStream.range(BigInteger.ZERO.intValue(), list.size()) |
1080 | .boxed() | |
1081 | .filter( | |
1082 | index -> { | |
1083 | EpochChange epochChange = list.get(index); | |
1084 | var epochChangeStartTime = epochTime.get(epochChange.getEndEpoch()).getStartTime(); | |
1085 | var epochChangeEndTime = epochTime.get(epochChange.getStartEpoch()).getEndTime(); | |
1086 | // check if filter time range of epoch time or not | |
1087 | var inRange = | |
1088 |
1
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
isWithinRange(startFilter, epochChangeStartTime, epochChangeEndTime) |
1089 |
1
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
|| isWithinRange(endFilter, epochChangeStartTime, epochChangeEndTime); |
1090 | // check if epoch time in filter range | |
1091 |
1
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
if (!inRange) { |
1092 | inRange = | |
1093 |
1
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
isWithinRange(epochChangeStartTime, startFilter, endFilter) |
1094 |
1
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
|| isWithinRange(epochChangeEndTime, startFilter, endFilter); |
1095 | } | |
1096 | ||
1097 | List<Integer> inRangeEpoch = new ArrayList<>(); | |
1098 |
2
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED 2. lambda$getOutRangeIndex$31 : negated conditional → KILLED |
if (inRange && !epochChange.getEndEpoch().equals(epochChange.getStartEpoch())) { |
1099 | IntStream.range( | |
1100 | epochChange.getEndEpoch(), | |
1101 |
1
1. lambda$getOutRangeIndex$31 : Replaced integer addition with subtraction → KILLED |
epochChange.getStartEpoch() + BigInteger.ONE.intValue()) |
1102 | .boxed() | |
1103 | .sorted(Collections.reverseOrder()) | |
1104 |
1
1. lambda$getOutRangeIndex$31 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
1105 | epoch -> { | |
1106 | final var epochStartTime = epochTime.get(epoch).getStartTime(); | |
1107 | final var epochEndTime = epochTime.get(epoch).getEndTime(); | |
1108 | ||
1109 | Boolean inEpochRange = | |
1110 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
isWithinRange(startFilter, epochStartTime, epochEndTime) |
1111 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
|| isWithinRange(endFilter, epochStartTime, epochEndTime); |
1112 | ||
1113 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
if (Boolean.FALSE.equals(inEpochRange)) { |
1114 | inEpochRange = | |
1115 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
isWithinRange(epochStartTime, startFilter, endFilter) |
1116 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
|| isWithinRange(epochEndTime, startFilter, endFilter); |
1117 | } | |
1118 | ||
1119 |
1
1. lambda$getOutRangeIndex$30 : negated conditional → KILLED |
if (Boolean.FALSE.equals(inEpochRange)) { |
1120 | return; | |
1121 | } | |
1122 | inRangeEpoch.add(epoch); | |
1123 | }); | |
1124 |
1
1. lambda$getOutRangeIndex$31 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/EpochChange::setStartEpoch → SURVIVED |
epochChange.setStartEpoch(inRangeEpoch.get(BigInteger.ZERO.intValue())); |
1125 |
1
1. lambda$getOutRangeIndex$31 : removed call to org/cardanofoundation/explorer/api/model/response/protocol/EpochChange::setEndEpoch → KILLED |
epochChange.setEndEpoch( |
1126 |
1
1. lambda$getOutRangeIndex$31 : Replaced integer subtraction with addition → KILLED |
inRangeEpoch.get(inRangeEpoch.size() - BigInteger.ONE.intValue())); |
1127 | } | |
1128 | ||
1129 |
2
1. lambda$getOutRangeIndex$31 : negated conditional → KILLED 2. lambda$getOutRangeIndex$31 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$getOutRangeIndex$31 → KILLED |
return !inRange; |
1130 | }) | |
1131 | .toList(); | |
1132 | } | |
1133 | ||
1134 | /** User java refection to mapping {@link ParamHistory} get method */ | |
1135 | private void setLatestParamHistoryMethods() { | |
1136 | latestParamHistoryMethods = new EnumMap<>(ProtocolType.class); | |
1137 | Method[] methods = LatestParamHistory.class.getDeclaredMethods(); | |
1138 | ||
1139 | List<String> fieldNames = | |
1140 | Arrays.stream(ProtocolType.values()).map(ProtocolType::getFieldName).toList(); | |
1141 | ||
1142 | for (String field : fieldNames) { | |
1143 | ||
1144 | AtomicReference<Method> getter = new AtomicReference<>(); | |
1145 | AtomicReference<Method> getterProposal = new AtomicReference<>(); | |
1146 | ||
1147 | Arrays.stream(methods) | |
1148 | .filter( | |
1149 | method -> { | |
1150 | var methodLowerCase = method.getName().toLowerCase(); | |
1151 | var fieldLowerCase = field.toLowerCase(); | |
1152 |
3
1. lambda$setLatestParamHistoryMethods$32 : negated conditional → KILLED 2. lambda$setLatestParamHistoryMethods$32 : replaced boolean return with true for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::lambda$setLatestParamHistoryMethods$32 → KILLED 3. lambda$setLatestParamHistoryMethods$32 : negated conditional → KILLED |
return methodLowerCase.contains(fieldLowerCase) && methodLowerCase.contains(GET); |
1153 | }) | |
1154 |
1
1. setLatestParamHistoryMethods : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach( |
1155 | method -> { | |
1156 |
1
1. lambda$setLatestParamHistoryMethods$33 : negated conditional → SURVIVED |
if (method.getName().contains(PROPOSAL)) { |
1157 |
1
1. lambda$setLatestParamHistoryMethods$33 : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
getterProposal.set(method); |
1158 | return; | |
1159 | } | |
1160 |
1
1. lambda$setLatestParamHistoryMethods$33 : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
getter.set(method); |
1161 | }); | |
1162 | ||
1163 |
1
1. setLatestParamHistoryMethods : negated conditional → KILLED |
if (Objects.isNull(getter.get())) { |
1164 | return; | |
1165 | } | |
1166 | Pair<Method, Method> methodPair = Pair.of(getter.get(), getterProposal.get()); | |
1167 | latestParamHistoryMethods.put(ProtocolType.valueStringOf(field), methodPair); | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | private FixedProtocol getFixedProtocolFromShelleyGenesis(String genesisShelley) { | |
1172 | log.info("Read protocol data from url {}", genesisShelley); | |
1173 | ShelleyGenesis shelley = genesisService.fillContentShelley(genesisShelley); | |
1174 |
1
1. getFixedProtocolFromShelleyGenesis : negated conditional → SURVIVED |
if (Objects.isNull(shelley)) { |
1175 | return null; | |
1176 | } | |
1177 |
1
1. getFixedProtocolFromShelleyGenesis : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getFixedProtocolFromShelleyGenesis → SURVIVED |
return FixedProtocol.builder() |
1178 | .activeSlotsCoeff(shelley.getActiveSlotsCoeff()) | |
1179 | .genDelegs(shelley.getGenDelegs()) | |
1180 | .updateQuorum(shelley.getUpdateQuorum()) | |
1181 | .networkId(shelley.getNetworkId()) | |
1182 | .initialFunds(shelley.getInitialFunds()) | |
1183 | .maxLovelaceSupply(shelley.getMaxLovelaceSupply()) | |
1184 | .networkMagic(shelley.getNetworkMagic()) | |
1185 | .epochLength(shelley.getEpochLength()) | |
1186 | .slotsPerKESPeriod(shelley.getSlotsPerKESPeriod()) | |
1187 | .slotLength(shelley.getSlotLength()) | |
1188 | .maxKESEvolutions(shelley.getMaxKESEvolutions()) | |
1189 | .securityParam(shelley.getSecurityParam()) | |
1190 | .build(); | |
1191 | } | |
1192 | ||
1193 | private FixedProtocol getFixedProtocolFromByronGenesis( | |
1194 | String genesisByron, FixedProtocol fixedProtocol) { | |
1195 | log.info("Read protocol data from url {}", genesisByron); | |
1196 | ByronGenesis byron = genesisService.fillContentByron(genesisByron); | |
1197 |
1
1. getFixedProtocolFromByronGenesis : negated conditional → SURVIVED |
if (Objects.isNull(fixedProtocol) |
1198 |
1
1. getFixedProtocolFromByronGenesis : negated conditional → SURVIVED |
|| Objects.isNull(byron) |
1199 |
1
1. getFixedProtocolFromByronGenesis : negated conditional → KILLED |
|| Objects.isNull(byron.getStartTime())) { |
1200 |
1
1. getFixedProtocolFromByronGenesis : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getFixedProtocolFromByronGenesis → SURVIVED |
return fixedProtocol; |
1201 | } | |
1202 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
1203 |
1
1. getFixedProtocolFromByronGenesis : removed call to java/text/SimpleDateFormat::setTimeZone → NO_COVERAGE |
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); |
1204 |
1
1. getFixedProtocolFromByronGenesis : removed call to org/cardanofoundation/explorer/api/model/response/protocol/FixedProtocol::setTimestamp → NO_COVERAGE |
fixedProtocol.setTimestamp( |
1205 |
1
1. getFixedProtocolFromByronGenesis : Replaced long multiplication with division → NO_COVERAGE |
dateFormat.format(new Date(new Timestamp(byron.getStartTime() * 1000L).getTime()))); |
1206 |
1
1. getFixedProtocolFromByronGenesis : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getFixedProtocolFromByronGenesis → NO_COVERAGE |
return fixedProtocol; |
1207 | } | |
1208 | ||
1209 | @Override | |
1210 | public Double getCCThresholdFromConwayGenesis() { | |
1211 | log.info("Read protocol data from url {}", conwayUrl); | |
1212 | ConwayGenesis conwayGenesis = genesisService.fillContentConway(conwayUrl); | |
1213 |
2
1. getCCThresholdFromConwayGenesis : negated conditional → NO_COVERAGE 2. getCCThresholdFromConwayGenesis : negated conditional → KILLED |
if (conwayGenesis != null && conwayGenesis.getCommittee() != null) { |
1214 | try { | |
1215 | JsonElement jsonElement = JsonParser.parseString(conwayGenesis.getCommittee().toString()); | |
1216 | JsonObject jsonObject = jsonElement.getAsJsonObject(); | |
1217 |
1
1. getCCThresholdFromConwayGenesis : replaced Double return value with 0 for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getCCThresholdFromConwayGenesis → NO_COVERAGE |
return Double.valueOf(jsonObject.get("threshold").getAsString()); |
1218 | } catch (Exception e) { | |
1219 | log.error("Cannot get CC threshold from conway genesis"); | |
1220 | } | |
1221 | } | |
1222 |
1
1. getCCThresholdFromConwayGenesis : replaced Double return value with 0 for org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::getCCThresholdFromConwayGenesis → SURVIVED |
return null; |
1223 | } | |
1224 | ||
1225 | @PostConstruct | |
1226 | public void setup() { | |
1227 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::setProtocolMethodMap → KILLED |
setProtocolMethodMap(); |
1228 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::setMapEpochParamMethods → KILLED |
setMapEpochParamMethods(); |
1229 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::setParamHistoryMethods → KILLED |
setParamHistoryMethods(); |
1230 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::setHistoriesProtocolMethods → KILLED |
setHistoriesProtocolMethods(); |
1231 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::setLatestParamHistoryMethods → KILLED |
setLatestParamHistoryMethods(); |
1232 | loadFixedProtocols(); | |
1233 |
1
1. setup : removed call to org/cardanofoundation/explorer/api/service/impl/ProtocolParamServiceImpl::deleteProtocolHistoryCache → SURVIVED |
deleteProtocolHistoryCache(); |
1234 | getCCThresholdFromConwayGenesis(); | |
1235 | } | |
1236 | } | |
Mutations | ||
136 |
1.1 |
|
146 |
1.1 2.2 |
|
149 |
1.1 |
|
150 |
1.1 2.2 |
|
151 |
1.1 |
|
157 |
1.1 2.2 |
|
158 |
1.1 2.2 |
|
165 |
1.1 2.2 |
|
166 |
1.1 2.2 |
|
184 |
1.1 2.2 |
|
188 |
1.1 |
|
194 |
1.1 |
|
216 |
1.1 |
|
218 |
1.1 |
|
219 |
1.1 |
|
225 |
1.1 |
|
226 |
1.1 |
|
229 |
1.1 |
|
230 |
1.1 |
|
232 |
1.1 |
|
236 |
1.1 |
|
240 |
1.1 |
|
241 |
1.1 |
|
250 |
1.1 |
|
253 |
1.1 2.2 |
|
254 |
1.1 |
|
263 |
1.1 |
|
265 |
1.1 |
|
266 |
1.1 |
|
267 |
1.1 |
|
268 |
1.1 |
|
270 |
1.1 |
|
271 |
1.1 |
|
279 |
1.1 |
|
280 |
1.1 |
|
290 |
1.1 |
|
294 |
1.1 |
|
295 |
1.1 |
|
301 |
1.1 |
|
303 |
1.1 |
|
306 |
1.1 |
|
307 |
1.1 |
|
308 |
1.1 |
|
310 |
1.1 |
|
311 |
1.1 |
|
317 |
1.1 |
|
320 |
1.1 |
|
322 |
1.1 |
|
323 |
1.1 |
|
331 |
1.1 |
|
333 |
1.1 |
|
334 |
1.1 |
|
338 |
1.1 |
|
340 |
1.1 |
|
341 |
1.1 |
|
345 |
1.1 |
|
349 |
1.1 |
|
353 |
1.1 |
|
369 |
1.1 |
|
370 |
1.1 |
|
373 |
1.1 2.2 3.3 |
|
376 |
1.1 |
|
391 |
1.1 |
|
401 |
1.1 |
|
404 |
1.1 |
|
432 |
1.1 |
|
436 |
1.1 |
|
448 |
1.1 |
|
449 |
1.1 |
|
450 |
1.1 |
|
451 |
1.1 |
|
458 |
1.1 |
|
465 |
1.1 |
|
468 |
1.1 |
|
476 |
1.1 |
|
484 |
1.1 |
|
491 |
1.1 |
|
492 |
1.1 |
|
494 |
1.1 |
|
499 |
1.1 |
|
503 |
1.1 |
|
509 |
1.1 |
|
510 |
1.1 |
|
521 |
1.1 |
|
534 |
1.1 |
|
536 |
1.1 |
|
538 |
1.1 |
|
553 |
1.1 |
|
557 |
1.1 |
|
601 |
1.1 |
|
602 |
1.1 |
|
604 |
1.1 |
|
607 |
1.1 |
|
617 |
1.1 |
|
633 |
1.1 |
|
644 |
1.1 |
|
652 |
1.1 |
|
657 |
1.1 2.2 |
|
658 |
1.1 |
|
669 |
1.1 |
|
671 |
1.1 |
|
672 |
1.1 |
|
673 |
1.1 |
|
674 |
1.1 |
|
679 |
1.1 |
|
680 |
1.1 |
|
694 |
1.1 |
|
695 |
1.1 |
|
696 |
1.1 |
|
700 |
1.1 2.2 |
|
701 |
1.1 |
|
718 |
1.1 |
|
720 |
1.1 |
|
722 |
1.1 |
|
725 |
1.1 |
|
744 |
1.1 2.2 |
|
745 |
1.1 |
|
749 |
1.1 |
|
750 |
1.1 |
|
774 |
1.1 2.2 |
|
776 |
1.1 |
|
781 |
1.1 |
|
797 |
1.1 |
|
800 |
1.1 |
|
803 |
1.1 |
|
807 |
1.1 |
|
811 |
1.1 |
|
812 |
1.1 |
|
813 |
1.1 |
|
818 |
1.1 |
|
819 |
1.1 |
|
823 |
1.1 |
|
824 |
1.1 |
|
829 |
1.1 |
|
830 |
1.1 |
|
833 |
1.1 |
|
838 |
1.1 |
|
839 |
1.1 |
|
840 |
1.1 |
|
843 |
1.1 |
|
862 |
1.1 2.2 |
|
863 |
1.1 |
|
868 |
1.1 |
|
869 |
1.1 |
|
870 |
1.1 |
|
891 |
1.1 2.2 |
|
892 |
1.1 |
|
903 |
1.1 2.2 |
|
904 |
1.1 |
|
909 |
1.1 2.2 |
|
932 |
1.1 2.2 |
|
933 |
1.1 |
|
944 |
1.1 2.2 |
|
945 |
1.1 |
|
950 |
1.1 2.2 |
|
973 |
1.1 2.2 |
|
974 |
1.1 |
|
979 |
1.1 |
|
1004 |
1.1 2.2 |
|
1015 |
1.1 2.2 3.3 |
|
1018 |
1.1 |
|
1024 |
1.1 |
|
1031 |
1.1 |
|
1032 |
1.1 |
|
1033 |
1.1 |
|
1044 |
1.1 |
|
1045 |
1.1 |
|
1049 |
1.1 |
|
1079 |
1.1 |
|
1088 |
1.1 |
|
1089 |
1.1 |
|
1091 |
1.1 |
|
1093 |
1.1 |
|
1094 |
1.1 |
|
1098 |
1.1 2.2 |
|
1101 |
1.1 |
|
1104 |
1.1 |
|
1110 |
1.1 |
|
1111 |
1.1 |
|
1113 |
1.1 |
|
1115 |
1.1 |
|
1116 |
1.1 |
|
1119 |
1.1 |
|
1124 |
1.1 |
|
1125 |
1.1 |
|
1126 |
1.1 |
|
1129 |
1.1 2.2 |
|
1152 |
1.1 2.2 3.3 |
|
1154 |
1.1 |
|
1156 |
1.1 |
|
1157 |
1.1 |
|
1160 |
1.1 |
|
1163 |
1.1 |
|
1174 |
1.1 |
|
1177 |
1.1 |
|
1197 |
1.1 |
|
1198 |
1.1 |
|
1199 |
1.1 |
|
1200 |
1.1 |
|
1203 |
1.1 |
|
1204 |
1.1 |
|
1205 |
1.1 |
|
1206 |
1.1 |
|
1213 |
1.1 2.2 |
|
1217 |
1.1 |
|
1222 |
1.1 |
|
1227 |
1.1 |
|
1228 |
1.1 |
|
1229 |
1.1 |
|
1230 |
1.1 |
|
1231 |
1.1 |
|
1233 |
1.1 |