3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 18:55:52 +00:00

TransactionInput: Add getConnectedTransaction(), as this seems to be a relevant usecase.

This commit is contained in:
Andreas Schildbach 2016-01-16 16:41:05 +01:00
parent d092922e64
commit 0a58837db0
2 changed files with 14 additions and 4 deletions

View File

@ -432,6 +432,16 @@ public class TransactionInput extends ChildMessage {
return getOutpoint().getConnectedOutput(); return getOutpoint().getConnectedOutput();
} }
/**
* Returns the connected transaction, assuming the input was connected with
* {@link TransactionInput#connect(TransactionOutput)} or variants at some point. If it wasn't connected, then
* this method returns null.
*/
@Nullable
public Transaction getConnectedTransaction() {
return getOutpoint().fromTx;
}
/** Returns a copy of the input detached from its containing transaction, if need be. */ /** Returns a copy of the input detached from its containing transaction, if need be. */
public TransactionInput duplicateDetached() { public TransactionInput duplicateDetached() {
return new TransactionInput(params, null, bitcoinSerialize(), 0); return new TransactionInput(params, null, bitcoinSerialize(), 0);

View File

@ -2189,7 +2189,7 @@ public class Wallet extends BaseTaggableObject
// Otherwise we saw a transaction spend our coins, but we didn't try and spend them ourselves yet. // Otherwise we saw a transaction spend our coins, but we didn't try and spend them ourselves yet.
// The outputs are already marked as spent by the connect call above, so check if there are any more for // The outputs are already marked as spent by the connect call above, so check if there are any more for
// us to use. Move if not. // us to use. Move if not.
Transaction connected = checkNotNull(input.getOutpoint().fromTx); Transaction connected = checkNotNull(input.getConnectedTransaction());
log.info(" marked {} as spent", input.getOutpoint()); log.info(" marked {} as spent", input.getOutpoint());
maybeMovePool(connected, "prevtx"); maybeMovePool(connected, "prevtx");
// Just because it's connected doesn't mean it's actually ours: sometimes we have total visibility. // Just because it's connected doesn't mean it's actually ours: sometimes we have total visibility.
@ -2244,7 +2244,7 @@ public class Wallet extends BaseTaggableObject
spent.remove(tx.getHash()); spent.remove(tx.getHash());
addWalletTransaction(Pool.DEAD, tx); addWalletTransaction(Pool.DEAD, tx);
for (TransactionInput deadInput : tx.getInputs()) { for (TransactionInput deadInput : tx.getInputs()) {
Transaction connected = deadInput.getOutpoint().fromTx; Transaction connected = deadInput.getConnectedTransaction();
if (connected == null) continue; if (connected == null) continue;
if (connected.getConfidence().getConfidenceType() != ConfidenceType.DEAD && deadInput.getConnectedOutput().getSpentBy() != null && deadInput.getConnectedOutput().getSpentBy().equals(deadInput)) { if (connected.getConfidence().getConfidenceType() != ConfidenceType.DEAD && deadInput.getConnectedOutput().getSpentBy() != null && deadInput.getConnectedOutput().getSpentBy().equals(deadInput)) {
checkState(myUnspents.add(deadInput.getConnectedOutput())); checkState(myUnspents.add(deadInput.getConnectedOutput()));
@ -2272,13 +2272,13 @@ public class Wallet extends BaseTaggableObject
for (TransactionInput input : overridingTx.getInputs()) { for (TransactionInput input : overridingTx.getInputs()) {
TransactionInput.ConnectionResult result = input.connect(unspent, TransactionInput.ConnectMode.DISCONNECT_ON_CONFLICT); TransactionInput.ConnectionResult result = input.connect(unspent, TransactionInput.ConnectMode.DISCONNECT_ON_CONFLICT);
if (result == TransactionInput.ConnectionResult.SUCCESS) { if (result == TransactionInput.ConnectionResult.SUCCESS) {
maybeMovePool(input.getOutpoint().fromTx, "kill"); maybeMovePool(input.getConnectedTransaction(), "kill");
myUnspents.remove(input.getConnectedOutput()); myUnspents.remove(input.getConnectedOutput());
log.info("Removing from UNSPENTS: {}", input.getConnectedOutput()); log.info("Removing from UNSPENTS: {}", input.getConnectedOutput());
} else { } else {
result = input.connect(spent, TransactionInput.ConnectMode.DISCONNECT_ON_CONFLICT); result = input.connect(spent, TransactionInput.ConnectMode.DISCONNECT_ON_CONFLICT);
if (result == TransactionInput.ConnectionResult.SUCCESS) { if (result == TransactionInput.ConnectionResult.SUCCESS) {
maybeMovePool(input.getOutpoint().fromTx, "kill"); maybeMovePool(input.getConnectedTransaction(), "kill");
myUnspents.remove(input.getConnectedOutput()); myUnspents.remove(input.getConnectedOutput());
log.info("Removing from UNSPENTS: {}", input.getConnectedOutput()); log.info("Removing from UNSPENTS: {}", input.getConnectedOutput());
} }