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.repository.ledgersync.AdaPotsRepository; | |
15 | import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository; | |
16 | import org.cardanofoundation.explorer.api.service.FetchRewardDataService; | |
17 | import org.cardanofoundation.explorer.api.service.SupplyService; | |
18 | import org.cardanofoundation.explorer.common.entity.ledgersync.AdaPots; | |
19 | ||
20 | @Service | |
21 | @RequiredArgsConstructor | |
22 | @Log4j2 | |
23 | public class SupplyServiceImpl implements SupplyService { | |
24 | ||
25 | private final AdaPotsRepository adaPotsRepository; | |
26 | ||
27 | private final EpochRepository epochRepository; | |
28 | ||
29 | private final FetchRewardDataService fetchRewardDataService; | |
30 | ||
31 | public Long getSupplyCirculating() { | |
32 | ||
33 | AdaPots latestAdaPots = getLatestAdaPots(); | |
34 | ||
35 |
1
1. getSupplyCirculating : negated conditional → KILLED |
if (Objects.isNull(latestAdaPots.getReserves()) |
36 |
1
1. getSupplyCirculating : negated conditional → KILLED |
|| Objects.isNull(latestAdaPots.getTreasury())) { |
37 | log.info("The reserves or treasury of the epoch {} is null", latestAdaPots.getEpochNo()); | |
38 |
1
1. getSupplyCirculating : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getSupplyCirculating → KILLED |
return null; |
39 | } | |
40 | BigInteger circulatingSupply = | |
41 | CommonConstant.TOTAL_ADA | |
42 | .toBigInteger() | |
43 | .subtract(latestAdaPots.getReserves()) | |
44 | .subtract(latestAdaPots.getTreasury()); | |
45 |
1
1. getSupplyCirculating : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getSupplyCirculating → KILLED |
return circulatingSupply.divide(CommonConstant.ONE_ADA_IN_LOVELACES).longValue(); |
46 | } | |
47 | ||
48 | public Long getSupplyTotal() { | |
49 | AdaPots latestAdaPots = getLatestAdaPots(); | |
50 |
1
1. getSupplyTotal : negated conditional → KILLED |
if (Objects.isNull(latestAdaPots.getReserves())) { |
51 | log.info("The reserves of the epoch {} is null", latestAdaPots.getEpochNo()); | |
52 |
1
1. getSupplyTotal : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getSupplyTotal → KILLED |
return null; |
53 | } | |
54 | BigInteger supplyTotal = | |
55 | CommonConstant.TOTAL_ADA.toBigInteger().subtract(latestAdaPots.getReserves()); | |
56 |
1
1. getSupplyTotal : replaced Long return value with 0L for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getSupplyTotal → KILLED |
return supplyTotal.divide(CommonConstant.ONE_ADA_IN_LOVELACES).longValue(); |
57 | } | |
58 | ||
59 | private AdaPots getLatestAdaPots() { | |
60 | Optional<Integer> currentEpoch = epochRepository.findCurrentEpochNo(); | |
61 | ||
62 |
1
1. getLatestAdaPots : negated conditional → KILLED |
if (currentEpoch.isEmpty()) { |
63 | log.info("Current epoch is empty"); | |
64 |
1
1. getLatestAdaPots : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getLatestAdaPots → KILLED |
return AdaPots.builder().build(); |
65 | } | |
66 | Integer currentEpochValue = currentEpoch.get(); | |
67 | boolean useKoiOs = fetchRewardDataService.useKoios(); | |
68 |
2
1. getLatestAdaPots : negated conditional → KILLED 2. getLatestAdaPots : negated conditional → KILLED |
if (useKoiOs && !fetchRewardDataService.checkAdaPots(currentEpochValue)) { |
69 | fetchRewardDataService.fetchAdaPots(List.of(currentEpochValue)); | |
70 | } | |
71 |
1
1. getLatestAdaPots : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/SupplyServiceImpl::getLatestAdaPots → KILLED |
return adaPotsRepository.findByEpochNo(currentEpoch.get()); |
72 | } | |
73 | } | |
Mutations | ||
35 |
1.1 |
|
36 |
1.1 |
|
38 |
1.1 |
|
45 |
1.1 |
|
50 |
1.1 |
|
52 |
1.1 |
|
56 |
1.1 |
|
62 |
1.1 |
|
64 |
1.1 |
|
68 |
1.1 2.2 |
|
71 |
1.1 |