diff --git a/core/src/main/java/com/google/bitcoin/core/Base58.java b/core/src/main/java/com/google/bitcoin/core/Base58.java
index 8584e76b..8718d301 100644
--- a/core/src/main/java/com/google/bitcoin/core/Base58.java
+++ b/core/src/main/java/com/google/bitcoin/core/Base58.java
@@ -35,54 +35,54 @@ import java.util.Arrays;
*
*/
public class Base58 {
- private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
- .toCharArray();
- private static final int BASE_58 = ALPHABET.length;
- private static final int BASE_256 = 256;
+ private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
+ .toCharArray();
+ private static final int BASE_58 = ALPHABET.length;
+ private static final int BASE_256 = 256;
- private static final int[] INDEXES = new int[128];
- static {
- for (int i = 0; i < INDEXES.length; i++) {
- INDEXES[i] = -1;
- }
- for (int i = 0; i < ALPHABET.length; i++) {
- INDEXES[ALPHABET[i]] = i;
- }
- }
-
- public static String encode(byte[] input) {
- if (input.length == 0) {
- return "";
- }
- input = copyOfRange(input, 0, input.length);
- // Count leading zeroes.
- int zeroCount = 0;
- while (zeroCount < input.length && input[zeroCount] == 0) {
- ++zeroCount;
- }
- // The actual encoding.
- byte[] temp = new byte[input.length * 2];
- int j = temp.length;
+ private static final int[] INDEXES = new int[128];
+ static {
+ for (int i = 0; i < INDEXES.length; i++) {
+ INDEXES[i] = -1;
+ }
+ for (int i = 0; i < ALPHABET.length; i++) {
+ INDEXES[ALPHABET[i]] = i;
+ }
+ }
+
+ public static String encode(byte[] input) {
+ if (input.length == 0) {
+ return "";
+ }
+ input = copyOfRange(input, 0, input.length);
+ // Count leading zeroes.
+ int zeroCount = 0;
+ while (zeroCount < input.length && input[zeroCount] == 0) {
+ ++zeroCount;
+ }
+ // The actual encoding.
+ byte[] temp = new byte[input.length * 2];
+ int j = temp.length;
- int startAt = zeroCount;
- while (startAt < input.length) {
- byte mod = divmod58(input, startAt);
- if (input[startAt] == 0) {
- ++startAt;
- }
- temp[--j] = (byte) ALPHABET[mod];
- }
+ int startAt = zeroCount;
+ while (startAt < input.length) {
+ byte mod = divmod58(input, startAt);
+ if (input[startAt] == 0) {
+ ++startAt;
+ }
+ temp[--j] = (byte) ALPHABET[mod];
+ }
- // Strip extra '1' if there are some after decoding.
- while (j < temp.length && temp[j] == ALPHABET[0]) {
- ++j;
- }
- // Add as many leading '1' as there were leading zeros.
- while (--zeroCount >= 0) {
- temp[--j] = (byte) ALPHABET[0];
- }
+ // Strip extra '1' if there are some after decoding.
+ while (j < temp.length && temp[j] == ALPHABET[0]) {
+ ++j;
+ }
+ // Add as many leading '1' as there were leading zeros.
+ while (--zeroCount >= 0) {
+ temp[--j] = (byte) ALPHABET[0];
+ }
- byte[] output = copyOfRange(temp, j, temp.length);
+ byte[] output = copyOfRange(temp, j, temp.length);
try {
return new String(output, "US-ASCII");
} catch (UnsupportedEncodingException e) {
@@ -90,69 +90,69 @@ public class Base58 {
}
}
- public static byte[] decode(String input) throws AddressFormatException {
- if (input.length() == 0) {
- return new byte[0];
- }
+ public static byte[] decode(String input) throws AddressFormatException {
+ if (input.length() == 0) {
+ return new byte[0];
+ }
- byte[] input58 = new byte[input.length()];
- //
- // Transform the String to a base58 byte sequence
- //
- for (int i = 0; i < input.length(); ++i) {
- char c = input.charAt(i);
+ byte[] input58 = new byte[input.length()];
+ //
+ // Transform the String to a base58 byte sequence
+ //
+ for (int i = 0; i < input.length(); ++i) {
+ char c = input.charAt(i);
- int digit58 = -1;
- if (c >= 0 && c < 128) {
- digit58 = INDEXES[c];
- }
- if (digit58 < 0) {
- throw new AddressFormatException("Illegal character " + c + " at " + i);
- }
+ int digit58 = -1;
+ if (c >= 0 && c < 128) {
+ digit58 = INDEXES[c];
+ }
+ if (digit58 < 0) {
+ throw new AddressFormatException("Illegal character " + c + " at " + i);
+ }
- input58[i] = (byte) digit58;
- }
+ input58[i] = (byte) digit58;
+ }
- //
- // Count leading zeroes
- //
- int zeroCount = 0;
- while (zeroCount < input58.length && input58[zeroCount] == 0) {
- ++zeroCount;
- }
+ //
+ // Count leading zeroes
+ //
+ int zeroCount = 0;
+ while (zeroCount < input58.length && input58[zeroCount] == 0) {
+ ++zeroCount;
+ }
- //
- // The encoding
- //
- byte[] temp = new byte[input.length()];
- int j = temp.length;
+ //
+ // The encoding
+ //
+ byte[] temp = new byte[input.length()];
+ int j = temp.length;
- int startAt = zeroCount;
- while (startAt < input58.length) {
- byte mod = divmod256(input58, startAt);
- if (input58[startAt] == 0) {
- ++startAt;
- }
+ int startAt = zeroCount;
+ while (startAt < input58.length) {
+ byte mod = divmod256(input58, startAt);
+ if (input58[startAt] == 0) {
+ ++startAt;
+ }
- temp[--j] = mod;
- }
+ temp[--j] = mod;
+ }
- //
- // Do no add extra leading zeroes, move j to first non null byte.
- //
- while (j < temp.length && temp[j] == 0) {
- ++j;
- }
+ //
+ // Do no add extra leading zeroes, move j to first non null byte.
+ //
+ while (j < temp.length && temp[j] == 0) {
+ ++j;
+ }
- return copyOfRange(temp, j - zeroCount, temp.length);
- }
-
- public static BigInteger decodeToBigInteger(String input) throws AddressFormatException {
- byte[] bytes = decode(input);
-
- // always return a positive BigInteger
- return new BigInteger(1, bytes);
- }
+ return copyOfRange(temp, j - zeroCount, temp.length);
+ }
+
+ public static BigInteger decodeToBigInteger(String input) throws AddressFormatException {
+ byte[] bytes = decode(input);
+
+ // always return a positive BigInteger
+ return new BigInteger(1, bytes);
+ }
/**
* Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is
@@ -160,60 +160,60 @@ public class Base58 {
*
* @throws AddressFormatException if the input is not base 58 or the checksum does not validate.
*/
- public static byte[] decodeChecked(String input) throws AddressFormatException {
- byte tmp [] = decode(input);
- if (tmp.length < 4)
- throw new AddressFormatException("Input to short");
- byte[] bytes = copyOfRange(tmp, 0, tmp.length - 4);
- byte[] checksum = copyOfRange(tmp, tmp.length - 4, tmp.length);
-
- tmp = Utils.doubleDigest(bytes);
- byte[] hash = copyOfRange(tmp, 0, 4);
- if (!Arrays.equals(checksum, hash))
- throw new AddressFormatException("Checksum does not validate");
-
- return bytes;
- }
-
- //
- // number -> number / 58, returns number % 58
- //
- private static byte divmod58(byte[] number, int startAt) {
- int remainder = 0;
- for (int i = startAt; i < number.length; i++) {
- int digit256 = (int) number[i] & 0xFF;
- int temp = remainder * BASE_256 + digit256;
+ public static byte[] decodeChecked(String input) throws AddressFormatException {
+ byte tmp [] = decode(input);
+ if (tmp.length < 4)
+ throw new AddressFormatException("Input to short");
+ byte[] bytes = copyOfRange(tmp, 0, tmp.length - 4);
+ byte[] checksum = copyOfRange(tmp, tmp.length - 4, tmp.length);
+
+ tmp = Utils.doubleDigest(bytes);
+ byte[] hash = copyOfRange(tmp, 0, 4);
+ if (!Arrays.equals(checksum, hash))
+ throw new AddressFormatException("Checksum does not validate");
+
+ return bytes;
+ }
+
+ //
+ // number -> number / 58, returns number % 58
+ //
+ private static byte divmod58(byte[] number, int startAt) {
+ int remainder = 0;
+ for (int i = startAt; i < number.length; i++) {
+ int digit256 = (int) number[i] & 0xFF;
+ int temp = remainder * BASE_256 + digit256;
- number[i] = (byte) (temp / BASE_58);
+ number[i] = (byte) (temp / BASE_58);
- remainder = temp % BASE_58;
- }
+ remainder = temp % BASE_58;
+ }
- return (byte) remainder;
- }
+ return (byte) remainder;
+ }
- //
- // number -> number / 256, returns number % 256
- //
- private static byte divmod256(byte[] number58, int startAt) {
- int remainder = 0;
- for (int i = startAt; i < number58.length; i++) {
- int digit58 = (int) number58[i] & 0xFF;
- int temp = remainder * BASE_58 + digit58;
+ //
+ // number -> number / 256, returns number % 256
+ //
+ private static byte divmod256(byte[] number58, int startAt) {
+ int remainder = 0;
+ for (int i = startAt; i < number58.length; i++) {
+ int digit58 = (int) number58[i] & 0xFF;
+ int temp = remainder * BASE_58 + digit58;
- number58[i] = (byte) (temp / BASE_256);
+ number58[i] = (byte) (temp / BASE_256);
- remainder = temp % BASE_256;
- }
+ remainder = temp % BASE_256;
+ }
- return (byte) remainder;
- }
+ return (byte) remainder;
+ }
- private static byte[] copyOfRange(byte[] source, int from, int to) {
- byte[] range = new byte[to - from];
- System.arraycopy(source, from, range, 0, range.length);
+ private static byte[] copyOfRange(byte[] source, int from, int to) {
+ byte[] range = new byte[to - from];
+ System.arraycopy(source, from, range, 0, range.length);
- return range;
- }
-
+ return range;
+ }
+
}
diff --git a/core/src/main/java/com/google/bitcoin/core/Block.java b/core/src/main/java/com/google/bitcoin/core/Block.java
index 5c8f9432..84bb0325 100644
--- a/core/src/main/java/com/google/bitcoin/core/Block.java
+++ b/core/src/main/java/com/google/bitcoin/core/Block.java
@@ -47,7 +47,7 @@ public class Block extends Message {
private static final Logger log = LoggerFactory.getLogger(Block.class);
private static final long serialVersionUID = 2738848929966035281L;
- /** How many bytes are required to represent a block header. */
+ /** How many bytes are required to represent a block header. */
public static final int HEADER_SIZE = 80;
static final long ALLOWED_TIME_DRIFT = 2 * 60 * 60; // Same value as official client.
@@ -79,7 +79,7 @@ public class Block extends Message {
private long difficultyTarget; // "nBits"
private long nonce;
- /** If null, it means this object holds only the headers. */
+ /** If null, it means this object holds only the headers. */
List