Skip to content

Commit

Permalink
Only apply depth if appearedAtChainHeight is not invalid (-1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Mar 29, 2018
1 parent f43606f commit 854ce3a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/main/java/org/bitcoinj/core/TransactionConfidence.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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.</p>
*
*
* <p>If the transaction appears in the top block, the depth is one. If it's anything else (pending, dead, unknown)
* the depth is zero.</p>
*/
Expand Down

0 comments on commit 854ce3a

Please sign in to comment.