mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
fix compareTo bug with unconfirmed parents
This commit is contained in:
parent
6a2af38b8a
commit
f0aa949174
1 changed files with 10 additions and 1 deletions
|
@ -34,7 +34,7 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(BlockTransaction blkTx) {
|
public int compareTo(BlockTransaction blkTx) {
|
||||||
if(getHeight() != blkTx.getHeight()) {
|
if(getHeight() != blkTx.getHeight()) {
|
||||||
return (getHeight() > 0 ? getHeight() : Integer.MAX_VALUE) - (blkTx.getHeight() > 0 ? blkTx.getHeight() : Integer.MAX_VALUE);
|
return getComparisonHeight() - blkTx.getComparisonHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getReferencedOutpoints(this).removeAll(getOutputs(blkTx))) {
|
if(getReferencedOutpoints(this).removeAll(getOutputs(blkTx))) {
|
||||||
|
@ -48,6 +48,15 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
|
||||||
return super.compareTo(blkTx);
|
return super.compareTo(blkTx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates a special height value that places txes with unconfirmed parents first, then normal unconfirmed txes, then confirmed txes
|
||||||
|
*
|
||||||
|
* @return the modified height value
|
||||||
|
*/
|
||||||
|
private int getComparisonHeight() {
|
||||||
|
return (getHeight() > 0 ? getHeight() : (getHeight() == -1 ? Integer.MAX_VALUE : Integer.MAX_VALUE - getHeight() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
private static List<HashIndex> getReferencedOutpoints(BlockTransaction blockchainTransaction) {
|
private static List<HashIndex> getReferencedOutpoints(BlockTransaction blockchainTransaction) {
|
||||||
if(blockchainTransaction.getTransaction() == null) {
|
if(blockchainTransaction.getTransaction() == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
Loading…
Reference in a new issue