From d03b68a109a732ab574f76bdfc8f6e2cc4650e1c Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sun, 1 Mar 2015 22:04:01 +0100 Subject: [PATCH] Transaction: add alternatives for getConfidence() --- .../java/org/bitcoinj/core/Transaction.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Transaction.java b/core/src/main/java/org/bitcoinj/core/Transaction.java index 07720fb2..699cf4c8 100644 --- a/core/src/main/java/org/bitcoinj/core/Transaction.java +++ b/core/src/main/java/org/bitcoinj/core/Transaction.java @@ -116,7 +116,7 @@ public class Transaction extends ChildMessage implements Serializable { private transient Sha256Hash hash; // Data about how confirmed this tx is. Serialized, may be null. - private TransactionConfidence confidence; + @Nullable private TransactionConfidence confidence; // Records a map of which blocks the transaction has appeared in (keys) to an index within that block (values). // The "index" is not a real index, instead the values are only meaningful relative to each other. For example, @@ -1120,15 +1120,33 @@ public class Transaction extends ChildMessage implements Serializable { return outputs.get((int)index); } - /** Returns the confidence object that is owned by this transaction object. */ - public synchronized TransactionConfidence getConfidence() { + /** + * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable} + * referenced by the implicit {@link Context}. + */ + public TransactionConfidence getConfidence() { + return getConfidence(Context.get()); + } + + /** + * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable} + * referenced by the given {@link Context}. + */ + public TransactionConfidence getConfidence(Context context) { + return getConfidence(context.getConfidenceTable()); + } + + /** + * Returns the confidence object for this transaction from the {@link org.bitcoinj.core.TxConfidenceTable} + */ + public TransactionConfidence getConfidence(TxConfidenceTable table) { if (confidence == null) - confidence = Context.get().getConfidenceTable().getOrCreate(getHash()) ; + confidence = table.getOrCreate(getHash()) ; return confidence; } /** Check if the transaction has a known confidence */ - public synchronized boolean hasConfidence() { + public boolean hasConfidence() { return getConfidence().getConfidenceType() != TransactionConfidence.ConfidenceType.UNKNOWN; }