fixed NullPoointer

This commit is contained in:
pinpong 2016-12-23 09:54:16 +01:00
parent 5881879f78
commit b1c75bf0de
2 changed files with 38 additions and 11 deletions

View File

@ -577,10 +577,12 @@ public class IotaAPIProxy {
// Calls getBalances and formats the output
// returns the final inputsObject then
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses,
final List<String> balances, long threshold, int start, int end) {
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses, List<String> balances, long threshold, int start, int end) {
GetBalancesResponse bres = getBalances(100, addresses);
if (balances == null || balances.isEmpty()) {
GetBalancesResponse getBalancesResponse = getBalances(100, addresses);
balances = Arrays.asList(getBalancesResponse.getBalances());
}
// If threshold defined, keep track of whether reached or not
// else set default to true

View File

@ -2,14 +2,12 @@ package jota.utils;
import jota.model.Transaction;
import jota.pow.Curl;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class Converter {
private static final Logger log = LoggerFactory.getLogger(Converter.class);
@ -69,12 +67,39 @@ public class Converter {
}
public static int[] trits(final String trytes) {
final int[] trits = new int[trytes.length() * NUMBER_OF_TRITS_IN_A_TRYTE];
for (int i = 0; i < trytes.length(); i++) {
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);
}
if (InputValidator.isValue(trytes)) {
int value = Integer.parseInt(trytes);
long absoluteValue = value < 0 ? -value : value;
while (absoluteValue > 0) {
int remainder = (int) (absoluteValue % RADIX);
absoluteValue /= RADIX;
if (remainder > MAX_TRIT_VALUE) {
remainder = MIN_TRIT_VALUE;
absoluteValue++;
}
trits[trits.length] = remainder;
}
if (value < 0) {
for (int i = 0; i < trits.length; i++) {
trits[i] = -trits[i];
}
}
} else {
for (int i = 0; i < trytes.length(); i++) {
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);
}
}
return trits;
}