Skip to content

Commit

Permalink
Refactor: Fixing SonarQube and Spotbugs issues (RA-79)
Browse files Browse the repository at this point in the history
  • Loading branch information
BerezinD committed Apr 30, 2024
1 parent 8d8bf1c commit 74a9d83
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import org.cardanofoundation.rosetta.api.block.model.entity.BlockAwareEntity;
import org.hibernate.annotations.DynamicUpdate;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -45,3 +47,4 @@ public class StakeAddressBalanceEntity extends BlockAwareEntity {
@Column(name = "epoch")
private Integer epoch;
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import org.cardanofoundation.rosetta.api.block.model.entity.DelegationEntity;

@Data
@Builder //TODO saa: refactor tests and remove builder and *argConstructor annotations
@NoArgsConstructor
Expand All @@ -21,4 +19,4 @@ public class Delegation {

private String address;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import org.cardanofoundation.rosetta.api.block.model.entity.PoolRegistrationEntity;
import org.openapitools.client.model.Relay;

@Data
Expand All @@ -28,4 +27,4 @@ public class PoolRegistration {
private Set<String> owners;
private List<Relay> relays;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import org.cardanofoundation.rosetta.api.block.model.entity.PoolRetirementEntity;

@Data
@Builder // TODO saa: remove this and refactor tests
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.bloxbean.cardano.yaci.core.model.certs.CertificateType;

import org.cardanofoundation.rosetta.api.block.model.entity.StakeRegistrationEntity;

@Data
@Builder //TODO saa: remove this and refactor tests
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum CatalystDataIndexes {

public static CatalystDataIndexes findByValue(Long value) {
for (CatalystDataIndexes a : CatalystDataIndexes.values()) {
if (a.getValue() == value) {
if (a.getValue().equals(value)) {
return a;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum CatalystLabels {

public static CatalystLabels findByValue(String label) {
for (CatalystLabels a : CatalystLabels.values()) {
if (a.getLabel() == label) {
if (a.getLabel().equals(label)) {
return a;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public static CoinChange getCoinChange(int index, String hash, CoinAction coinAc
CoinIdentifier coinIdentifier = new CoinIdentifier();
coinIdentifier.setIdentifier(hash + ":" + index);

return CoinChange.builder().coinIdentifier(CoinIdentifier.builder().identifier(hash + ":" + index).build())
.coinAction(coinAction).build();
return CoinChange.builder().coinIdentifier(coinIdentifier).coinAction(coinAction).build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static void fillOutputOperations(TransactionBody transactionBody, List<O
operations);
log.info("[parseOperationsFromTransactionBody] About to parse {} outputs", outputs.size());
for (TransactionOutput output : outputs) {
Operation outputParsed = ParseConstructionUtil.TransActionOutputToOperation(output, (long) operations.size(),
Operation outputParsed = ParseConstructionUtil.transActionOutputToOperation(output, (long) operations.size(),
relatedOperations);
operations.add(outputParsed);
}
Expand All @@ -117,7 +117,7 @@ private static void fillInputOperations(TransactionBody transactionBody, Transac
operations.add(inputOperations.get(i));
} else {
TransactionInput input = inputs.get(i);
Operation inputParsed = ParseConstructionUtil.TransactionInputToOperation(input, (long) operations.size());
Operation inputParsed = ParseConstructionUtil.transactionInputToOperation(input, (long) operations.size());
operations.add(inputParsed);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

import org.cardanofoundation.rosetta.api.account.model.domain.AddressBalance;
import org.cardanofoundation.rosetta.api.account.model.domain.Utxo;
import org.cardanofoundation.rosetta.api.block.model.domain.Block;
import org.cardanofoundation.rosetta.api.block.model.domain.BlockTx;
import org.cardanofoundation.rosetta.api.block.model.domain.GenesisBlock;
import org.cardanofoundation.rosetta.api.block.model.domain.ProtocolParams;
import org.cardanofoundation.rosetta.api.block.model.domain.StakeAddressBalance;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getCardanoAddress(AddressType addressType, PublicKey stakingCreden

public HdPublicKey getHdPublicKeyFromRosettaKey(PublicKey publicKey) {
byte[] pubKeyBytes = HexUtil.decodeHexString(publicKey.getHexBytes());
HdPublicKey pubKey = new HdPublicKey();
HdPublicKey pubKey;
if(pubKeyBytes.length == 32) {
pubKey = new HdPublicKey();
pubKey.setKeyData(pubKeyBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import okhttp3.Request.Builder;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.openapitools.client.model.AccountIdentifier;
Expand Down Expand Up @@ -367,7 +368,7 @@ public UnsignedTransaction createUnsignedTransaction(NetworkIdentifierType netwo
String transactionBytes = HexUtil.encodeHexString(
com.bloxbean.cardano.yaci.core.util.CborSerializationUtil.serialize(mapCbor));
log.info("[createUnsignedTransaction] Hashing transaction body");
String bodyHash = com.bloxbean.cardano.client.util.HexUtil.encodeHexString(
String bodyHash = HexUtil.encodeHexString(
Blake2bUtil.blake2bHash256(CborSerializationUtil.serialize(mapCbor)));
UnsignedTransaction toReturn = new UnsignedTransaction(
HexUtil.encodeHexString(HexUtil.decodeHexString(bodyHash)), transactionBytes,
Expand Down Expand Up @@ -509,27 +510,25 @@ public String submitTransaction(String signedTransaction) throws ApiException {
.build();
OkHttpClient client = new OkHttpClient();
Call call = client.newCall(request);
Response response = null;
try {
response = call.execute();
try (Response response = call.execute()) {
ResponseBody body = response.body();

if (response.code() == Constants.SUCCESS_SUBMIT_TX_HTTP_CODE) {
String txHash = response.body().string();
if (body == null) {
throw ExceptionFactory.sendTransactionError("Empty response body");
}
String txHash = body.string();
// removing leading and trailing quotes returned from node API
if (txHash.length() == Constants.TX_HASH_LENGTH + 2) {
txHash = txHash.substring(1, txHash.length() - 1);
}
return txHash;
} else {
throw ExceptionFactory.sendTransactionError(response.body().string());
throw ExceptionFactory.sendTransactionError(body == null ? null : body.string());
}
} catch (IOException e) {
log.error("{}[submitTransaction] There was an error submitting transaction", e.getMessage());
throw ExceptionFactory.sendTransactionError(e.getMessage());
} finally {
if (response != null) {
response.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.cardanofoundation.rosetta.common.enumeration.OperationType;

import java.util.ArrayList;
import java.util.List;
import org.openapitools.client.model.CurveType;

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

public static final List<String> STAKING_OPERATIONS = new ArrayList<>(
public static final List<String> STAKING_OPERATIONS =
List.of(OperationType.STAKE_DELEGATION.getValue(),
OperationType.STAKE_KEY_REGISTRATION.getValue(),
OperationType.STAKE_KEY_DEREGISTRATION.getValue(),
OperationType.WITHDRAWAL.getValue()));
public static final List<String> POOL_OPERATIONS = new ArrayList<>(
OperationType.WITHDRAWAL.getValue());
public static final List<String> POOL_OPERATIONS =
List.of(OperationType.POOL_RETIREMENT.getValue(),
OperationType.POOL_REGISTRATION.getValue(),
OperationType.POOL_REGISTRATION_WITH_CERT.getValue()));
public static final List<String> STAKE_POOL_OPERATIONS = new ArrayList<>(
OperationType.POOL_REGISTRATION_WITH_CERT.getValue());
public static final List<String> STAKE_POOL_OPERATIONS =
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 List<String> VOTE_OPERATIONS = new ArrayList<>(
List.of(OperationType.VOTE_REGISTRATION.getValue()));
OperationType.POOL_REGISTRATION_WITH_CERT.getValue());
public static final List<String> VOTE_OPERATIONS =
List.of(OperationType.VOTE_REGISTRATION.getValue());

public static final Integer ED_25519_KEY_SIGNATURE_BYTE_LENGTH = 64;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

public class OperationParseUtil {

private OperationParseUtil() {
}

public static ProcessOperations parseOperation(
Operation operation, NetworkIdentifierType networkIdentifierType, ProcessOperations resultAccumulator, String type) {
return switch (OperationType.fromValue(type)) {
Expand Down

0 comments on commit 74a9d83

Please sign in to comment.