1 | package org.cardanofoundation.explorer.api.util; | |
2 | ||
3 | import com.bloxbean.cardano.client.address.util.AddressUtil; | |
4 | ||
5 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
6 | import org.cardanofoundation.explorer.api.exception.BusinessCode; | |
7 | import org.cardanofoundation.explorer.common.exception.BusinessException; | |
8 | import org.cardanofoundation.explorer.common.model.address.ShelleyAddress; | |
9 | ||
10 | public class AddressUtils { | |
11 | ||
12 | private AddressUtils() { | |
13 | throw new IllegalStateException("Utility class"); | |
14 | } | |
15 | ||
16 | /** | |
17 | * Check address | |
18 | * | |
19 | * @param address address | |
20 | * @return stake address if exits, throw exception if not valid | |
21 | */ | |
22 | public static String checkStakeAddress(String address) { | |
23 | String stakeAddress = null; | |
24 | try { | |
25 |
1
1. checkStakeAddress : negated conditional → KILLED |
if (address.startsWith(CommonConstant.ADDRESS_PREFIX)) { |
26 | ShelleyAddress shelleyAddress = new ShelleyAddress(address); | |
27 |
1
1. checkStakeAddress : negated conditional → KILLED |
if (shelleyAddress.containStakeAddress()) { |
28 | // TO-DO: Move to common | |
29 | byte[] addr = shelleyAddress.getStakeReference(); | |
30 | shelleyAddress.getHexPaymentPart(); | |
31 | ShelleyAddress stakeShelley = new ShelleyAddress(addr); | |
32 | stakeAddress = stakeShelley.getAddress(); | |
33 | } | |
34 |
1
1. checkStakeAddress : negated conditional → SURVIVED |
} else if (address.startsWith(CommonConstant.STAKE_ADDRESS_PREFIX)) { |
35 | throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND); | |
36 |
1
1. checkStakeAddress : negated conditional → NO_COVERAGE |
} else if (!AddressUtil.isValidAddress(address)) { |
37 | throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND); | |
38 | } | |
39 | } catch (Exception e) { | |
40 | throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND); | |
41 | } | |
42 |
1
1. checkStakeAddress : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::checkStakeAddress → KILLED |
return stakeAddress; |
43 | } | |
44 | ||
45 | /** | |
46 | * Get hex payment part (script hash) associated with the address | |
47 | * | |
48 | * @param address | |
49 | * @return hex payment part | |
50 | */ | |
51 | public static String getHexPaymentPart(String address) { | |
52 |
1
1. getHexPaymentPart : negated conditional → KILLED |
if (address.startsWith(CommonConstant.ADDRESS_PREFIX)) { |
53 | ShelleyAddress shelleyAddress = new ShelleyAddress(address); | |
54 |
1
1. getHexPaymentPart : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → KILLED |
return shelleyAddress.getHexPaymentPart(); |
55 | } | |
56 |
1
1. getHexPaymentPart : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → NO_COVERAGE |
return null; |
57 | } | |
58 | } | |
Mutations | ||
25 |
1.1 |
|
27 |
1.1 |
|
34 |
1.1 |
|
36 |
1.1 |
|
42 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 |
|
56 |
1.1 |