From dd7973c834e25473c032b0bc777efa3796c2b1e4 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 22 Apr 2014 21:53:35 +0200 Subject: [PATCH] Implement equals/hashCode on TransactionInput. --- .../google/bitcoin/core/TransactionInput.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionInput.java b/core/src/main/java/com/google/bitcoin/core/TransactionInput.java index 27af0ee1..9e51af75 100644 --- a/core/src/main/java/com/google/bitcoin/core/TransactionInput.java +++ b/core/src/main/java/com/google/bitcoin/core/TransactionInput.java @@ -24,6 +24,7 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.lang.ref.WeakReference; +import java.util.Arrays; import java.util.Map; import static com.google.common.base.Preconditions.checkElementIndex; @@ -422,4 +423,34 @@ public class TransactionInput extends ChildMessage implements Serializable { public TransactionOutput getConnectedOutput() { return getOutpoint().getConnectedOutput(); } + + /** Returns a copy of the input detached from its containing transaction, if need be. */ + public TransactionInput duplicateDetached() { + return new TransactionInput(params, null, bitcoinSerialize(), 0); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TransactionInput input = (TransactionInput) o; + + if (sequence != input.sequence) return false; + if (!outpoint.equals(input.outpoint)) return false; + if (!Arrays.equals(scriptBytes, input.scriptBytes)) return false; + if (scriptSig != null ? !scriptSig.equals(input.scriptSig) : input.scriptSig != null) return false; + if (parentTransaction != input.parentTransaction) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (sequence ^ (sequence >>> 32)); + result = 31 * result + outpoint.hashCode(); + result = 31 * result + (scriptBytes != null ? Arrays.hashCode(scriptBytes) : 0); + result = 31 * result + (scriptSig != null ? scriptSig.hashCode() : 0); + return result; + } }