Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
refactor: extra complicated conditions to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Mar 25, 2020
1 parent 7c430ce commit 6a2653f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ public Map<Hash, Long> generateBalanceDiff(Set<Hash> visitedTransactions, Hash s
TransactionViewModel trunkTransactionViewModel = transactionViewModel.getTrunkTransaction(tangle);
TransactionViewModel branchTransactionViewModel = transactionViewModel.getBranchTransaction(tangle);

boolean approvedTrunk = (trunkTransactionViewModel.snapshotIndex() > 0) && (trunkTransactionViewModel.snapshotIndex() != milestoneIndex);
boolean approvedBranch = (branchTransactionViewModel.snapshotIndex() > 0) && (branchTransactionViewModel.snapshotIndex() != milestoneIndex);
if ((trunkTransactionViewModel.getType() == TransactionViewModel.PREFILLED_SLOT || visitedTransactions.contains(trunkTransactionViewModel.getHash()) || approvedTrunk) &&
(branchTransactionViewModel.getType() == TransactionViewModel.PREFILLED_SLOT || visitedTransactions.contains(branchTransactionViewModel.getHash()) || approvedBranch)) {
boolean isEmptyTrunk = trunkTransactionViewModel.getType() == TransactionViewModel.PREFILLED_SLOT;
boolean isEmptyBranch = branchTransactionViewModel.getType() == TransactionViewModel.PREFILLED_SLOT;
boolean isApprovedTrunk = (trunkTransactionViewModel.snapshotIndex() > 0) && (trunkTransactionViewModel.snapshotIndex() != milestoneIndex);
boolean isApprovedBranch = (branchTransactionViewModel.snapshotIndex() > 0) && (branchTransactionViewModel.snapshotIndex() != milestoneIndex);
boolean isLeafTrunk = isEmptyTrunk || visitedTransactions.contains(trunkTransactionViewModel.getHash()) || isApprovedTrunk;
boolean isLeafBranch = isEmptyBranch || visitedTransactions.contains(branchTransactionViewModel.getHash()) || isApprovedBranch;

if (isLeafTrunk && isLeafBranch) {
if (transactionViewModel.getCurrentIndex() == 0) {
if (transactionViewModel.getType() == TransactionViewModel.PREFILLED_SLOT) {
return null;
Expand Down Expand Up @@ -227,9 +231,9 @@ public Map<Hash, Long> generateBalanceDiff(Set<Hash> visitedTransactions, Hash s
visitedTransactions.add(transactionPointer);
stack.pop();
}
else if((trunkTransactionViewModel.getType() != TransactionViewModel.PREFILLED_SLOT && !visitedTransactions.contains(trunkTransactionViewModel.getHash()) && !approvedTrunk)){
else if(!isLeafTrunk){
stack.addFirst(trunkTransactionViewModel.getHash());
}else if((branchTransactionViewModel.getType() != TransactionViewModel.PREFILLED_SLOT && !visitedTransactions.contains(branchTransactionViewModel.getHash()) && !approvedBranch)) {
}else if(!isLeafBranch) {
stack.addFirst(branchTransactionViewModel.getHash());
}
}catch(Exception e){
Expand Down

0 comments on commit 6a2653f

Please sign in to comment.