Skip to content

Commit

Permalink
feat: fix sonarqube issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BerezinD committed Apr 25, 2024
1 parent af2a236 commit 751fb55
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.cardanofoundation.rosetta.common.enumeration;

public enum RewardType {
leader,
member,
reserves,
treasury,
refund
LEADER,
MEMBER,
RESERVES,
TREASURY,
REFUND
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static void fillCertOperations(TransactionBody transactionBody, Transact
Integer network, List<Operation> operations)
throws CborException, CborSerializationException {
List<Operation> certOps = extraData.operations().stream()
.filter(o -> Constants.StakePoolOperations.contains(o.getType())
.filter(o -> Constants.STAKE_POOL_OPERATIONS.contains(o.getType())
).toList();
List<Operation> parsedCertOperations = ParseConstructionUtil.parseCertsToOperations(
transactionBody, certOps,
Expand Down Expand Up @@ -124,7 +124,7 @@ private static void fillInputOperations(TransactionBody transactionBody, Transac
}
public static List<String> getSignerFromOperation(NetworkIdentifierType networkIdentifierType,
Operation operation) {
if (Constants.PoolOperations.contains(operation.getType())) {
if (Constants.POOL_OPERATIONS.contains(operation.getType())) {
return getPoolSigners(networkIdentifierType, operation);
}
if (!ObjectUtils.isEmpty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public static Boolean isKeyValid(String publicKeyBytes, String curveType) {
}

public static String add0xPrefix(String hex) {
return (hex.startsWith("0x") ? hex : Constants.EMPTY_SYMBOl + hex);
return (hex.startsWith("0x") ? hex : Constants.EMPTY_SYMBOL + hex);
}

public static boolean isEd25519Signature(String hash) {
byte[] signatureByte = HexUtil.decodeHexString(hash);
return signatureByte.length >= Constants.Ed25519_Key_Signature_BYTE_LENGTH;
return signatureByte.length >= Constants.ED_25519_KEY_SIGNATURE_BYTE_LENGTH;
}


Expand Down Expand Up @@ -179,11 +179,11 @@ public static EraAddressType getEraAddressType(String address) {
}

public static Boolean isPolicyIdValid(String policyId) {
return policyId.matches(Constants.PolicyId_Validation);
return policyId.matches(Constants.POLICY_ID_VALIDATION);
}

public static Boolean isTokenNameValid(String name) {
return name.matches(Constants.Token_Name_Validation) || isEmptyHexString(name);
return name.matches(Constants.TOKEN_NAME_VALIDATION) || isEmptyHexString(name);
}

public static Boolean isEmptyHexString(String toCheck) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ private static List<Operation> getTxExtraData(List<Operation> operations){
boolean coinActionStatement =
!ObjectUtils.isEmpty(coinAction) && coinAction.equals(Constants.COIN_SPENT_ACTION);
return coinActionStatement ||
Constants.StakingOperations.contains(operation.getType()) ||
Constants.PoolOperations.contains(operation.getType()) ||
Constants.VoteOperations.contains(operation.getType());
Constants.STAKING_OPERATIONS.contains(operation.getType()) ||
Constants.POOL_OPERATIONS.contains(operation.getType()) ||
Constants.VOTE_OPERATIONS.contains(operation.getType());
}
).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ private Constants() {

public static final String IS_POSITIVE_NUMBER = "^\\+?\\d+";

public static final String Token_Name_Validation = "^[0-9a-fA-F]{0," + ASSET_NAME_LENGTH + "}$";
public static final String TOKEN_NAME_VALIDATION = "^[0-9a-fA-F]{0," + ASSET_NAME_LENGTH + "}$";

public static final String PolicyId_Validation = "^[0-9a-fA-F]{" + POLICY_ID_LENGTH + "}$";
public static final String POLICY_ID_VALIDATION = "^[0-9a-fA-F]{" + POLICY_ID_LENGTH + "}$";

public static final Integer SIGNATURE_LENGTH = 128;

Expand Down Expand Up @@ -89,26 +89,26 @@ private Constants() {
public static final String CHAIN_CODE_DUMMY = new String(new char[CHAIN_CODE_LENGTH]).replace(
"\0", "0");

public static final ArrayList<String> StakingOperations = new ArrayList<>(
public static final List<String> STAKING_OPERATIONS = new ArrayList<>(
List.of(OperationType.STAKE_DELEGATION.getValue(),
OperationType.STAKE_KEY_REGISTRATION.getValue(),
OperationType.STAKE_KEY_DEREGISTRATION.getValue(),
OperationType.WITHDRAWAL.getValue()));
public static final ArrayList<String> PoolOperations = new ArrayList<>(
public static final List<String> POOL_OPERATIONS = new ArrayList<>(
List.of(OperationType.POOL_RETIREMENT.getValue(),
OperationType.POOL_REGISTRATION.getValue(),
OperationType.POOL_REGISTRATION_WITH_CERT.getValue()));
public static final ArrayList<String> StakePoolOperations = new ArrayList<>(
public static final List<String> STAKE_POOL_OPERATIONS = new ArrayList<>(
List.of(OperationType.STAKE_DELEGATION.getValue(),
OperationType.STAKE_KEY_REGISTRATION.getValue(),
OperationType.STAKE_KEY_DEREGISTRATION.getValue(),
OperationType.POOL_RETIREMENT.getValue(),
OperationType.POOL_REGISTRATION.getValue(),
OperationType.POOL_REGISTRATION_WITH_CERT.getValue()));
public static final ArrayList<String> VoteOperations = new ArrayList<>(
public static final List<String> VOTE_OPERATIONS = new ArrayList<>(
List.of(OperationType.VOTE_REGISTRATION.getValue()));

public static final Integer Ed25519_Key_Signature_BYTE_LENGTH = 64;
public static final Integer ED_25519_KEY_SIGNATURE_BYTE_LENGTH = 64;

public static final String CERTIFICATE = "certificate";
public static final String ADDRESS = "address";
Expand Down Expand Up @@ -173,7 +173,7 @@ private Constants() {
public static final String PORT = "port";
public static final String IDENTIFIER = "identifier";
public static final String COST = "cost";
public static final String EMPTY_SYMBOl = "0x";
public static final String EMPTY_SYMBOL = "0x";
public static final String SYMBOL_REGEX = "\\x";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static List<Operation> parseCertsToOperations(TransactionBody transaction

for (int i = 0; i < certsCount; i++) {
Operation certOperation = certOps.get(i);
if (Constants.StakingOperations.contains(certOperation.getType())) {
if (Constants.STAKING_OPERATIONS.contains(certOperation.getType())) {
String hex = null;
if (checkStakeCredential(certOperation)) {
hex = certOperation.getMetadata().getStakingCredential().getHexBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public static List<MultiAsset> validateAndParseTokenBundle(List<TokenBundleItem>
if (token.getCurrency().getSymbol().equals(Constants.SYMBOL_REGEX)) {
token.getCurrency().setSymbol("");
}
assets.add(new Asset(token.getCurrency().getSymbol().startsWith(Constants.EMPTY_SYMBOl) ? token.getCurrency().getSymbol() : Constants.EMPTY_SYMBOl + token.getCurrency().getSymbol(), valueOf(Long.parseLong(token.getValue()))));
assets.add(new Asset(token.getCurrency().getSymbol().startsWith(Constants.EMPTY_SYMBOL) ? token.getCurrency().getSymbol() : Constants.EMPTY_SYMBOL
+ token.getCurrency().getSymbol(), valueOf(Long.parseLong(token.getValue()))));
assetsCheck.add(new Asset(token.getCurrency().getSymbol(), valueOf(Long.parseLong(token.getValue()))));
});
multiAssets.add(new MultiAsset(tokenBundleItem.getPolicyId(), assets));
Expand Down

0 comments on commit 751fb55

Please sign in to comment.