@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 this input is connected, check the output is connected back to this input and release it if so, making * it spendable once again. * * @return true if the disconnection took place, false if it was not connected. */ public boolean disconnect() { if (outpoint.fromTx == null) return false; TransactionOutput output = outpoint.fromTx.getOutput((int) outpoint.getIndex()); if (output.getSpentBy() == this) { output.markAsUnspent(); outpoint.fromTx = null; return true; } else { return false; } }
/** * If this input is connected, check the output is connected back to this input and release it if so, making * it spendable once again. * * @return true if the disconnection took place, false if it was not connected. */ public boolean disconnect() { if (outpoint.fromTx == null) return false; TransactionOutput output = outpoint.fromTx.getOutput((int) outpoint.getIndex()); if (output.getSpentBy() == this) { output.markAsUnspent(); outpoint.fromTx = null; return true; } else { return false; } }
/** * If this input is connected, check the output is connected back to this input and release it if so, making * it spendable once again. * * @return true if the disconnection took place, false if it was not connected. */ public boolean disconnect() { TransactionOutput connectedOutput; if (outpoint.fromTx != null) { // The outpoint is connected using a "standard" wallet, disconnect it. connectedOutput = outpoint.fromTx.getOutput((int) outpoint.getIndex()); outpoint.fromTx = null; } else if (outpoint.connectedOutput != null) { // The outpoint is connected using a UTXO based wallet, disconnect it. connectedOutput = outpoint.connectedOutput; outpoint.connectedOutput = null; } else { // The outpoint is not connected, do nothing. return false; } if (connectedOutput != null && connectedOutput.getSpentBy() == this) { // The outpoint was connected to an output, disconnect the output. connectedOutput.markAsUnspent(); return true; } else { return false; } }
/** * If this input is connected, check the output is connected back to this input and release it if so, making * it spendable once again. * * @return true if the disconnection took place, false if it was not connected. */ public boolean disconnect() { TransactionOutput connectedOutput; if (outpoint.fromTx != null) { // The outpoint is connected using a "standard" wallet, disconnect it. connectedOutput = outpoint.fromTx.getOutput((int) outpoint.getIndex()); outpoint.fromTx = null; } else if (outpoint.connectedOutput != null) { // The outpoint is connected using a UTXO based wallet, disconnect it. connectedOutput = outpoint.connectedOutput; outpoint.connectedOutput = null; } else { // The outpoint is not connected, do nothing. return false; } if (connectedOutput != null && connectedOutput.getSpentBy() == this) { // The outpoint was connected to an output, disconnect the output. connectedOutput.markAsUnspent(); return true; } else { return false; } }
@Test public void isTxConsistentReturnsFalseAsExpected_WhenAvailableForSpendingEqualsFalse() { Wallet wallet = new Wallet(PARAMS); TransactionOutput to = createMock(TransactionOutput.class); EasyMock.expect(to.isAvailableForSpending()).andReturn(false); EasyMock.expect(to.getSpentBy()).andReturn(null); Transaction tx = FakeTxBuilder.createFakeTxWithoutChange(PARAMS, to); replay(to); boolean isConsistent = wallet.isTxConsistent(tx, false); assertFalse(isConsistent); }
@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); }
Transaction connected = deadInput.getConnectedTransaction(); if (connected == null) continue; if (connected.getConfidence().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().getHash()); if (myUnspents.remove(deadOutput)) log.info("XX Removed from UNSPENTS: {}", deadOutput); TransactionInput connected = deadOutput.getSpentBy(); if (connected == null) continue; final Transaction parentTransaction = connected.getParentTransaction();
Transaction connected = deadInput.getConnectedTransaction(); if (connected == null) continue; if (connected.getConfidence().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().getHash()); if (myUnspents.remove(deadOutput)) log.info("XX Removed from UNSPENTS: {}", deadOutput); TransactionInput connected = deadOutput.getSpentBy(); if (connected == null) continue; final Transaction parentTransaction = connected.getParentTransaction();
Transaction connected = deadInput.getConnectedTransaction(); if (connected == null) continue; if (connected.getConfidence().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().getHash()); if (myUnspents.remove(deadOutput)) log.info("XX Removed from UNSPENTS: {}", deadOutput); TransactionInput connected = deadOutput.getSpentBy(); if (connected == null) continue; final Transaction parentTransaction = connected.getParentTransaction();
Transaction connected = deadInput.getConnectedTransaction(); if (connected == null) continue; if (connected.getConfidence().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().getHash()); if (myUnspents.remove(deadOutput)) log.info("XX Removed from UNSPENTS: {}", deadOutput); TransactionInput connected = deadOutput.getSpentBy(); if (connected == null) continue; final Transaction parentTransaction = connected.getParentTransaction();
.setScriptBytes(ByteString.copyFrom(output.getScriptBytes())) .setValue(output.getValue().value); final TransactionInput spentBy = output.getSpentBy(); if (spentBy != null) { Sha256Hash spendingHash = spentBy.getParentTransaction().getHash();
.setScriptBytes(ByteString.copyFrom(output.getScriptBytes())) .setValue(output.getValue().value); final TransactionInput spentBy = output.getSpentBy(); if (spentBy != null) { Sha256Hash spendingHash = spentBy.getParentTransaction().getHash();
.setScriptBytes(ByteString.copyFrom(output.getScriptBytes())) .setValue(output.getValue().value); final TransactionInput spentBy = output.getSpentBy(); if (spentBy != null) { Sha256Hash spendingHash = spentBy.getParentTransaction().getHash();
.setScriptBytes(ByteString.copyFrom(output.getScriptBytes())) .setValue(output.getValue().value); final TransactionInput spentBy = output.getSpentBy(); if (spentBy != null) { Sha256Hash spendingHash = spentBy.getParentTransaction().getHash();
assertEquals(send1, received.getOutput(0).getSpentBy().getParentTransaction()); assertEquals(TransactionConfidence.ConfidenceType.DEAD, send1.getConfidence().getConfidenceType()); assertEquals(send2, received.getOutput(0).getSpentBy().getParentTransaction());
assertFalse(walletTransactionIterator.next().getHash().equals(clientState.getRefundTransaction().getHash())); assertEquals(multisigContract.getHash(), clientWalletMultisigContract.getHash()); assertFalse(clientWalletMultisigContract.getInput(0).getConnectedOutput().getSpentBy().getParentTransaction().getHash().equals(refund.getHash()));