diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index 4136103ba..6315c1731 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -2174,7 +2174,7 @@ public class Wallet extends BaseTaggableObject if (log.isInfoEnabled()) log.info("Received a pending transaction {} that spends {} from our own wallet, and sends us {}", tx.getTxId(), valueSentFromMe.toFriendlyString(), valueSentToMe.toFriendlyString()); - if (tx.getConfidence().getSource().equals(TransactionConfidence.Source.UNKNOWN)) { + if (getConfidence(tx).getSource().equals(TransactionConfidence.Source.UNKNOWN)) { log.warn("Wallet received transaction with an unknown source. Consider tagging it!"); } @@ -2296,7 +2296,7 @@ public class Wallet extends BaseTaggableObject */ public boolean isTransactionMature(Transaction tx) { return !tx.isCoinBase() || - tx.getConfidence().getDepthInBlocks() >= params.getSpendableCoinbaseDepth(); + getConfidence(tx).getDepthInBlocks() >= params.getSpendableCoinbaseDepth(); } /** @@ -2482,9 +2482,9 @@ public class Wallet extends BaseTaggableObject currentTxDependencies.remove(tx); List currentTxDependenciesSorted = sortTxnsByDependency(currentTxDependencies); for (Transaction txDependency : currentTxDependenciesSorted) { - if (txDependency.getConfidence().getConfidenceType().equals(ConfidenceType.IN_CONFLICT)) { + if (getConfidence(txDependency).getConfidenceType().equals(ConfidenceType.IN_CONFLICT)) { if (isNotSpendingTxnsInConfidenceType(txDependency, ConfidenceType.IN_CONFLICT)) { - txDependency.getConfidence().setConfidenceType(ConfidenceType.PENDING); + getConfidence(txDependency).setConfidenceType(ConfidenceType.PENDING); confidenceChanged.put(txDependency, TransactionConfidence.Listener.ChangeReason.TYPE); } } @@ -2536,7 +2536,7 @@ public class Wallet extends BaseTaggableObject private boolean isNotSpendingTxnsInConfidenceType(Transaction tx, ConfidenceType confidenceType) { for (TransactionInput txInput : tx.getInputs()) { Transaction connectedTx = this.getTransaction(txInput.getOutpoint().hash()); - if (connectedTx != null && connectedTx.getConfidence().getConfidenceType().equals(confidenceType)) { + if (connectedTx != null && getConfidence(connectedTx).getConfidenceType().equals(confidenceType)) { return false; } } @@ -2584,7 +2584,7 @@ public class Wallet extends BaseTaggableObject return; for (Map.Entry entry : confidenceChanged.entrySet()) { final Transaction tx = entry.getKey(); - tx.getConfidence().queueListeners(entry.getValue()); + getConfidence(tx).queueListeners(entry.getValue()); queueOnTransactionConfidenceChanged(tx); } confidenceChanged.clear(); @@ -2619,7 +2619,7 @@ public class Wallet extends BaseTaggableObject // increment the tx confidence depth twice, it'd result in miscounting. ignoreNextNewBlock.remove(tx.getTxId()); } else { - TransactionConfidence confidence = tx.getConfidence(); + TransactionConfidence confidence = getConfidence(tx); if (confidence.getConfidenceType() == ConfidenceType.BUILDING) { // Erase the set of seen peers once the tx is so deep that it seems unlikely to ever go // pending again. We could clear this data the moment a tx is seen in the block chain, but @@ -2671,7 +2671,7 @@ public class Wallet extends BaseTaggableObject // to confirm them again. But this is a deeply unusual edge case that due to the maturity rule should never // happen in practice, thus for simplicities sake we ignore it here. log.info(" coinbase tx <-dead: confidence {}", tx.getTxId(), - tx.getConfidence().getConfidenceType().name()); + getConfidence(tx).getConfidenceType().name()); dead.remove(tx.getTxId()); } @@ -2841,14 +2841,14 @@ public class Wallet extends BaseTaggableObject for (TransactionInput deadInput : tx.getInputs()) { Transaction connected = deadInput.getConnectedTransaction(); if (connected == null) continue; - if (connected.getConfidence().getConfidenceType() != ConfidenceType.DEAD && deadInput.getConnectedOutput().getSpentBy() != null && deadInput.getConnectedOutput().getSpentBy().equals(deadInput)) { + if (getConfidence(connected).getConfidenceType() != ConfidenceType.DEAD && deadInput.getConnectedOutput().getSpentBy() != null && deadInput.getConnectedOutput().getSpentBy().equals(deadInput)) { checkState(myUnspents.add(deadInput.getConnectedOutput())); log.info("Added to UNSPENTS: {} in {}", deadInput.getConnectedOutput(), deadInput.getConnectedOutput().getParentTransaction().getTxId()); } deadInput.disconnect(); maybeMovePool(connected, "kill"); } - tx.getConfidence().setOverridingTxId(overridingTx != null ? overridingTx.getTxId() : null); + getConfidence(tx).setOverridingTxId(overridingTx != null ? overridingTx.getTxId() : null); confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.TYPE); // Now kill any transactions we have that depended on this one. for (TransactionOutput deadOutput : tx.getOutputs()) { @@ -2948,7 +2948,7 @@ public class Wallet extends BaseTaggableObject // tx is a double spend against a tx already in the best chain or spends outputs of a DEAD tx. // Add tx to the dead pool and schedule confidence listener notifications. log.info("->dead: {}", tx.getTxId()); - tx.getConfidence().setConfidenceType(ConfidenceType.DEAD); + getConfidence(tx).setConfidenceType(ConfidenceType.DEAD); confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.TYPE); addWalletTransaction(Pool.DEAD, tx); } else if (!doubleSpendPendingTxns.isEmpty() || @@ -2961,14 +2961,14 @@ public class Wallet extends BaseTaggableObject doubleSpendPendingTxns.add(tx); addTransactionsDependingOn(doubleSpendPendingTxns, getTransactions(true)); for (Transaction doubleSpendTx : doubleSpendPendingTxns) { - doubleSpendTx.getConfidence().setConfidenceType(ConfidenceType.IN_CONFLICT); + getConfidence(doubleSpendTx).setConfidenceType(ConfidenceType.IN_CONFLICT); confidenceChanged.put(doubleSpendTx, TransactionConfidence.Listener.ChangeReason.TYPE); } } else { // No conflict detected. // Add to the pending pool and schedule confidence listener notifications. log.info("->pending: {}", tx.getTxId()); - tx.getConfidence().setConfidenceType(ConfidenceType.PENDING); + getConfidence(tx).setConfidenceType(ConfidenceType.PENDING); confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.TYPE); addWalletTransaction(Pool.PENDING, tx); } @@ -3370,7 +3370,7 @@ public class Wallet extends BaseTaggableObject } // This is safe even if the listener has been added before, as TransactionConfidence ignores duplicate // registration requests. That makes the code in the wallet simpler. - tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener); + getConfidence(tx).addEventListener(Threading.SAME_THREAD, txConfidenceListener); } /** @@ -3756,7 +3756,7 @@ public class Wallet extends BaseTaggableObject // Ignore and don't print this line. } if (tx.hasConfidence()) - builder.append(" confidence: ").append(tx.getConfidence()).append('\n'); + builder.append(" confidence: ").append(getConfidence(tx)).append('\n'); builder.append(tx.toString(chain, network(), " ")); } } @@ -4673,7 +4673,7 @@ public class Wallet extends BaseTaggableObject // Label the transaction as being self created. We can use this later to spend its change output even before // the transaction is confirmed. We deliberately won't bother notifying listeners here as there's not much // point - the user isn't interested in a confidence transition they made themselves. - req.tx.getConfidence().setSource(TransactionConfidence.Source.SELF); + getConfidence(req.tx).setSource(TransactionConfidence.Source.SELF); // Label the transaction as being a user requested payment. This can be used to render GUI wallet // transaction lists more appropriately, especially when the wallet starts to generate transactions itself // for internal purposes. @@ -5122,7 +5122,7 @@ public class Wallet extends BaseTaggableObject if (tx.isCoinBase()) continue; log.info(" ->pending {}", tx.getTxId()); - tx.getConfidence().setConfidenceType(ConfidenceType.PENDING); // Wipe height/depth/work data. + getConfidence(tx).setConfidenceType(ConfidenceType.PENDING); // Wipe height/depth/work data. confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.TYPE); addWalletTransaction(Pool.PENDING, tx); updateForSpends(tx, false); @@ -5183,8 +5183,8 @@ public class Wallet extends BaseTaggableObject */ private void subtractDepth(int depthToSubtract, Collection transactions) { for (Transaction tx : transactions) { - if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) { - tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract); + if (getConfidence(tx).getConfidenceType() == ConfidenceType.BUILDING) { + getConfidence(tx).setDepthInBlocks(getConfidence(tx).getDepthInBlocks() - depthToSubtract); confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH); } } @@ -5630,7 +5630,7 @@ public class Wallet extends BaseTaggableObject // Don't hold the wallet lock whilst doing this, so if the broadcaster accesses the wallet at some point there // is no inversion. for (Transaction tx : toBroadcast) { - ConfidenceType confidenceType = tx.getConfidence().getConfidenceType(); + ConfidenceType confidenceType = getConfidence(tx).getConfidenceType(); checkState(confidenceType == ConfidenceType.PENDING || confidenceType == ConfidenceType.IN_CONFLICT, () -> "Tx " + tx.getTxId() + ": expected PENDING or IN_CONFLICT, was " + confidenceType); // Re-broadcast even if it's marked as already seen for two reasons @@ -5887,7 +5887,7 @@ public class Wallet extends BaseTaggableObject log.error("Failed to adjust rekey tx for fees."); return null; } - rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF); + getConfidence(rekeyTx).setSource(TransactionConfidence.Source.SELF); rekeyTx.setPurpose(Transaction.Purpose.KEY_ROTATION); SendRequest req = SendRequest.forTx(rekeyTx); req.aesKey = aesKey;