From 854ce3ad13e707f079a123f18444bd5da27eb9e8 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 29 Mar 2018 11:15:27 -0500 Subject: [PATCH] Only apply depth if appearedAtChainHeight is not invalid (-1) --- .../org/bitcoinj/core/TransactionConfidence.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/TransactionConfidence.java b/core/src/main/java/org/bitcoinj/core/TransactionConfidence.java index 562b1e4d6b4..e3e706914d3 100644 --- a/core/src/main/java/org/bitcoinj/core/TransactionConfidence.java +++ b/core/src/main/java/org/bitcoinj/core/TransactionConfidence.java @@ -112,12 +112,12 @@ public enum ConfidenceType { * If a transaction hasn't been broadcast yet, or there's no record of it, its confidence is UNKNOWN. */ UNKNOWN(0); - + private int value; ConfidenceType(int value) { this.value = value; } - + public int getValue() { return value; } @@ -262,7 +262,7 @@ public synchronized ConfidenceType getConfidenceType() { } /** - * Called by other objects in the system, like a {@link Wallet}, when new information about the confidence of a + * Called by other objects in the system, like a {@link Wallet}, when new information about the confidence of a * transaction becomes available. */ public synchronized void setConfidenceType(ConfidenceType confidenceType) { @@ -369,7 +369,9 @@ public synchronized String toString() { * @return the new depth */ public synchronized int incrementDepthInBlocks(int height) { - this.depth = height - getAppearedAtChainHeight() + 1; + if (getAppearedAtChainHeight() != -1) + this.depth = height - getAppearedAtChainHeight() + 1; + return this.depth; } @@ -379,7 +381,7 @@ public synchronized int incrementDepthInBlocks(int height) { * considers a transaction impractical to reverse after 6 blocks, but as of EOY 2011 network * security is high enough that often only one block is considered enough even for high value transactions. For low * value transactions like songs, or other cheap items, no blocks at all may be necessary.

- * + * *

If the transaction appears in the top block, the depth is one. If it's anything else (pending, dead, unknown) * the depth is zero.

*/