1 | package org.cardanofoundation.explorer.api.service.impl; | |
2 | ||
3 | import java.math.BigInteger; | |
4 | import java.util.List; | |
5 | import java.util.Objects; | |
6 | import java.util.Optional; | |
7 | ||
8 | import lombok.RequiredArgsConstructor; | |
9 | import lombok.extern.log4j.Log4j2; | |
10 | ||
11 | import org.springframework.stereotype.Service; | |
12 | ||
13 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
14 | import org.cardanofoundation.explorer.api.model.response.PotsOverviewResponse; | |
15 | import org.cardanofoundation.explorer.api.repository.ledgersync.AdaPotsRepository; | |
16 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository; | |
17 | import org.cardanofoundation.explorer.api.service.FetchRewardDataService; | |
18 | import org.cardanofoundation.explorer.api.service.PotsService; | |
19 | import org.cardanofoundation.explorer.common.entity.ledgersync.AdaPots; | |
20 | ||
21 | @Service | |
22 | @RequiredArgsConstructor | |
23 | @Log4j2 | |
24 | public class PotsServiceImpl implements PotsService { | |
25 | ||
26 | private final EpochRepository epochRepository; | |
27 | ||
28 | private final AdaPotsRepository adaPotsRepository; | |
29 | ||
30 | private final FetchRewardDataService fetchRewardDataService; | |
31 | ||
32 | @Override | |
33 | public PotsOverviewResponse getPotsOverview() { | |
34 | Optional<Integer> currentEpoch = epochRepository.findCurrentEpochNo(); | |
35 | ||
36 |
1
1. getPotsOverview : negated conditional → KILLED |
if (currentEpoch.isEmpty()) { |
37 | log.info("Current epoch is empty"); | |
38 |
1
1. getPotsOverview : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PotsServiceImpl::getPotsOverview → KILLED |
return PotsOverviewResponse.builder().epoch(null).build(); |
39 | } | |
40 | Integer currentEpochValue = currentEpoch.get(); | |
41 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
42 |
2
1. getPotsOverview : negated conditional → KILLED 2. getPotsOverview : negated conditional → KILLED |
if (useKoiOs && !fetchRewardDataService.checkAdaPots(currentEpochValue)) { |
43 | fetchRewardDataService.fetchAdaPots(List.of(currentEpochValue)); | |
44 | } | |
45 | AdaPots adaPots = adaPotsRepository.findByEpochNo(currentEpoch.get()); | |
46 |
1
1. getPotsOverview : negated conditional → KILLED |
if (Objects.isNull(adaPots)) { |
47 | log.info("Ada pots of current epoch is null"); | |
48 |
1
1. getPotsOverview : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PotsServiceImpl::getPotsOverview → KILLED |
return PotsOverviewResponse.builder().epoch(null).build(); |
49 | } | |
50 | ||
51 | BigInteger depositsAndFees = | |
52 | CommonConstant.TOTAL_ADA | |
53 | .toBigInteger() | |
54 | .subtract( | |
55 |
1
1. getPotsOverview : negated conditional → SURVIVED |
Objects.isNull(adaPots.getTreasury()) ? BigInteger.ZERO : adaPots.getTreasury()) |
56 |
1
1. getPotsOverview : negated conditional → KILLED |
.subtract(Objects.isNull(adaPots.getRewards()) ? BigInteger.ZERO : adaPots.getRewards()) |
57 | .subtract( | |
58 |
1
1. getPotsOverview : negated conditional → SURVIVED |
Objects.isNull(adaPots.getReserves()) ? BigInteger.ZERO : adaPots.getReserves()); |
59 | ||
60 |
1
1. getPotsOverview : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/PotsServiceImpl::getPotsOverview → KILLED |
return PotsOverviewResponse.builder() |
61 | .epoch(currentEpoch.get()) | |
62 | .depositsAndFees(depositsAndFees) | |
63 | .rewards(adaPots.getRewards()) | |
64 | .reserves(adaPots.getReserves()) | |
65 | .treasury(adaPots.getTreasury()) | |
66 | .build(); | |
67 | } | |
68 | } | |
Mutations | ||
36 |
1.1 |
|
38 |
1.1 |
|
42 |
1.1 2.2 |
|
46 |
1.1 |
|
48 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
58 |
1.1 |
|
60 |
1.1 |