diff --git a/core/src/main/java/org/bitcoinj/core/Sha256Hash.java b/core/src/main/java/org/bitcoinj/core/Sha256Hash.java index 88cb0f35..793424e4 100644 --- a/core/src/main/java/org/bitcoinj/core/Sha256Hash.java +++ b/core/src/main/java/org/bitcoinj/core/Sha256Hash.java @@ -266,8 +266,15 @@ public class Sha256Hash implements Serializable, Comparable { } @Override - public int compareTo(Sha256Hash o) { - // note that in this implementation compareTo() is not consistent with equals() - return this.hashCode() - o.hashCode(); // arbitrary but consistent + public int compareTo(final Sha256Hash other) { + for (int i = 31; i >= 0; i--) { + final int thisByte = this.bytes[i] & 0xff; + final int otherByte = other.bytes[i] & 0xff; + if (thisByte > otherByte) + return 1; + if (thisByte < otherByte) + return -1; + } + return 0; } }