/** * <p>Returns the list of transacion outputs, whether spent or unspent, that match a wallet by address or that are * watched by a wallet, i.e., transaction outputs whose script's address is controlled by the wallet and transaction * outputs whose script is watched by the wallet.</p> * * @param transactionBag The wallet that controls addresses and watches scripts. * @return linked list of outputs relevant to the wallet in this transaction */ public List<TransactionOutput> getWalletOutputs(TransactionBag transactionBag){ List<TransactionOutput> walletOutputs = new LinkedList<TransactionOutput>(); for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; walletOutputs.add(o); } return walletOutputs; }
/** * <p>Returns the list of transacion outputs, whether spent or unspent, that match a wallet by address or that are * watched by a wallet, i.e., transaction outputs whose script's address is controlled by the wallet and transaction * outputs whose script is watched by the wallet.</p> * * @param transactionBag The wallet that controls addresses and watches scripts. * @return linked list of outputs relevant to the wallet in this transaction */ public List<TransactionOutput> getWalletOutputs(TransactionBag transactionBag){ List<TransactionOutput> walletOutputs = new LinkedList<>(); for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; walletOutputs.add(o); } return walletOutputs; }
/** * <p>Returns the list of transacion outputs, whether spent or unspent, that match a wallet by address or that are * watched by a wallet, i.e., transaction outputs whose script's address is controlled by the wallet and transaction * outputs whose script is watched by the wallet.</p> * * @param transactionBag The wallet that controls addresses and watches scripts. * @return linked list of outputs relevant to the wallet in this transaction */ public List<TransactionOutput> getWalletOutputs(TransactionBag transactionBag) { List<TransactionOutput> walletOutputs = new LinkedList<>(); for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; walletOutputs.add(o); } return walletOutputs; }
/** * <p>Returns the list of transacion outputs, whether spent or unspent, that match a wallet by address or that are * watched by a wallet, i.e., transaction outputs whose script's address is controlled by the wallet and transaction * outputs whose script is watched by the wallet.</p> * * @param transactionBag The wallet that controls addresses and watches scripts. * @return linked list of outputs relevant to the wallet in this transaction */ public List<TransactionOutput> getWalletOutputs(TransactionBag transactionBag){ List<TransactionOutput> walletOutputs = new LinkedList<TransactionOutput>(); for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; walletOutputs.add(o); } return walletOutputs; }
/** * Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true * otherwise. */ public boolean isEveryOwnedOutputSpent(TransactionBag transactionBag) { for (TransactionOutput output : outputs) { if (output.isAvailableForSpending() && output.isMineOrWatched(transactionBag)) return false; } return true; }
/** * Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true * otherwise. */ public boolean isEveryOwnedOutputSpent(TransactionBag transactionBag) { for (TransactionOutput output : outputs) { if (output.isAvailableForSpending() && output.isMineOrWatched(transactionBag)) return false; } return true; }
/** * Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true * otherwise. */ public boolean isEveryOwnedOutputSpent(TransactionBag transactionBag) { for (TransactionOutput output : outputs) { if (output.isAvailableForSpending() && output.isMineOrWatched(transactionBag)) return false; } return true; }
/** * Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true * otherwise. */ public boolean isEveryOwnedOutputSpent(TransactionBag transactionBag) { for (TransactionOutput output : outputs) { if (output.isAvailableForSpending() && output.isMineOrWatched(transactionBag)) return false; } return true; }
/** * Calculates the sum of the outputs that are sending coins to a key in the wallet. */ public Coin getValueSentToMe(TransactionBag transactionBag) { // This is tested in WalletTest. Coin v = Coin.ZERO; for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; v = v.add(o.getValue()); } return v; }
/** * Calculates the sum of the outputs that are sending coins to a key in the wallet. */ public Coin getValueSentToMe(TransactionBag transactionBag) { // This is tested in WalletTest. Coin v = Coin.ZERO; for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; v = v.add(o.getValue()); } return v; }
/** * Calculates the sum of the outputs that are sending coins to a key in the wallet. */ public Coin getValueSentToMe(TransactionBag transactionBag) { // This is tested in WalletTest. Coin v = Coin.ZERO; for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; v = v.add(o.getValue()); } return v; }
/** * Calculates the sum of the outputs that are sending coins to a key in the wallet. */ public Coin getValueSentToMe(TransactionBag transactionBag) { // This is tested in WalletTest. Coin v = Coin.ZERO; for (TransactionOutput o : outputs) { if (!o.isMineOrWatched(transactionBag)) continue; v = v.add(o.getValue()); } return v; }
@VisibleForTesting boolean isTxConsistent(final Transaction tx, final boolean isSpent) { boolean isActuallySpent = true; for (TransactionOutput o : tx.getOutputs()) { if (o.isAvailableForSpending()) { if (o.isMineOrWatched(this)) isActuallySpent = false; if (o.getSpentBy() != null) { log.error("isAvailableForSpending != spentBy"); return false; } } else { if (o.getSpentBy() == null) { log.error("isAvailableForSpending != spentBy"); return false; } } } return isActuallySpent == isSpent; }
@VisibleForTesting boolean isTxConsistent(final Transaction tx, final boolean isSpent) { boolean isActuallySpent = true; for (TransactionOutput o : tx.getOutputs()) { if (o.isAvailableForSpending()) { if (o.isMineOrWatched(this)) isActuallySpent = false; if (o.getSpentBy() != null) { log.error("isAvailableForSpending != spentBy"); return false; } } else { if (o.getSpentBy() == null) { log.error("isAvailableForSpending != spentBy"); return false; } } } return isActuallySpent == isSpent; }
@VisibleForTesting boolean isTxConsistent(final Transaction tx, final boolean isSpent) { boolean isActuallySpent = true; for (TransactionOutput o : tx.getOutputs()) { if (o.isAvailableForSpending()) { if (o.isMineOrWatched(this)) isActuallySpent = false; if (o.getSpentBy() != null) { log.error("isAvailableForSpending != spentBy"); return false; } } else { if (o.getSpentBy() == null) { log.error("isAvailableForSpending != spentBy"); return false; } } } return isActuallySpent == isSpent; }
@VisibleForTesting boolean isTxConsistent(final Transaction tx, final boolean isSpent) { boolean isActuallySpent = true; for (TransactionOutput o : tx.getOutputs()) { if (o.isAvailableForSpending()) { if (o.isMineOrWatched(this)) isActuallySpent = false; if (o.getSpentBy() != null) { log.error("isAvailableForSpending != spentBy"); return false; } } else { if (o.getSpentBy() == null) { log.error("isAvailableForSpending != spentBy"); return false; } } } return isActuallySpent == isSpent; }
if (output.isAvailableForSpending() && output.isMineOrWatched(this)) myUnspents.add(output);
@Test public void isTxConsistentReturnsFalseAsExpected() { Wallet wallet = new Wallet(PARAMS); TransactionOutput to = createMock(TransactionOutput.class); EasyMock.expect(to.isAvailableForSpending()).andReturn(true); EasyMock.expect(to.isMineOrWatched(wallet)).andReturn(true); EasyMock.expect(to.getSpentBy()).andReturn(new TransactionInput(PARAMS, null, new byte[0])); Transaction tx = FakeTxBuilder.createFakeTxWithoutChange(PARAMS, to); replay(to); boolean isConsistent = wallet.isTxConsistent(tx, false); assertFalse(isConsistent); }
txHashes.add(tx.getHash()); for (TransactionOutput txo : tx.getOutputs()) { if (txo.isAvailableForSpending() && txo.isMineOrWatched(account)) { OutPointOutput utxo = new OutPointOutput(tx, txo.getIndex()); if (tx.getConfidenceType() == BUILDING) {
/** * Calculates the sum of the inputs that are spending coins with keys in the wallet. This requires the * transactions sending coins to those keys to be in the wallet. This method will not attempt to download the * blocks containing the input transactions if the key is in the wallet but the transactions are not. * * @return sum of the inputs that are spending coins with keys in the wallet */ public Coin getValueSentFromMe(TransactionBag wallet) throws ScriptException { // This is tested in WalletTest. Coin v = Coin.ZERO; for (TransactionInput input : inputs) { // This input is taking value from a transaction in our wallet. To discover the value, // we must find the connected transaction. TransactionOutput connected = input.getConnectedOutput(wallet.getTransactionPool(Pool.UNSPENT)); if (connected == null) connected = input.getConnectedOutput(wallet.getTransactionPool(Pool.SPENT)); if (connected == null) connected = input.getConnectedOutput(wallet.getTransactionPool(Pool.PENDING)); if (connected == null) continue; // The connected output may be the change to the sender of a previous input sent to this wallet. In this // case we ignore it. if (!connected.isMineOrWatched(wallet)) continue; v = v.add(connected.getValue()); } return v; }