diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/BlockHeader.java b/src/main/java/com/sparrowwallet/drongo/protocol/BlockHeader.java index fd75f10..f152876 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/BlockHeader.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/BlockHeader.java @@ -47,7 +47,7 @@ public class BlockHeader extends Message { } public Date getTimeAsDate() { - return new Date(time); + return new Date(time * 1000); } public long getDifficultyTarget() { diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransaction.java b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransaction.java index f11a220..da102bf 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransaction.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransaction.java @@ -3,11 +3,13 @@ package com.sparrowwallet.drongo.wallet; import com.sparrowwallet.drongo.protocol.Sha256Hash; import com.sparrowwallet.drongo.protocol.Transaction; +import java.util.Date; + public class BlockTransaction extends BlockTransactionHash implements Comparable { private final Transaction transaction; - public BlockTransaction(Sha256Hash hash, int height, Long fee, Transaction transaction) { - super(hash, height, fee); + public BlockTransaction(Sha256Hash hash, int height, Date date, Long fee, Transaction transaction) { + super(hash, height, date, fee); this.transaction = transaction; } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHash.java b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHash.java index 2d189e0..db6566f 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHash.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHash.java @@ -2,26 +2,21 @@ package com.sparrowwallet.drongo.wallet; import com.sparrowwallet.drongo.protocol.Sha256Hash; +import java.util.Date; import java.util.Objects; public abstract class BlockTransactionHash { private final Sha256Hash hash; private final int height; + private final Date date; private final Long fee; private String label; - public BlockTransactionHash(Sha256Hash hash) { - this(hash, 0, 0L); - } - - public BlockTransactionHash(Sha256Hash hash, int height) { - this(hash, height, 0L); - } - - public BlockTransactionHash(Sha256Hash hash, int height, Long fee) { + public BlockTransactionHash(Sha256Hash hash, int height, Date date, Long fee) { this.hash = hash; this.height = height; + this.date = date; this.fee = fee; } @@ -37,6 +32,10 @@ public abstract class BlockTransactionHash { return height; } + public Date getDate() { + return date; + } + public Long getFee() { return fee; } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHashIndex.java b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHashIndex.java index 225b87f..6b61b45 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHashIndex.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/BlockTransactionHashIndex.java @@ -2,6 +2,7 @@ package com.sparrowwallet.drongo.wallet; import com.sparrowwallet.drongo.protocol.Sha256Hash; +import java.util.Date; import java.util.Objects; public class BlockTransactionHashIndex extends BlockTransactionHash implements Comparable { @@ -9,12 +10,12 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C private final long value; private BlockTransactionHashIndex spentBy; - public BlockTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value) { - this(hash, height, fee, index, value, null); + public BlockTransactionHashIndex(Sha256Hash hash, int height, Date date, Long fee, long index, long value) { + this(hash, height, date, fee, index, value, null); } - public BlockTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value, BlockTransactionHashIndex spentBy) { - super(hash, height, fee); + public BlockTransactionHashIndex(Sha256Hash hash, int height, Date date, Long fee, long index, long value, BlockTransactionHashIndex spentBy) { + super(hash, height, date, fee); this.index = index; this.value = value; this.spentBy = spentBy; @@ -51,12 +52,14 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; BlockTransactionHashIndex that = (BlockTransactionHashIndex) o; - return index == that.index; + return index == that.index && + value == that.value && + Objects.equals(spentBy, that.spentBy); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), index); + return Objects.hash(super.hashCode(), index, value, spentBy); } @Override @@ -66,10 +69,20 @@ public class BlockTransactionHashIndex extends BlockTransactionHash implements C return diff; } - return (int)(index - reference.index); + diff = (int)(index - reference.index); + if(diff != 0) { + return diff; + } + + diff = (int)(value - reference.value); + if(diff != 0) { + return diff; + } + + return spentBy == null ? (reference.spentBy == null ? 0 : Integer.MIN_VALUE) : (reference.spentBy == null ? Integer.MAX_VALUE : spentBy.compareTo(reference.spentBy)); } public BlockTransactionHashIndex copy() { - return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getFee(), index, value, spentBy.copy()); + return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getDate(), super.getFee(), index, value, spentBy == null ? null : spentBy.copy()); } }