Skip to content

Commit b1c75bf

Browse files
committed
fixed NullPoointer
1 parent 5881879 commit b1c75bf

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎src/main/java/jota/IotaAPIProxy.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,12 @@ public GetBalancesAndFormatResponse getInputs(final String seed, final List<Stri
577577

578578
// Calls getBalances and formats the output
579579
// returns the final inputsObject then
580-
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses,
581-
final List<String> balances, long threshold, int start, int end) {
580+
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses, List<String> balances, long threshold, int start, int end) {
582581

583-
GetBalancesResponse bres = getBalances(100, addresses);
582+
if (balances == null || balances.isEmpty()) {
583+
GetBalancesResponse getBalancesResponse = getBalances(100, addresses);
584+
balances = Arrays.asList(getBalancesResponse.getBalances());
585+
}
584586

585587
// If threshold defined, keep track of whether reached or not
586588
// else set default to true

‎src/main/java/jota/utils/Converter.java‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import jota.model.Transaction;
44
import jota.pow.Curl;
5-
6-
import java.util.Arrays;
7-
import java.util.Optional;
8-
95
import org.apache.commons.lang3.StringUtils;
106
import org.slf4j.Logger;
117
import org.slf4j.LoggerFactory;
128

9+
import java.util.Arrays;
10+
1311
public class Converter {
1412

1513
private static final Logger log = LoggerFactory.getLogger(Converter.class);
@@ -69,12 +67,39 @@ public static void getTrits(final byte[] bytes, final int[] trits) {
6967
}
7068

7169
public static int[] trits(final String trytes) {
72-
7370
final int[] trits = new int[trytes.length() * NUMBER_OF_TRITS_IN_A_TRYTE];
74-
for (int i = 0; i < trytes.length(); i++) {
75-
System.arraycopy(TRYTE_TO_TRITS_MAPPINGS[Constants.TRYTE_ALPHABET.indexOf(trytes.charAt(i))], 0, trits, i * NUMBER_OF_TRITS_IN_A_TRYTE, NUMBER_OF_TRITS_IN_A_TRYTE);
76-
}
7771

72+
if (InputValidator.isValue(trytes)) {
73+
74+
int value = Integer.parseInt(trytes);
75+
76+
long absoluteValue = value < 0 ? -value : value;
77+
78+
while (absoluteValue > 0) {
79+
80+
int remainder = (int) (absoluteValue % RADIX);
81+
absoluteValue /= RADIX;
82+
83+
if (remainder > MAX_TRIT_VALUE) {
84+
remainder = MIN_TRIT_VALUE;
85+
absoluteValue++;
86+
}
87+
88+
trits[trits.length] = remainder;
89+
}
90+
if (value < 0) {
91+
92+
for (int i = 0; i < trits.length; i++) {
93+
94+
trits[i] = -trits[i];
95+
}
96+
}
97+
} else {
98+
99+
for (int i = 0; i < trytes.length(); i++) {
100+
System.arraycopy(TRYTE_TO_TRITS_MAPPINGS[Constants.TRYTE_ALPHABET.indexOf(trytes.charAt(i))], 0, trits, i * NUMBER_OF_TRITS_IN_A_TRYTE, NUMBER_OF_TRITS_IN_A_TRYTE);
101+
}
102+
}
78103
return trits;
79104
}
80105

0 commit comments

Comments
 (0)