Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Fixed some warning / issues mentioned by SonarLint. #237

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jota/src/main/java/org/iota/jota/IotaAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ public Future<ConditionalDepositAddress> newDepositRequest(DepositRequest reques
StoredDepositAddress storedRequest = new StoredDepositAddress(request, options.getSecurityLevel());
accountManager.addDepositRequest(address.getIndex(), storedRequest);
balanceCache.addBalance(
new Input(address.getAddress().getHashCheckSum(), 0, address.getIndex(), options.getSecurityLevel()),
new Input(address.getAddressHash().getHashCheckSum(), 0, address.getIndex(), options.getSecurityLevel()),
request);

EventNewInput event = new EventNewInput(address, request);
eventManager.emit(event);
return new ConditionalDepositAddress(request, address.getAddress());
return new ConditionalDepositAddress(request, address.getAddressHash());
});
task.run();
return task;
Expand Down Expand Up @@ -732,7 +732,7 @@ private List<String> prepareBundle(Bundle bundle, List<Transfer> transfers){

private List<Transaction> sendTrytes(Hash reference, String... trytes) {
GetTransactionsToApproveResponse txs = getApi().getTransactionsToApprove(options.getDepth(),
reference == null ? null : reference.getHash());
reference == null ? null : reference.getHashString());

EventAttachingToTangle attach = new EventAttachingToTangle(trytes);
getEventManager().emit(attach);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ private void calculateBalance(IotaAPI api, int index, DepositRequest request, in
long balance;
if (request.hasTimeOut()) {
// Not a remainder address, check balance
balance = api.getBalance(address.getAddress().getHashCheckSum());
balance = api.getBalance(address.getAddressHash().getHashCheckSum());
} else {
balance = request.getExpectedAmount();
}

Input input = new Input(
address.getAddress().getHashCheckSum(), balance, index, security
address.getAddressHash().getHashCheckSum(), balance, index, security
);
addInput(input, request);
}
Expand All @@ -78,7 +78,7 @@ private void addInput(Input input, DepositRequest balance) {
}

public Entry<Input, DepositRequest> getByAddress(Address address){
return getByHash(address.getAddress());
return getByHash(address.getAddressHash());
}

public Entry<Input, DepositRequest> getByHash(Hash hash){
Expand Down
11 changes: 7 additions & 4 deletions jota/src/main/java/org/iota/jota/account/AccountState.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.iota.jota.account.deposits.StoredDepositAddress;

Expand Down Expand Up @@ -94,15 +95,15 @@ public AccountState clone() throws CloneNotSupportedException {

if (null != depositRequests) {
newState.depositRequests = new HashMap<>();
for (int key : depositRequests.keySet()) {
newState.depositRequests.put(key, depositRequests.get(key).clone());
for (Map.Entry<Integer, StoredDepositAddress> entry : depositRequests.entrySet()) {
newState.depositRequests.put(entry.getKey(), entry.getValue().clone());
}
}

if (null != pendingTransfers) {
newState.pendingTransfers = new HashMap<>();
for (String key : pendingTransfers.keySet()) {
newState.pendingTransfers.put(key, pendingTransfers.get(key).clone());
for (Map.Entry<String, PendingTransfer> entry : pendingTransfers.entrySet()) {
newState.pendingTransfers.put(entry.getKey(), entry.getValue().clone());
}
}

Expand Down Expand Up @@ -134,4 +135,6 @@ public boolean equals(Object obj) {
&& Objects.equals(depositRequests, as.depositRequests)
&& Objects.equals(pendingTransfers, as.pendingTransfers);
}

//TODO: SonarLint-Rule: "equals(Object obj)" and "hashCode()" should be overridden in pairs. Therefore also overrie "hashCode()".
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Input createRemainder(long remainder) {


Input remainderInput = new Input(
addressService.get(key).getAddress().getHash(),
addressService.get(key).getAddressHash().getHashString(),
remainder,
key,
options.getSecurityLevel()
Expand Down Expand Up @@ -202,7 +202,7 @@ public Map<String, PendingTransfer> getPendingTransfers(){
public boolean isOwnAddress(String hash) {
for (Entry<Integer, StoredDepositAddress> entry : getDepositRequests().entrySet()) {
if (addressService.get(entry.getKey(), entry.getValue().getSecurityLevel())
.getAddress().getHash().equals(hash)) {
.getAddressHash().getHashString().equals(hash)) {

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private String getParam(String condition, Map<String, List<String>> paramsMap, S

@Override
public String build(ConditionalDepositAddress conditions) {
String address = conditions.getDepositAddress().getHash();
String address = conditions.getDepositAddress().getHashString();
String magnetChecksum = magnetChecksum(address,
conditions.getRequest().getTimeOut().getTime(),
conditions.getRequest().isMultiUse(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.iota.jota.account.event;

public enum AccountEventType {
Promotion,
Reattachment,
SendingTransfer,
TransferConfirmed,
ReceivedDeposit,
ReceivingDeposit,
ReceivedMessage,
DepositAddress,
Shutdown,
Error,
AttachingToTangle,
DoingProofOfWork
PROMOTION,
REATTACHMENT,
SENDING_TRANSFER,
TRANSFER_CONFIRMED,
RECEIVED_DEPOSIT,
RECEIVING_DEPOSIT,
RECEIVED_MESSAGE,
DEPOSIT_ADDRESS,
SHUTDOWN,
ERROR,
ATTACHING_TO_TANGLE,
DOING_PROOF_OF_WORK
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventAccountError extends EventImpl {
private boolean shouldLog;

public EventAccountError(Exception exception) {
super(AccountEventType.Error);
super(AccountEventType.ERROR);
this.exception = exception;
this.shouldLog = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventAttachingToTangle extends EventImpl {
private String[] trytes;

public EventAttachingToTangle(String[] trytes) {
super(AccountEventType.AttachingToTangle);
super(AccountEventType.ATTACHING_TO_TANGLE);

this.trytes = trytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventDoingProofOfWork extends EventImpl {
private String[] trytes;

public EventDoingProofOfWork(String[] trytes) {
super(AccountEventType.DoingProofOfWork);
super(AccountEventType.DOING_PROOF_OF_WORK);

this.trytes = trytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EventNewInput extends EventImpl {
private Address address;

public EventNewInput(Address address, DepositRequest request) {
super(AccountEventType.DepositAddress);
super(AccountEventType.DEPOSIT_ADDRESS);
this.address = address;
this.request = request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventPromotion extends EventImpl {
private Bundle promotedBundle;

public EventPromotion(Bundle promotedBundle) {
super(AccountEventType.Promotion);
super(AccountEventType.PROMOTION);

this.promotedBundle = promotedBundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EventReattachment extends EventImpl {
private Bundle newBundle;

public EventReattachment(Bundle originalBundle, Bundle newBundle) {
super(AccountEventType.Reattachment);
super(AccountEventType.REATTACHMENT);
this.originalBundle = originalBundle;
this.newBundle = newBundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class EventReceivedDeposit extends EventAbstractBundle {
private Address receiver;

public EventReceivedDeposit(Bundle bundle, Address address) {
super(AccountEventType.ReceivedDeposit, bundle);
super(AccountEventType.RECEIVED_DEPOSIT, bundle);
receiver = address;
}

Expand All @@ -28,13 +28,13 @@ public Address getAddress(){

public long getAmount() {
for (Transaction t : getBundle().getTransactions()) {
if (t.getAddress().equals(receiver.getAddress().toString())) {
if (t.getAddress().equals(receiver.getAddressHash().toString())) {
return t.getValue();
}
}

// This should NEVER happen
log.error("Deposit received event fired but could not find amount!\\n Please check " + receiver.getAddress());
log.error("Deposit received event fired but could not find amount!\\n Please check " + receiver.getAddressHash());
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class EventReceivedMessage extends EventAbstractBundle {
private String message = null;

public EventReceivedMessage(Bundle bundle) {
super(AccountEventType.ReceivedMessage, bundle);
super(AccountEventType.RECEIVED_MESSAGE, bundle);
}

public String getMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class EventReceivingDeposit extends EventAbstractBundle {
private Address receiver;

public EventReceivingDeposit(Bundle bundle, Address address) {
super(AccountEventType.ReceivingDeposit, bundle);
super(AccountEventType.RECEIVING_DEPOSIT, bundle);
this.receiver = address;
}

Expand All @@ -28,13 +28,13 @@ public Address getAddress(){

public long getAmount() {
for (Transaction t : getBundle().getTransactions()) {
if (t.getAddress().equals(receiver.getAddress().toString())) {
if (t.getAddress().equals(receiver.getAddressHash().toString())) {
return t.getValue();
}
}

// This should NEVER happen
log.error("Deposit received event fired but could not find amount!\\n Please check " + receiver.getAddress());
log.error("Deposit received event fired but could not find amount!\\n Please check " + receiver.getAddressHash());
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventSentTransfer extends EventImpl {
private Bundle bundle;

public EventSentTransfer(Bundle bundle) {
super(AccountEventType.SendingTransfer);
super(AccountEventType.SENDING_TRANSFER);
this.bundle = bundle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EventShutdown extends EventImpl {
private Date time;

public EventShutdown(Date now) {
super(AccountEventType.Shutdown);
super(AccountEventType.SHUTDOWN);
this.time = now;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EventTransferConfirmed extends EventImpl {
private Bundle bundle;

public EventTransferConfirmed(Bundle bundle) {
super(AccountEventType.TransferConfirmed);
super(AccountEventType.TRANSFER_CONFIRMED);
this.bundle = bundle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ private PendingTransfer getPendingTransferForBundle(Bundle bundle) {
}

private String findPromotableTail(PendingTransfer pendingBundle) {
String tailOrig = pendingBundle.getTailHashes().get(0).getHash();
String tailOrig = pendingBundle.getTailHashes().get(0).getHashString();
for (int i = pendingBundle.getTailHashes().size() - 1; i >= 0; i--) {
String tail = pendingBundle.getTailHashes().get(i).getHash();
String tail = pendingBundle.getTailHashes().get(i).getHashString();
Transaction tailTransaction = getBundleTail(tailOrig, tail);

if (null == tailTransaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void addUnconfirmedBundle(Address address) {
ScheduledFuture<?> task = service.scheduleAtFixedRate(
new IncomingTransferCheckerTask(address, api, eventManager, skipFirst, accountManager),
0, CHECK_INCOMING_DELAY, TimeUnit.MILLISECONDS);
unconfirmedBundles.put(address.getAddress().getHash(), task);
unconfirmedBundles.put(address.getAddressHash().getHashString(), task);
}

@AccountEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IncomingTransferCheckerTask(Address address, IotaAPI api, EventManager ev

@Override
public void run() {
String addrHash = address.getAddress().getHashCheckSum();
String addrHash = address.getAddressHash().getHashCheckSum();
try {
Bundle[] bundles = api.bundlesFromAddresses(true, addrHash);
if (bundles == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void doTask(Bundle bundle) {

// Get states of all tails (reattachments incl original)
GetInclusionStateResponse check = api.getLatestInclusion(
pending.getTailHashes().stream().map(Hash::getHash).toArray(size -> new String[size])
pending.getTailHashes().stream().map(Hash::getHashString).toArray(size -> new String[size])
);

if (anyTrue(check.getStates())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.iota.jota.store.Store;
import org.iota.jota.types.Hash;
import org.iota.jota.types.Trytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand All @@ -22,6 +24,8 @@
*/
public class AccountFileStore extends AccountStoreImpl {

private static final Logger log = LoggerFactory.getLogger(AccountFileStore.class);

private Store store;

public AccountFileStore() {
Expand Down Expand Up @@ -59,8 +63,7 @@ public void shutdown() {
try {
store.save(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("Exception at shutdown. Message: {}",e.getMessage(), e);
}
}

Expand All @@ -69,7 +72,8 @@ public AccountState loadAccount(String id) {
AccountState state = store.get(id, null);

if (state == null) {
saveAccount(id, state = new AccountState());
state = new AccountState();
saveAccount(id, state);
}
return state;
}
Expand Down Expand Up @@ -119,19 +123,19 @@ public void addPendingTransfer(String id, Hash tailTx, Trytes[] bundleTrytes, in
PendingTransfer pendingTransfer = new PendingTransfer(trytesToTrits(bundleTrytes));
pendingTransfer.addTail(tailTx);

loadAccount(id).addPendingTransfers(tailTx.getHash(), pendingTransfer);
loadAccount(id).addPendingTransfers(tailTx.getHashString(), pendingTransfer);
save();
}

@Override
public void removePendingTransfer(String id, Hash tailHash) {
loadAccount(id).removePendingTransfer(tailHash.getHash());
loadAccount(id).removePendingTransfer(tailHash.getHashString());
save();
}

@Override
public void addTailHash(String id, Hash tailHash, Hash newTailTxHash) {
loadAccount(id).getPendingTransfer(tailHash.getHash()).addTail(newTailTxHash);
loadAccount(id).getPendingTransfer(tailHash.getHashString()).addTail(newTailTxHash);
save();
}

Expand All @@ -155,8 +159,7 @@ private void save() {
try {
store.save(false);
} catch (Exception e) {
// TODO log account error
e.printStackTrace();
log.error("Exception at shutdown. Message: {}",e.getMessage(), e);
}
}

Expand Down
Loading