mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-01-29 00:21:11 +00:00
get dates from block header, better equality
This commit is contained in:
parent
cb18f7c4c3
commit
fa30f37e23
4 changed files with 34 additions and 20 deletions
|
@ -47,7 +47,7 @@ public class BlockHeader extends Message {
|
|||
}
|
||||
|
||||
public Date getTimeAsDate() {
|
||||
return new Date(time);
|
||||
return new Date(time * 1000);
|
||||
}
|
||||
|
||||
public long getDifficultyTarget() {
|
||||
|
|
|
@ -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<BlockTransaction> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<BlockTransactionHashIndex> {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue